# Formatting PHP in VSCode Using Prettier and PHP Intelephense

> Learn how to set up Visual Studio Code (VSCode) for automatic PHP file formatting using the Prettier and PHP Intelephense extensions. This step-by-step tutorial will help you maintain a clean and organised codebase, enhancing your PHP development experience.

- URL: https://www.codethepixel.com/formatting-php-in-vscode-using-prettier-and-php-intelephense
- Author: Asyraf Wahi Anuar (https://www.codethepixel.com/author/asyraf-wahi-anuar)
- Published: 2025-06-15
- Category: Tools & Software
- Tested with: PHP
- Tags: CakePHP, Visual Studio Code, Prettier, Code Formatter
- Reading time: 2 min

Visual Studio Code (VSCode) is a popular code editor renowned for its versatility and numerous extensions that enhance the coding experience. Among these, the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) stands out for its ability to format code consistently across various languages, making it a favourite among developers. However, when it comes to formatting PHP files, many users encounter challenges, as Prettier does not natively support PHP formatting. This limitation can be frustrating, especially for those looking to maintain a clean and organised codebase in PHP.

In this tutorial, I will guide you through the steps to effectively set up your VS Code environment to automatically format PHP files using Prettier in conjunction with the [PHP Intelephense](https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client) extension. By following this guide, you'll be able to streamline your PHP development process and ensure your code looks sharp and professional. Let’s dive in and unlock the full potential of code formatting in VSCode!

1. Install and enable the [Prettier Extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) in VS Code
2. Set as default formatter in VS Code settings:

a) File - Preferences - Settings / Shortcut: CTRL + ,  
b) Search: Formatter  
c) Editor: Default Formatter select: Prettier - Code Formatter

3. Install and enable the [PHP Intelephense](https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client)
4. CTRL + Shift + P then search for "open user settings (JSON)" and insert the following parameter:

```php
{
... //other config
  "[php]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
  },
  "editor.linkedEditing": true
...
}
```

All files ending with the .php extension will be formatted using the PHP Intelephense extension. Make sure to securely save the settings.json file to preserve these configurations for future use.
