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.
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!
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
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.