Use PHP in the version you prefer with nothing more than Docker installed (for development purpose).
curl -fsSL https://raw.githubusercontent.com/jclaveau/docker-php-multiversion/master/installer.sh | sh
Or with bpkg/bpkg
sudo bpkg install -g jclaveau/docker-php-multiversion
$ php 7.1 spec/phpversion.php
$ 7.1
$ php 7.1 5.6 spec/phpversion.php
$ 7.1
$ 5.6If you installed PHP locally it's still available but only in the version you installed
$ /usr/bin/php spec/phpversion.phpThis works also with phpunit
$ php 7.1 vendor/bin/phpunitand composer
$ php 7.1 /usr/bin/composerYou can list php-multiversion containers (Supporting all options of docker ps)
$ php containers # all running containers
$ php container # container attached to the current directoryYou can kill/rerun containers
$ php kill-containers # all running containers
$ php kill-container # container attached to the current directory
$ php rerun-container # kill then run current container You can also exec whatever you want in the container attached to your current working dir
$ php container-exec bashGet the IP of your container
$ php container-ip- If you create à
host:./logfolder, all the content ofcontainer:/var/logwill be placed inside in realtime. - A call to
php rerun-containeris required if thehost:./logfolder is created after the container is run. - The user who run the container always owns all the content of
host:./log.
- All the content of
<container>:/etcwould be overriden by the content of<host>:<your project path>/etc. - Calling
php config-containerwill prepare a<container>:/etchaving the content<container>:/etc_default - It contains empty files in
./etc/phpwhich are read after the loading of all PHP configurations, enabling you to change any option instantly. - You can read the current config with
php 7.4 -i - You can access directly the current configuration value wth
php container-exec nano /etc/php/7.4/cli/php.inibut it wouldn't persist after a container restart.
This docker image provides all PHP versions available in Ondřej Surý's PPA.
For production purpose I recommend jtreminio/php-docker image which provides a light image of PHP in any version of the same PPA.
My use case is presently centered around php-cli and I have a lot of work before matching my expectations but using it as a multiversion cli provider could be interesting also later.
