The other day, I encountered an issue while trying to use Composer with PhpStorm in my local environment. Every time I would try to install or update packages, I would get an error message of the following format:
This issue was happening because my local environment was not a carbon copy of my sandbox or production environments. In fact, it was only meant to write code; any kind of testing, be it manual or automated, had to be done on the sandbox environment.
Thankfully, Composer has the
--ignore-platform-reqs flag, which allows us
to deal with this issue. Composer’s official documentation
defines the flag as such:
–ignore-platform-reqs: ignore all platform requirements (
ext-*) and force the installation even if the local machine does not fulfill these.
Thus, instead of running…
… one would run:
composer install --ignore-platform-reqs
All well and good, right? Not quite: there was no way to use this flag within my version of PhpStorm! 🤯 After some research, here are the solutions I have found. I hope one of them will be useful to you.
Update your version of PhpStorm
The latest versions of PhpStorm do support the
It can be set by clicking on File in PhpStorm’s menu, then on Settings,
PHP and Composer. You will see a checkbox labeled Run install/update with
Provided you aren’t stuck with your current version of PhpStorm, you might think that this
is the best method to run Composer with the
--ignore-platform-reqs flag. However, as of
PhpStorm 2022.3.1, this setting is not persistent. In other words, every time you restart
PhpStorm, you have to recheck the box for the flag to be applied. I assume this is a bug
and that it’s going to be fixed eventually. In the meantime, it may or may not be a deal
breaker to you.
Add the flag through scripting
For this workaround, we will add ourselves the
--ignore-platform-reqs flag whenever
PhpStorm is calling the
require command through Composer. The benefit
of this method is that it works even on older versions of PhpStorm.
First of all, you have to locate your
composer.phar file. Once this is done, create a
batch file with the following code and save it next to your
composer.phar. If you are
on Mac or Linux, you will need to convert the code below into Bash. I named my script
1:: Written by Pascal Bergeron
9if %COMMAND%==install set IGNOREPLATFORMREQS=true
10if %COMMAND%==update set IGNOREPLATFORMREQS=true
11if %COMMAND%==require set IGNOREPLATFORMREQS=true
13if %IGNOREPLATFORMREQS%==true (php "%~dp0composer.phar" %* --ignore-platform-reqs) else (php "%~dp0composer.phar" %*)
In PhpStorm, go to the menu, click on File, Settings, PHP and Composer. Under the Execution section, check the ‘composer’ executable box and enter the path to your newly created script file. Validate the changes.
Rely on an environment variable
In your operating system, create an environment variable named
and set its value to
1. They are two downsides to this method:
- It doesn’t work with older versions of Composer. You need Composer 2.3.0-RC1 or above.
- Since the environment variable is a global variable, it might have adverse effects on other projects that depend on Composer.