← Other topics

VSCode PHP CS Fixer: executablePath not found (junstyle)

Video Notes

This guide covers what to do if you’re using the VSCode extension php cs fixer by junstyle and are receiving the following error when the formatter is run:

Error message: PHP CS Fixer: executablePath not found.
PHP CS Fixer: executablePath not found. Try setting `"php-cs-fixer.executablePath": "${extensionPath}/php-cs-fixer.phar"` and try again.

First, let’s check your settings. Open your VSCode settings.json file:

  • View > Command Palette
  • Type in settings and choose Preferences: Open User Settings (JSON)

Make sure you have the following settings:

"[php]": {
    "editor.defaultFormatter": "junstyle.php-cs-fixer"
},
"php-cs-fixer.executablePath": "${extensionPath}/php-cs-fixer.phar",

Still not working? Confirm PHP is available

If you’re still seeing the same error after placing the above settings, it might be because VSCode can't locate an install of PHP on your system in order to execute the php cs fixer program.

To confirm this, try running the command which php in a bash-based command line program. If it reports back that the command is not found, that’s your problem.

To resolve the issue, you need to set up PHP on your computer. There are many ways to do this, but I suggest the following programs that include PHP:

Once you have one of those programs installed, you need to update your VSCode settings telling it where it can find the PHP executable that came with the program. Here are some examples:

Mac with PHP via Herd (Update YourUsername with your username):

"php.validate.executablePath": "/Users/YourUsername/Library/Application Support/Herd/bin/php"

Mac with PHP via XAMPP:

"php.validate.executablePath": "/Applications/XAMPP/bin"

Windows with PHP via Laragon (update the PHP version number as appropriate):

"php.validate.executablePath": "c:/laragon/bin/php/php-8.1.10-Win32-vs16-x64/php.exe",

Windows with PHP via XAMPP:

"php.validate.executablePath": "c:/xampp/php/php.exe",

Optional: Make PHP globally available

The above setting will make it so that VSCode can find PHP on your system, but PHP might still not be available in command line. To make PHP globally available, update your computer’s PATH variable adding one of the above paths so the php command is available globally on your computer. Once you do that, you don’t have to make specific setting changes in VSCode to tell it where PHP is. For instructions on updating your PATH variable, check out one of the following guides:

If this info helped you out you can say thanks and support future content by clicking my Amazon affiliate link: https://amzn.to/3UtgnYk. If you make a purchase on Amazon within 24 hours of clicking the link I may receive a micro-commission and it costs you nothing extra. Any income from these sales goes directly to supporting me in making new videos and guides. Thank you for your support!

← Other topics