Skip to content

Instantly share code, notes, and snippets.

@selfinvoking
Created December 12, 2017 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save selfinvoking/a135123c3ad1c89b1d825233e6985bcc to your computer and use it in GitHub Desktop.
Save selfinvoking/a135123c3ad1c89b1d825233e6985bcc to your computer and use it in GitHub Desktop.
Easily run different PHP versions with nginx, using Docker

Easily run different PHP versions with nginx, using Docker

Using this method will allow you to develop with any version of PHP you require without having to install it or worry about uninstalling other versions.

Method

If you are switching versions you will first want to stop and remove any existing php-fpm docker instance.

docker stop php
docker rm php

Create a php-fpm docker instance. You can replace the ports and workspace directory as required. Change the php-fpm version with any from the list below.

docker run -d -p 9000:9000 -v ~/workspace:/var/www/html -t --name php cytopia/php-fpm-7.2

Configure nginx to use this php-fpm docker instance (add this to your nginx config, E.g. /etc/nginx/sites-available/default). You may need to replace any existing location blocks which conflict with this one.

# Allow php only in root index.php
location ~ \.php$ {
    # other settings here...
    fastcgi_pass localhost:9000;
    # other settings here...
}

Don't forget to restart nginx!

Availiable versions

We will use docker images @cytopia, the following versions are available: (It would be easy to run other versions, you would just need to create your own php-fpm docker image)

  • 5.4
  • 5.5
  • 5.6
  • 7.0
  • 7.1
  • 7.2

Credit

In order to achieve this, we are using some docker images from @cytopia. Be sure to check out their awesome app Devilbox - A modern dockerized LAMP and MEAN stack alternative to XAMPP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment