Setting Multiple PHP runtime
In our last post we’ve successfully setup a development environment to develop applications in Laravel, though this setup can be use to build any PHP application. Now suppose for whatever use case if we need to test our application for different PHP version than our current one, it’d be very complex and messier process to do it in our host machine with native setup. But with docker we can do this without any hassle (also it can be achieved in many other ways e.g vagrant).
We’ll install php 5.6 version. Everything will be same as the way we installed php 7 earlier. We’ll use php:5.6-fpm image from docker hub.
Do not select any network for the container right now, we will do it later.
We will map our sites directory to the /var/www directory in the container.
Finally in Command tabs put /var/www as value in Working Dir field
Now start the container by hitting start container button. Docker will pull the image from docker hub registry and then start a container by php-5.6 name.
Assigning an alias
Now we’ll assign a alias called php for this container so that our nginx configuration works for both php-7 and php-5.6 container. If you look in the nginx config for any application we are forwarding all request from nginx to php:9000. Assigning a alias for php-5.6 container will allow us use the same config for both php container. First stop the container and then run the below command from the command line (portainer doesn’t have an option for assigning alias yet)
docker network connect --alias=php php php-5.6
So the above command connect a container to a network, we’re connecting php-5.6 container to php network and assigning a alias php. Now start the container from portainer. Now you can run all the php application in php 5.6 version. Now if you want to run again in php 7 runtime first stop the php-5.6 container and then start the php 7 container.
Using docker you can easily test your app for different php version above mention way. In next post we’ll see how we to run laravel asset compiling package elixir or mix to compile our frontend stuff.