Skip to content

Instantly share code, notes, and snippets.

@realrashid
Last active May 5, 2024 05:14
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save realrashid/59d0f99ed31103ae44291f3c752240b6 to your computer and use it in GitHub Desktop.
Save realrashid/59d0f99ed31103ae44291f3c752240b6 to your computer and use it in GitHub Desktop.
How to Install PHP-CS-Fixer on Windows

Installing PHP-CS-Fixer for VsCode on Windows

Install PHP-CS-FIXER Using Composer

composer global require friendsofphp/php-cs-fixer

after successfully installation of PHP-CS-FIXER

now install PHP-CS-FIXER VSCODE Extension

PHP-CS-Fixer

Configuration

in VSCODE User Settings press Ctrl+, to get VSCODE User Settings

"php-cs-fixer.executablePath": "php-cs-fixer.bat",
"php-cs-fixer.executablePathWindows": "php-cs-fixer.bat",
"php-cs-fixer.onsave": true,
//If you want to create a custom config for php-cs-fixer
//create a .php_cs file in this C:\Users\username\.vscode directory
"php-cs-fixer.config": "C:\\Users\\username\\.vscode\\.php_cs",

That's all! Hope this will help you!

Regard's

Rashid Ali

@ryanbriscall
Copy link

There's no php-cs-fixer.bat, and that executablePath wouldn't work unless the environment variable PATH is updated. This gist is lacking a lot of information.

@realrashid
Copy link
Author

C:\Users\rasho\AppData\Roaming\Composer\vendor\bin\php-cs-fixer.bat
it exists !
it's working in my case.

share your issue what issue are you facing and your os info.

@trevorhawes
Copy link

We need a full step by step instructions on how to install php cs fixer in windows, including the fact that PHP needs to be installed (how, where, what to set up) then exactly what to do next. No luck for me so far. So hard to find good info.

@trevorhawes
Copy link

Is there a way to get it to work without having to install composer. I just want to format some php, not have the whole composer thing

@jaimecosme
Copy link

I extracted both php and php-cs-fixer on the same folder without installing composer.

I then added this lines to my config file and php-cs-fixer is working:
"php.validate.executablePath": "C:\Users\jaime\php-7.2.7-Win32-VC15-x64\php.exe",
"php.executablePath": "C:\Users\jaime\php-7.2.7-Win32-VC15-x64\php.exe",
"php-cs-fixer.executablePath": "C:\Users\jaime\php-7.2.7-Win32-VC15-x64\php-cs-fixer-v2.phar",
"php-cs-fixer.executablePathWindows": "C:\Users\jaime\php-7.2.7-Win32-VC15-x64\php-cs-fixer-v2.phar",

@torressam333
Copy link

When you install composer globally the php-cs-fixer.bat file will be available in your Roaming\Composer\vendor\bin directory. From there you can go in phpstorm and under Languages and Frameworks ->PHP -> Quality Tools -> PHP CS Fixer -> click the ... and set the directory path to your .bat file and you then set it in Editor->Inspections->Quality Tools->PHP CS Fixer Validation. Apply the settings and click ok and you should be good.

@denOldTimer
Copy link

denOldTimer commented Jun 8, 2019

settings.json file
"php-cs-fixer.executablePath": "%USERPROFILE%\\AppData\\Roaming\\Composer\\vendor\\bin\\php-cs-fixer.bat",
"php-cs-fixer.executablePathWindows": "%USERPROFILE%\\AppData\\Roaming\\Composer\\vendor\\bin\\php-cs-fixer.bat",
"php-cs-fixer.config": "%USERPROFILE%\\.vscode\\.php_cs",

@kareemadesola
Copy link

There's no php-cs-fixer.bat, and that executablePath wouldn't work unless the environment variable PATH is updated. This gist is lacking a lot of information.

Same here and I don't know what to do.

@realrashid
Copy link
Author

realrashid commented Apr 10, 2020 via email

@fdlmhmd29
Copy link

This is work just fine on my Windows. Thank's a lot btw.

@akiyoko
Copy link

akiyoko commented Sep 10, 2021

I usually use Local by Flywheel on Windows, and I did not install PHP locally.
In that case, it seems that you need to install PHP separately.

The first step is to go to
https://www.php.net/downloads
from the "Windows downlaods" link at to install PHP in C:\php.

Next, download php-cs-fixer-v3.phar from the following link and place it in ~/.vscode/.
https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/installation.rst

Finally, add the following lines to settings.json and it works fine.

    "[php]": {
        "editor.defaultFormatter": "junstyle.php-cs-fixer"
    },
    // "php.executablePath": "C:/php/php.exe",
    "php.validate.executablePath": "C:/php/php.exe",
    "php-cs-fixer.onsave": true,
    "php-cs-fixer.executablePath": "~/.vscode/php-cs-fixer-v3.phar",

@LuisCardeBu
Copy link

I usually use Local by Flywheel on Windows, and I did not install PHP locally. In that case, it seems that you need to install PHP separately.

The first step is to go to https://www.php.net/downloads from the "Windows downlaods" link at to install PHP in C:\php.

Next, download php-cs-fixer-v3.phar from the following link and place it in ~/.vscode/. https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/installation.rst

Finally, add the following lines to settings.json and it works fine.

    "[php]": {
        "editor.defaultFormatter": "junstyle.php-cs-fixer"
    },
    // "php.executablePath": "C:/php/php.exe",
    "php.validate.executablePath": "C:/php/php.exe",
    "php-cs-fixer.onsave": true,
    "php-cs-fixer.executablePath": "~/.vscode/php-cs-fixer-v3.phar",

This is the one that worked for me, thanks!!

@realrashid
Copy link
Author

realrashid commented Mar 27, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment