Use composer and bin/console from your Docker image directly within PHPSTORM

Okay, you are like me. Your machine has nothing installed locally. Not even composer nor PHP in CLI!

While you use PHP and maybe even Symfony (or not), you need to use composer daily. You use PhpStorm every day and think it's a shame not to benefit from all the options of your IDE, especially everything related to composer and the Symfony console. So how do you configure PhpStorm to specify that the composer for your project is located in the docker image?

Here is an example of docker-compose.yml In actuality, you will use yours with your php/composer inside.

version: "3.8"
    image: 'devpartitech/php:7.4-apache'
      - "80:80"
      - "./:/var/www/"
      - host.docker.internal:host-gateway

Know that installing composer in your image is extremely simple, you just need to copy the composer from an already prepared image 😊

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

So now how do we tell PhpStorm that we want to use /usr/local/bin/composer from our container?

Go to File > Settings > PHP > Composer


At this point nothing is done yet. So, you will check Synchronize ide Settings with composer.json and Remote Interpreter.


On the “…” from CLI Interpreter, you will create a new configuration.


Naturally, choose From Docker.


You will have several options available to you. You could directly link to a specific docker image. Personally, I choose my docker-compose which allows me to select the service I want to use. My docker-compose is extremely simple. It has only one service and everything I need is there.


Regarding the configuration, I personally choose to use the connection to the existing service since I use the docker-compose. If I had used a docker container directly, I would have used the “always start a new container” option. Do not forget to click on the refresh button at the end of General > PHP executable to confirm everything is present.


Eventually, you will have a small banner at the top when you open your composer.json file


You will have access to the options directly to install / update, show log lets you see what is really happening in your container. After your commands, you have access to options that allow you to launch more commands.


You also have the possibility to execute your scripts directly from the green arrow to the left of your code.


Now that our first step is configured, let's add composer and the Symfony console directly to PhpStorm's “Run Anything” system; the famous window that opens when you press CTRL twice.

Open the configuration window File > Settings, go to the configuration of Tools > Command line Tool Support and click on the small “+” to add a new configuration.

A configuration window should appear. Click on the small “+” to create a new configuration.


You will have a small configuration window like this with several choices, including composer and Symfony that we will both configure.


Let's start by configuring composer:


Once registered, you should have a small message indicating that several commands have been found. That's rather a good sign 😺


Personally, I changed the alias to put composer, by default PhpStorm will put “c”. We do the manipulation again but this time with Symfony.


As usual, choose your interpreter. I choose my container from my docker-compose, and I choose the desired version of Symfony. Honestly, if you haven't chosen 3.* 4.* there's a serious problem 😺 Note that if you have a hard time upgrading your Symfony application to the latest version, we know how to do it and we'll be delighted to help you ^^


Again, I change the alias. I prefer to put “console”. A matter of habit 😺


That's it! We are ready to test everything. Press CTRL twice. The “Run anything” window will open.

Type console and you will see all your Symfony commands appear. And as it's magic, they will execute directly in your container.