Skip to main content

Install a PHP Docker environment in a matter of seconds

Quickly set up a PHP Docker Dev Container environment for VSCode. Get Composer and pre-installed static analysis tools like PHP-CS-Fixer and Rector instantly.

· 6 min read
View raw
Christophe
Markdown, WSL and Docker lover ~ Insatiable curious.
Cet article existe aussi en français — lire la version française.

This article is over a year old but was reviewed on July 30, 2026 — the content is still accurate.

Install a PHP Docker environment in a matter of seconds

⚡
TL;DR

This is the short, quick-start version of the full devcontainer article: download the php_devcontainer skeleton with curl, open the folder in VSCode, and click "Reopen in Container" to get a ready-to-use PHP environment with Composer, PHP-CS-Fixer, PHPCS/PHPCBF, SonarLint and Rector preinstalled — for both brand-new projects and existing codebases.

This article is the very short and straightforward version of PHP development in a devcontainer with preinstalled code quality tools. If you just want to follow a very few steps and get your PHP environment, this article is for you.

By following the steps described in this article, you'll obtain

  • A Docker PHP environment so you can code using vscode,
  • The PHP composer package manager installed,
  • A few static analysis tool like php-cs-fixer, phpcs, phpcbf, sonarlint and Rector installed
  • A devcontainer ready-to-use environment.

Just follow the guide...

The aim of this article is to create a development environment (aka devcontainer)

Please refers to my other articles about Docker to see how to Dockerize the application and be able to run the application using Apache and a database service like PostgreSQL.

What the environment gives you​

Here is PHP-CS-Fixer reformatting a file, inside the container, a couple of minutes after the download — nothing installed on my host machine, no PHP, no Composer, no extension to configure:

PHP-CS-Fixer

The same is true for PHP_CodeSniffer (phpcbf.phar), Rector and SonarLint: they're already in the image, already configured through the .config folder shipped with the skeleton. You'll find the exact commands in the You are ready to use tools section below.

Two ways to get there, depending on whether you're starting from scratch or adding this to an existing codebase.

You have nothing and wish to create a fully new project​

1. Install the php_devcontainer skeleton​

For this blog article, I'll create a temporary folder in /tmp/devcontainer_php. Don't hesitate to update the path to something like ~/my_project to match your need.

>user@machine: ~/yourproject

Download a specific version

If you don't want to download the latest version but a given one, specify the tags like: curl -LOJ --silent https://github.com/cavo789/php_devcontainer/archive/refs/tags/1.0.0.tar.gz.

You've thus downloaded code from my https://github.com/cavo789/php_devcontainer repo into your folder.

2. Open VSCode​

Start VSCode on your machine:

>user@machine: ~/yourproject

3. Switch to the Dev Container​

VSCode will automatically suggest opening a Dev Container. Click on the Reopen in Container button.

VSCode automatically suggests opening a Dev Container

If you don't have this popup, just press CTRL+SHIFT+P to open the Command Palette and search for Dev Containers: Rebuild and Reopen in Dev Container and click on it.

VSCode will now take a while to build the Docker image then start a Docker container before you can work. It can take a few minutes depending on the speed of your machine.

You are ready to use tools​

Press CTRL+ù to open the Terminal pane and type there /usr/local/bin/php-cs-fixer.phar fix --config /var/www/html/.config/.php-cs-fixer.php index.php to run PHP-CS-Fixer — that's the command that produced the screenshot at the top of this article.

You can also run /usr/local/bin/phpcbf.phar --standard=/var/www/html/.config/phpcs.xml /var/www/html/index.php for reformatting your code using PHP_CodeSniffer.

You can run Rector too by running vendor/bin/rector process index.php --config .config/rector.php.

As you can see, in just three actions you've downloaded and installed a functional PHP environment using Docker and VSCode.

You already have an existing project​

In a real-life use case, you already have a PHP project.

Start a terminal and open the folder where you've your codebase.

For this blog post, I'll download a very old learning Laravel codebase I've done years ago:

>user@machine: ~/yourproject

So, my project will be in folder /tmp/laravel_todos.

In my project folder, now, I'll run:

>user@machine: ~/yourproject

This will download the PHP devcontainer files in my project.

I will run code . to open VSCode and, like before, VSCode will suggest opening the folder in a Dev Container. Let's do this.

And voilà, I've Dockerized my PHP coding environment. In my case, I've made Laravel Todos in 2018, using PHP 7.1.3 and Laravel 5.x; an eternity then.

And like in the previous chapter, I can run the commands below to fix coding style issues and fixes all files in my repo:

>user@machine: ~/yourproject

And I will be able to run Rector to refactor my entire codebase:

>user@machine: ~/yourproject

but in my case, I can't right now because my Laravel Todos is an old one and I need first to make some changes to my composer.json file (upgrading PHP and Laravel versions first).

Conclusion​

A curl, a tar and a click on Reopen in Container: that's the whole distance between an empty folder and a PHP environment where the quality tools are already there, at the same version for everyone who clones the repository. Nothing has been installed on your machine, and deleting the folder deletes the environment.

Same recipe, other stacks: Docker - Python devcontainer. And when the time comes to ship, One Docker Image for Production and Devcontainers - The Clean Way shows how to keep all this tooling out of your production image.


Was this article helpful?
Did you try the steps in this article?