3

We have a php application which was running fine using Docker Image :

php:7.2-apache-stretch

We now have to make use of the below image for better performance and make the application work as it was before .

php:7.2.17-fpm-stretch

As this image does not have apache in it . I updated the Dockerfile starting from the installation of apache2 and related packages based on various forums .

There is many other steps . I have just added the instructions which I have updated in the Dockerfile.

 FROM php:7.2.17-fpm-stretch

RUN apt-get update && apt-get install -y apache2 wget

RUN cd /tmp && wget http://mirrors.kernel.org/ubuntu/pool/multiverse/liba/libapache-mod-fastcgi/libapache2-mod-fastcgi_2.4.7~0910052141-1.2_amd64.deb && dpkg -i libapache2-mod-fastcgi_2.4.7~0910052141-1.2_amd64.deb;apt-get install -f

RUN a2enmod actions proxy_fcgi fastcgi
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
COPY info.php /var/www/html/info.php
COPY run.sh /app/run.sh
# EXPOSE 9000
RUN chmod 755 /app/run.sh
CMD "/app/run.sh"

The info.php contains <?php phpinfo( ); ?> . In the run.sh script , we start the php-fpm service and apache2 as below

php-fpm -D

/usr/sbin/apachectl -D FOREGROUND

previously I was trying to access the app from the port which was mapped to 9000 ( fpm ) . When I accessed the correct port where apache was running , I was able to view info.php .

The Content in the vhost.conf file.

<FilesMatch \.php$>
  SetHandler "proxy:fcgi://localhost:9000"
</FilesMatch>

3 Answers 3

3

I got it working making a few modifications.

I used this slightly modified dockerfile:

FROM php:7.2.17-fpm-stretch

RUN apt-get update; apt-get install -y apache2 wget

RUN cd /tmp && wget http://mirrors.kernel.org/ubuntu/pool/multiverse/liba/libapache-mod-fastcgi/libapache2-mod-fastcgi_2.4.7~0910052141-1.2_amd64.deb && dpkg -i libapache2-mod-fastcgi_2.4.7~0910052141-1.2_amd64.deb;apt-get install -f


RUN a2enmod actions proxy_fcgi fastcgi

COPY run.sh /app/run.sh
RUN chmod 755 /app/run.sh
CMD "/app/run.sh"

I also added the following snippet (the same modification you did) to /etc/apache2/sites-available/000-default.conf:

<FilesMatch \.php$>
  SetHandler "proxy:fcgi://localhost:9000"
</FilesMatch>

Here is the output I get:

[09-Apr-2019 21:23:06] NOTICE: fpm is running, pid 9
[09-Apr-2019 21:23:06] NOTICE: ready to handle connections
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

Also, did you try building the dockerfile without the cache? Sometimes, caching can cause issues with package installation (see here for more details). To do a clean build of an image, just use:

docker build --no-cache 
Sign up to request clarification or add additional context in comments.

4 Comments

Hello , thanks a lot for the response . I missed to include . I am doing a chmod to the script and I am able to successfully start both process . But I am not sure how this whole things connects . Is my implementation in vhost.conf is correct . If we have a php app like WordPress and I have to host it in Apache server using php-fpm what are the steps to be done .
I added the following snippet to /etc/apache2/sites-available/000-default.conf and it worked for me: <FilesMatch \.php$> SetHandler "proxy:fcgi://localhost:9000" </FilesMatch>
I have updated my Dockerfile . When I try to access the info.php . I am unable to do it . While localhost is able to access index.html . :( .
Its working for a sample.php file . I have a wordpress application which was running in php: . In that Dockerfile the following mods were enabled .
2

I got your new configuration working using this dockerfile:

FROM php:7.2.17-fpm-stretch

RUN apt-get update && apt-get install -y apache2 wget

RUN cd /tmp && wget http://mirrors.kernel.org/ubuntu/pool/multiverse/liba/libapache-mod-fastcgi/libapache2-mod-fastcgi_2.4.7~0910052141-1.2_amd64.deb && dpkg -i libapache2-mod-fastcgi_2.4.7~0910052141-1.2_amd64.deb;apt-get install -f

RUN a2enmod actions proxy_fcgi fastcgi
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
COPY info.php /var/www/html/info.php
COPY run.sh /app/run.sh
RUN chmod 755 /app/run.sh
EXPOSE 80
CMD "/app/run.sh"

The command I ran was:

docker run -P -d --rm <php-image>

The exposed ports are:

0.0.0.0:32773->80/tcp, 0.0.0.0:32772->9000/tcp

I was able to access info.php using http://localhost:32773/info.php

2 Comments

Thanks for the response . Now my wordpress app is working . But I face issue with Rewrite which I have mentioned in .htaccess file . [Wed Apr 10 15:24:03.632495 2019] [proxy_fcgi:error] [pid 15:tid 139956055955200] [client 172.17.0.18:55636] AH01071: Got error 'Primary script unknown\n', referer: local.test.com [Wed Apr 10 15:26:53.354451 2019] [proxy_fcgi:error] [pid 16:tid 139956039169792] [client 172.17.0.18:56056] AH01071: Got error 'Primary script unknown\n', referer: local.test.com
What .htaccess file?
0

I was able to access the php page . Everything was working fine . But I was looking in the wrong direction . When I run the container .

docker run -P -d --rm php:test-fpm

The output was

82071c9ff023        php:test-fpm                    "docker-php-entrypoi…"   2 seconds ago       Up 1 second         0.0.0.0:32778->80/tcp, 0.0.0.0:32777->9000/tcp   practical_mclean

I was accessing localhost:32777/info.php . But I should I accessed the 32778 where apache is exposed and localhost: 32778/info.php worked !!! .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.