Tom Butler's programming blog - an Easy to set up development environment for Docker

Introduction is a small and very easy to use virtual server. If you're inexplicably still using XAMPP in 2021 or just want to run a server without doing any configuration yourself, this is a good starting point for using Docker.

It's designed for anyone who wants a quick and easy to set up web development server with a lot of flexibility. It's been built with portability and ease of use in mind. The server will run pages on the url after it's been booted with the docker-compose up command and no further configuration.

The source code is available in this github repository:

Getting started

  1. Install Docker for your operating system (for Linux you can install docker and docker-compose through your distribution's package manager)
  2. Create a folder where your website is going to be stored
  3. Open a terminal at that location (Windows, have the folder open then click File -> Open Windows Powershell)
  4. Run docker run --rm -v ${PWD}:/install vjedev/installer:latest (this command downloads the configuration files used in the next step)
  5. Run docker-compose up -d (the command may take a few minutes to finish the first time you run it, subsequent runs will be quick)
  6. Navigate to in your browser
  7. To make files visible on the server put them in the websites/default/public folder that was created.


  1. All hosted websites use HTTPS with a valid SSL certificate from Let's Encrypt
  2. No configuration needed. Run docker-compose up and your website is hosted on
  3. Without configuration host different websites on subdomains e.g. and
  4. Includes up to date PHP development software*:
    • PHP
    • NGINX
    • MariaDB
    • Composer
    • PHPUnit
  5. Portability: You can run docker-compose stop on one machine, copy the folder, then docker-compose up on another and your website will be visible. The database is automatically imported and exported. Most environments store the database inside a local volume. If you move your files to a different PC the database is lost. That's not the case with this environment.
  6. URL rewriting is already set up. A request to any file that does not exist is sent to index.php


Connect to MySQL from your desktop using:

  • Host:
  • Port: 3306
  • Username:
  • Password:

To connect to the server from PHP you must use mysql as the host. For example:

= new PDO('mysql:dbname=test;host=mysql''''');

This MySQL user has full access to create schemas and other users. I suggest using MySQL Workbench but you can install the clunky PHPMyAdmin tool if you want a worse experience.

Starting and stopping the server

To start the server, run the command docker-compose up -d from the project's directory.

To stop the server, run the command docker-compose down from the project's directory

Hosting multiple websites

The environment is configured to host multiple websites from different folders within the created websites directory. To create a new website which is available on

  1. Create the directory mysite inside the websites directory.
  2. Create the directory public inside the mysite directory.
  3. Place your web-accessible files inside the websites/mysite/public directory. For example, the file in websites/mysite/public/phpinfo.php will be accessible on the URL

Any directory you create inside the websites directory is treated as a subdomain of

Easily import databases

You can import an SQL database automatically while the server is running. Create the file websites/import.sql, the SQL script inside the file will be executed and the import.sql file deleted.


To run PHPUnit tests you can use the command:

docker-compose run phpunit

This will run PHPUnit from the context of the websites/default directory and look for phpunit.xml at the path websites/default/phpunit.xml. If you wish to run unit tests for another directory you can specify it as a command line argument. For example to run php unit tests from the websites/subdomain directory you can run the command

docker-compose run phpunit /websites/subdomain


Composer is included and like PHPUnit defaults to the websites/default directory. Running the following command:

docker-compose run composer require level-2/dice

Will create a vendor directory and install Dice Dependency Injection Container in websites/default/vendor. To specify a different folder, pass the directory to the command using the -d switch:

docker-compose run composer require level-2/dice -/websites/subdomain