DEV Community

Cover image for Setup your VSCode as PHP code editor/IDE
Manuel Ojeda
Manuel Ojeda

Posted on

Setup your VSCode as PHP code editor/IDE

As you know VSCode became a so popular text editor which can be tuned up to any language development (JavaScript, C, C#, Java, Go, Python and many more). In this post we are going to setup one of the popular backend language, I'm talking about PHP.

Requirements

If you are a Windows user, you can skip installing PHP and Composer in a single step using Laragon, in case you are Linux/MacOS you can follow this guide: https://dev.to/manuelojeda/setup-a-php-dev-enviroment-with-laravel-valet-and-wsl-1pp6

After you have installed all the things mentioned, I suggest you to install this extension in your VSCode:

Settings Sync

This one will let you bring your VSCode configuration anywhere you need it, only vinculate your GitHut account and you are ready to go:
https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync

After having all of this installed let is begin with the dance.

Settings at VSCode

First of all, let's tell VSCode where is the PHP Path is. Go to Settings and type php at the search bar, then look for the section; PHP › Validate: Executable Path then click in Edit in settings.json:

Alt Text

Once you have opened, look of the line that it says: "php.validate.executablePath". If you have it, make sure your php installation path is there, in case you haven't add this rule to your settings.json:

In Linux and Mac should be:

"php.validate.executablePath": "/usr/bin/php"

In Windows should be:

"php.validate.executablePath": "c:/Program Files/php/php.exe"

After doing this preparation you are ready to install and make your VSCode be ready to do some PHP code, let's roll!

Extensions

PHP IntelliSense

What this extension does is giving some help depending on what version of PHP you have installed (at least PHP 7) giving you the autocompletition that Intellisense do in Visual Studio.

PHP Namespace Resolver

This is extension give you the posibility to auto add a Class from another file with few steps and without the necessity of tiping it at the beginning of your PHP file:

Example on how PHP Namespace Resolver works
Credtis to the author: Mehedi Hassan

phpcs

This extension linter you code and tells you what you need to have an overall standar for a PHP code made. Follow up the installation guide and enjoy having a PHP linter in VSCode.

Laravel Blade Snippets

This extension gives you some helpful snippets when you are coding some blade files for the views of Laravel.

Composer

This provides an interface to manage your Composer dependencies and validates your composer.json config file

Conclusion

With these extensions your PHP development will be boosted greatly and make Visual Studio Code a great free alternative in the market. I hope this post was helpul to you and I wish to you good luck in the path.

Top comments (0)