-
-
Save leymannx/2fca8bfdc5004bade15bac84b9ab73e7 to your computer and use it in GitHub Desktop.
[Updated PHP7.0 to PHP 7.1 ] Dockerized example for article at Pehapkari.cz about running multiple PHP versions on NGINX: https://pehapkari.cz/blog/2017/03/27/multiple-php-versions-the-easy-way/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM debian:stretch | |
ENV DEBIAN_FRONTEND noninteractive | |
# install NGINX | |
RUN apt-get update && \ | |
apt-get install -y nginx --no-install-recommends && \ | |
rm -rf /var/lib/apt/lists/* | |
# set repository | |
RUN apt-get update && \ | |
apt-get install -y apt-transport-https ca-certificates curl gnupg --no-install-recommends && \ | |
rm -rf /var/lib/apt/* | |
RUN curl https://packages.sury.org/php/apt.gpg | apt-key add - | |
RUN echo 'deb https://packages.sury.org/php/ stretch main' > /etc/apt/sources.list.d/deb.sury.org.list | |
# install PHP 7.1 | |
RUN apt-get update && \ | |
apt-get install -y php7.1 php7.1-cli php7.1-fpm --no-install-recommends && \ | |
rm -rf /var/lib/apt/lists/* | |
# install PHP 5.6 | |
RUN apt-get update && \ | |
apt-get install -y php5.6-cli php5.6-fpm --no-install-recommends && \ | |
rm -rf /var/lib/apt/lists/* | |
# verify versions | |
RUN php7.1 -v | |
RUN php5.6 -v | |
RUN php -v | |
# clear active virtual hosts | |
RUN rm -f /etc/nginx/sites-enabled/* | |
# prepare PHP 7.1 virtual host | |
RUN mkdir /var/www/site-with-php7.1 | |
COPY index.php /var/www/site-with-php7.1/index.php | |
COPY site-with-php7.1.vhost /etc/nginx/sites-available/site-with-php7.1 | |
# prepare PHP 5.6 virtual host | |
RUN mkdir /var/www/site-with-php5.6 | |
COPY index.php /var/www/site-with-php5.6/index.php | |
COPY site-with-php5.6.vhost /etc/nginx/sites-available/site-with-php5.6 | |
# enable the virtual hosts | |
RUN ln -s ../sites-available/site-with-php5.6 /etc/nginx/sites-enabled | |
RUN ln -s ../sites-available/site-with-php7.1 /etc/nginx/sites-enabled | |
# (Docker-specific) install supervisor so we can run everything together | |
RUN apt-get update && \ | |
apt-get install -y supervisor --no-install-recommends && \ | |
rm -rf /var/lib/apt/lists/* | |
COPY supervisor.conf /etc/supervisor/supervisord.conf | |
RUN mkdir -p /run/php | |
EXPOSE 8871 8856 | |
CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
phpinfo(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 8856 default_server; | |
listen [::]:8856 default_server; | |
server_name _; | |
root /var/www/site-with-php5.6; | |
index index.php; | |
location / { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/run/php/php5.6-fpm.sock; # adjust for the listen setting discussed above | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 8871 default_server; | |
listen [::]:8871 default_server; | |
server_name _; | |
root /var/www/site-with-php7.1; | |
index index.php; | |
location / { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/run/php/php7.1-fpm.sock; # adjust for the listen setting discussed above | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[supervisord] | |
nodaemon = true | |
[program:php71] | |
command = php-fpm7.1 -F -y /etc/php/7.1/fpm/php-fpm.conf | |
user = root | |
autostart = true | |
[program:php56] | |
command = php-fpm5.6 -F -y /etc/php/5.6/fpm/php-fpm.conf | |
user = root | |
autostart = true | |
[program:nginx] | |
command = /usr/sbin/nginx -g 'daemon off;' | |
user = root | |
autostart = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
docker build -t nginx-multiphp . | |
docker run -p 8856:8856 -p 8871:8871 --rm -P nginx-multiphp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions
$ git clone https://gist.github.com/2fca8bfdc5004bade15bac84b9ab73e7.git test/multiphp
$ docker build -t nginx-multiphp test/multiphp
$ docker run -p 8856:8856 -p 8871:8871 --rm -P nginx-multiphp
http://localhost:8856
for PHP56 andhttp://localhost:8871
for PHP71 accordingly.