Change php version in laradock

Abdul Wahab
1 min readAug 27, 2018

--

I have some projects which are running php 5.6 and some uses 7.1 or whatever and i use laradock a docker container

So to use different versions of php with same container

Switch php version by changing PHP_VERSION in .env file and then run the following to rebuild php-fpm and cli

docker-compose build php-fpmdocker-compose build workspace

and then restart the container

Changing PHP version with all these commands is cumbersome so i created a shell script to change version. for that either clone the repo https://github.com/abdulwahabkhan1/laradock-change-php
and run shell with version as a parameter or create a xyz.sh file in laradock folder and add these lines

#!/bin/bash
version=$1
echo 'changing Php Version to '$1;
###change version in env file
sed -i '.bak' "s/PHP_VERSION=.../PHP_VERSION=$1/g" '.env'
### Build fpm and cli for new version
docker-compose build php-fpm
docker-compose build workspace
### Restart Container to use new version of php
docker-compose down
docker-compose up -d nginx mysql workspace redis

give file permission chmod 700 xyz.sh and then run with the version as parameter

./xyz.sh 5.6

--

--