How to install php-cs-fixer in PHPStorm

As we know, php-cs-fixer is a strongly recommended tool for automatically formating php code according to the PSR standards. However, installing it is a big problem. I spent three hours to install successfully. Now, I would like to share my experience with you.

First, my environment consists of PHPtorm 2023.1.2 running on a standalone pc with Windows 11.

  1. Don't install the 'php-cs-fixer' plugin from the PHPStorm marketplace of if you have the same environment as I do.
    I believe that the plugin is intended for UNIX/Linux developer rather than Windows developer. If you check its homepage, you will see that the reviews are not favorable.

  2. The following steps have been verified successfully:

a. Run the command in the windows CLI:

composer global require friendsofphp/php-cs-fixer

To verify a successful install, you can run:

php-cs-fixer --version

b. In phpstorm, go to 'File > Setting > PHP > Quality Tools', click on PHP CS Fixer and configure it:
image

c. On the configuration screen, it is best to select the absolute path to 'php-cs-fixer.bat' after clicking '...' on the right of the 'Configuration' field:
image
The file is generally located at 'C:\Users{your user name}\AppData\Roaming\Composer\vendor\bin**php-cs-fixer.bat**'. You can get the path using dash command in CLI:

where.exe php-cs-fixer

d. In phpstorm, go to 'File > Setting > Tools > File Watcher', click on + and configure it:
image

Congratulations! you can now use the PHP-CS-Fixer to format your code. Open a php file, edit it or save it, PHP-CS-Fixer runs automatically. You can see the process details in the output window.

posted @ 2025-10-21 13:39  繁星灼灼  阅读(7)  评论(0)    收藏  举报