joseluisq / alpine-php-fpm

Lightweight & optimized Multi-Arch Docker Images (x86_64/arm/arm64) for PHP-FPM (PHP 8.1, 8.2, 8.3) with essential extensions on top of latest Alpine Linux. :elephant:
Apache License 2.0
179 stars 42 forks source link

Nginx + PHP via single Dockerfile? #9

Closed maietta closed 1 year ago

maietta commented 1 year ago

Haven't been able to make use of your version of Nginx + PHP via FPM-PHP because my deployment requires a dockerfile, not a docker-compose.

I've been tinkering with how to get the Nginx + PHP working inside a single dockerfile, but having no real luck. I'm usually pretty good at this stuff but not today.

Using the example from docker-compose and fairly common Docker syntax, this is what I have so far.

FROM nginx:1.17-alpine

COPY conf.d/ /etc/nginx/conf.d/
COPY nginx.conf /etc/nginx/nginx.conf

FROM joseluisq/php-fpm

USER root
COPY backend/ /var/www/html
RUN chown -R nobody.nobody /var/www/html

ENV ENV_SUBSTITUTION_ENABLE=true
ENV PHP_MEMORY_LIMIT=512M
ENV PHP_FPM_LISTEN=9090
ENV PHP_SESSION_GC_MAXLIFETIME=7200
ENV NODE_ENV production

USER nobody

EXPOSE 80
CMD ["php-fpm"]

When building, then running I get the following error:

/envsubst.sh: line 14: can't create /usr/local/etc/php-fpm.conf: Permission denied

If I remove "USER nobody", then I can clear this permission denied problem, but now get an Empty Response error from the webserver. I believe the port is 80 for Nginx.

I'm now trying to get "FROM joseluisq/php-fpm:8.1" working instead... but still getting empty responses. Perhaps my /var/www/html is bad location.

Do you know of a better way to accomplish what I am trying to do here?

joseluisq commented 1 year ago

Just to remark that this image is obviously thought to integrate with Nginx/Apache in a multi-service context without including those web servers intentionally.

Do you know of a better way to accomplish what I am trying to do here?

I never tried both in the same image but here are some options that come to my mind:

maietta commented 1 year ago

Thank you for the quick reply.

I spent all morning tryin to come up with a solution to no avail, so I ended up putting together similar to my php7 repo while looking at numerous projects including yours for inspiration.

I've just now released this at https://github.com/PremoWeb/alpine-nginx-php8.

The reason I want to use your version is because I build a lot of projects that use older versions of PHP for legacy applications and am slowly bringing them to PHP 8. Using your project makes sense for me, but this one issue is a deal breaker for me.

Based on your answer, I'll keep investigating how this could adopted and if so, I'll update this issue. For now, I will close it.

Again, thank you.