Local Docker setup to use PHP CLI without installing it on the host OS. It provides Composer 2 and PHP from 7.1 to 8.1.
Requirements:
- make
- Docker with BuildKit support
Or you can just copy and edit what's in the Makefile.
Clone the repository, then run make setup to build the Docker images and create the Composer cache directory.
Then add a source command to your ~/.bashrc file:
source ~/path/to/LodoPHP/bash_aliasesThe default PHP version is 7.4, the default Composer version is 2. To use a specific PHP version use phpX.Y or composerX.Y:
# PHP 7.4
php --version
# PHP 8.1
php8.1 --version
# Composer 2 using PHP 8.1
composer8.1 installTo change the default PHP version, change the bash_aliases file:
alias php='phpX.Y'
alias composer='composerX.Y'You can also create a lodo.conf file in the repository and then rebuild the images:
make buildextensions="pdo_mysql xdebug"
Refer to the mlocati/docker-php-extension-installer support table.
composer_version="2.2.6"
Refer to the Composer image tags on Docker Hub.
PHP Docker images are built using cli-alpine base images, installing Composer.
Bash aliases are used to call the right Docker commands to create a container. Every container is removed when stopped,
uses the host UID:GID and the host network. The current directory is mounted into the container.
Additionnally for Composer, a cache directory is mounted into the container too.
Lodo is functional but still looks like a draft. To make it easier to use, here are the few feature ideas to implement:
- PHP version switch from the command line (nvm style)
- packaging as a single binary