Composer integration



You can now configure and run Linux for PHP containers for your PHP projects without ever touching the Docker command line!

You can create a custom configuration for each PHP project you have and launch the Linux for PHP containers directly from within your projects' working directories!

Installation and configuration

To install the Linux for Composer package, you can simply run the following commands:

composer require linuxforphp/linuxforcomposer
php vendor/bin/linuxforcomposer.phar

NOTE: On Windows, please use the Linux for Composer PHAR file in the 'vendor/linuxforphp/linuxforcomposer/bin' folder.

You will now be able to modify the 'linuxforcomposer.json' file according to the specific needs of your project.

Here are the main configuration settings:

  • php-versions (required):
    • Default: none.
    • You can choose from 7.3.0dev (bleeding edge dev version), 7.2.5, 7.1.16, 7.0.29 and/or 5.6.35.
    • If you choose many versions, Linux for Composer will start a detached container for each chosen version.
    • If you choose only one version, enter '/bin/bash' in the script section (see below) and do not ask for the 'detached' mode in the modes section (see below), you will get an interactive shell.
    • Finally, if you enter a version number like '7.3.0' (without the 'dev' part), Linux for Composer will COMPILE the latest version from source!!! Now, that's really bleeding edge, isn't it?
  • modes (optional):
    • Default: detached mode.
    • Three possible modes: detached, interactive and tty.
    • Precedence: detached mode.
  • ports (optional):
    • Default: none.
    • You can decide to share many ports from the host system with your containers.
    • If you enter many port mappings for each shared port, Linux for Composer will share each mapping with one container in the order they were given. For example, 'port1' contains two mappings (8181:80 and 8282:80) and so does 'port2' (13306:3306 and 13307:3306). The first element of each mapping (8181:80 and 13306:3306) will be given to container 1, which corresponds to the first given PHP version in the 'php-versions' section (see above). The second element of each mapping (8282:80 and 13307:3306) will be given to container 2.
  • volumes (optional):
    • Default: none.
    • You can share volumes between the host and your containers.
    • Each volume will be shared with each and every container.
    • Linux/Unix/Mac users can insert Bash environment variables in this part of the JSON file. For example, you can share your current working directory with your containers by entering: "${PWD}/:/srv/www". This will make your working directory available to the web server inside the Linux for PHP container.
    • Windows 10 users must make sure to turn volume sharing on in the Docker settings.
  • script (optional):
    • Default: 'lfphp'.
    • You can enter any command that you wish to execute as soon as the Linux for PHP container has finished starting. The most common ones are 'lfphp' and '/bin/bash', But, you could also execute a PHP script directly or launch one of our recipes from the LfPHP Cookbook section of this website. For example, to install automatically, you could enter : "'/bin/bash -c \"cd ; wget -O tmp ; /bin/bash ./tmp ; echo '<?php phpinfo();' > /srv/www/index.php ; /bin/bash\"'". Please don't forget the single quotes at the beginning and the end of the string, and to escape the double quotes to avoid invalidating your JSON!
  • thread-safe (optional):
    • You can decide to run the Zend thread-safe ('true') or non-thread safe ('false') versions of PHP.
    • Default: 'false'

Here is the distribution's version of the 'linuxforcomposer,json' file:

    "name": "linuxforphp/linuxforcomposer",
    "description": "A Composer interface to run 'Linux for PHP' Docker containers.",
    "php-versions": [
    "modes": {
        "mode1": "detached",
        "mode2": "interactive",
        "mode3": "tty"
    "ports": {
        "port1": [
    "volumes": {
        "volume1": ""
    "script": "lfphp",
    "thread-safe": "false"


Once you are done modifying the JSON file, you can start the container or containers by issuing the following command:

php vendor/bin/linuxforcomposer.phar docker:run start

In order to stop all the containers that were started using Linux for Composer, please enter the following command:

php vendor/bin/linuxforcomposer.phar docker:run stop

One final note: you can install Linux for Composer for your entire system by copying the binary in a folder that is in your PATH:

cp vendor/linuxforphp/linuxforcomposer/bin/linuxforcomposer.phar /usr/local/bin/linuxforcomposer

You would then be able to invoke the binary directly from within the working directories of your PHP projects:

cd /my/favorite/php/project
linuxforcomposer docker:run start

Have a lot of fun!