Member-only story
1+n PHP versions and projects via LaraDock
I found myself in a peculiar situation — working with multiple, legacy and greenfield, PHP projects thus in need to have my local development environment supporting 7.1.x, 7.2.x and 7.4.x.
My choice for a local PHP development environment is Laradock, love this project. It does support multiple project setup but sadly, at the moment of writing, does not support multiple PHP versions. There’s an open issue from 2017 with recent (2019) updates which talks about this challenge.
This was a must-have for me.
The Process
- Clone LaraDock.
- Get your
.env
in order. - Amend
docker-compose.yml
to introduce newphp-fpm
services. - Configure NGINX sites to use different
php-fpm
services. - PHP extensions and Composer.
Let’s discuss every step in more details.
Clone Laradock
The setup was done and tested with v9.5 tag.
If you are running LaraDock from a master branch, or later on, decide to update to a newer tag, make sure to stash local docker-compose.yml
changes before you pull, and pop afterwards.
$ git clone git@github.com:laradock/laradock.git
$ cd laradock
$ git checkout v9.5
Get your .env in order
By default .env
is well configured and whit out any change can cover the majority of web projects. If change is needed it’s usually project-specific.
My common tweaks are:
- PHP version
- MySQL version
- Node version
- Enable Python
Do explore the .env
file and various configuration flags. I bet (if you aren’t familiar with LaraDock) you’ll be amazed how much this single, Docker-based development environment can cover for you.
Amend docker-compose.yml
The goal is to introduce 1+n php-fpm
services which run different versions of PHP.
By default, you get one php-fpm
service where PHP version is controlled with PHP_VERSION
flag in the .env
file.
This is your “master” php-fpm
service and should run the newest PHP version, the same version applies to PHP CLI inside workspace
container. At the moment…