Last active
November 8, 2019 17:41
-
-
Save Majkl578/08bb58780344603ad253a9e3b0552eb0 to your computer and use it in GitHub Desktop.
Dockerized example for article at Pehapkari.cz about running multiple PHP versions: 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/* | |
# install PHP 7.0 | |
RUN apt-get update && \ | |
apt-get install -y php7.0-cli php7.0-fpm --no-install-recommends && \ | |
rm -rf /var/lib/apt/lists/* | |
# install PHP 5.6 | |
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 | |
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.0 -v | |
RUN php5.6 -v | |
RUN php -v | |
# clear active virtual hosts | |
RUN rm -f /etc/nginx/sites-enabled/* | |
# prepare PHP 7.0 virtual host | |
RUN mkdir /var/www/site-with-php7.0 | |
COPY index.php /var/www/site-with-php7.0/index.php | |
COPY site-with-php7.0.vhost /etc/nginx/sites-available/site-with-php7.0 | |
# 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.0 /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 /run/php | |
EXPOSE 8870 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 8870 default_server; | |
listen [::]:8870 default_server; | |
server_name _; | |
root /var/www/site-with-php7.0; | |
index index.php; | |
location / { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/run/php/php7.0-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:php70] | |
command = php-fpm7.0 -F -y /etc/php/7.0/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 multiphp . | |
docker run --rm -P multiphp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated PHP70 to PHP71
$ git clone https://gist.github.com/2fca8bfdc5004bade15bac84b9ab73e7.git tmp/multiphp
$ docker build -t nginx-multiphp tmp/multiphp
$ docker run -p 8856:8856 -p 8871:8871 --rm -P nginx-multiphp
http://localhost:8856
for PHP56 andhttp://localhost:8871
for PHP71 accordingly.