• Home
  • -
  • Setting up a PHP Docker Environment

Setting up a PHP Docker Environment

TLDR

We've prepared the following GIST, that will configure a PHP & Apache docker environment in which you just need to start and add your project files.

curl -o https://gist.githubusercontent.com/SamJUK/5021c6da0059b0a033114bad49cf6a03/raw/018c6c8f1f14841d5ede352f6cc6e85fa7596ee4/m2docker.sh | sh;
cd project-name && docker-compose up -d

Why should I?

There are many reasons to use docker, but the main points that cause us to is;

Independent Application Versions

Being able to use independent application versions is a really nice feature, say you have a few sites with the following configuration.

  • Magento 1 => PHP 5.6
  • Magento 2 => PHP 7.3
  • Laravel => PHP 7.1

Collaboration Versioning

When working on a project within a team, bugs may start to appear on some workstations but not on others. Often caused by inconsistent application versions between them; By using docker it allows your team to deploy the projects environment with the exact same versions as everyone else without affecting their uncontaineraised applications.

How to start

First of all, you need to decide on a domain and update our local hosts file to point it to our machine. For this example we are going to use dockersite.local.

echo "127.0.0.1 dockersite.local www.dockersite.local" | sudo tee -a /etc/hosts

Now that we setup our loopback, we need to create our file structure for the docker project.

- project_base/
    - docker/
        -  db/
        -  xdebug.ini
    -  docker-compose.yml
    -  html/

We can do this with the following command

mkdir -p docker/db html && touch docker-compose.yml docker/xdebug.ini;