Tutorial

How To Set Up Visual Studio Code (VS Code) for PHP Development

Published on May 28, 2021

Developer Advocate

How To Set Up Visual Studio Code (VS Code) for PHP Development

Introduction

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems.

With a large collection of extensions for many programming languages, VS Code can be customized to serve a wide variety of development needs. In this guide, you’ll learn how to set up Visual Studio Code for working on PHP projects.

The gif shows the VS Code interface for PHP development

Prerequisites

To follow this guide, you’ll need to download and install the appropriate version of Visual Studio Code for your operating system.

The instructions in this guide were validated on an Ubuntu 20.04 desktop computer, but they should work seamlessly in all operating systems that are supported by VS Code. Please note, though, that keyboard shortcut keys may need to be slightly modified for compatibility with MacOS systems.

Step 1 — Installing VS Code PHP Extensions for Extra Support

Right after installation, VS Code already recognizes PHP code and helps with syntax highlighting, basic debugging, and code indentation. These features are suitable for quick edits or when working with individual PHP scripts. Working in larger projects, though, can become difficult without more context around the code and how each file interacts and integrates within the larger project.

There are a number of VS Code extensions that can help speed up your productivity when working on PHP projects. In this guide, we’ll install and set up PHP Intelephense, a popular PHP extension for VS Code that provides several advanced features such as improved code completion, better navigation between components, rich information tooltips on mouse hover, code auto formatting, and real time error reporting based on static code analysis.

Open the extensions tab by clicking on the last icon on the left menu bar, or by pressing CTRL + SHIFT + X. This will bring up a sidebar menu with a search box and a list of popular or recommended extensions. Type “php” or “intelephense” to locate the PHP Intelephense extension. Click on the Install button to install and enable the extension.

The gif shows how to access the extensions menu on the left sidebar

Once installation is complete, Intelephense’s official documentation recommends that you disable the built-in PHP Language Features extension that comes with VS Code.

To disable this extension, type @builtin php in the Extensions search box to locate the built-in PHP extensions. Then click on the settings icon for the PHP Language Features extension, and click the Disable option in the drop-down menu.

The gif shows how to disable the builtin PHP Language Features extension

If you have any files open in VS Code, you’ll need to reload the editor to apply the changes.

You can install other extensions by following the same process described for the PHP Intelephense extension, but be aware that some extensions will require additional software to be installed on your system. Check the extension documentation to make sure you have requirements set appropriately.

Step 2 — Importing or Creating a New PHP Project

To import an existing PHP project into VS Code, click on the first icon on the left menu bar or type CTRL + SHIFT + E to access the file explorer. Click the Open Folder button and select your project’s directory. In case you are creating a new project, you can create a new folder and select that as your project directory.

The gif shows how to import a PHP project to VS Code

The explorer window will now show the project’s directory tree, giving you quick access to files and directories on your project.

Step 3 — Customizing Theme and Editor Font (Optional)

Although not necessary, it is often a good idea to customize the appearance of your editor to make it more comfortable to use in the longer term. As a developer you may spend several hours every day looking at an IDE such as VS Code, and for that reason it’s important to make sure the editor font has an appropriate size, and the contrast is enough for good readability without tiring your eyes too quickly.

You may want to experiment with different themes and fonts in order to find a custom setup that works well for you.

Changing VS Code Theme

VS Code comes with a few different themes that allow you to change the colors used in the editor interface and in the code highlighting. Both dark and light styles are included by default.

Go to File -> Preferences -> Color Theme or type CTRL + K + T to select a different theme for VS Code.

The gif shows how to change VS Code theme

You can also install theme extensions to further customize VS Code’s appearance. If you search for theme within the extensions tab (CTRL + SHIFT + X), you’ll find several theme extensions in different styles and colors, including color schemes ported from other popular editors and platforms.

Adjusting the Font

Although the default VS Code font settings will be good enough for many users, you may want to adjust the size and the type of the editor font for increased readability.

If you would like to modify the font size or change to another type, you can go to File -> Preferences -> Settings, then choose Text Editor on the left menu. Then, click on Font in the submenu that opens up. That section contains font family and size settings which you can tweak as preferred.

The gif shows how to change VS Code editor font size

The changes are immediately saved and applied to all current open files.

Conclusion

Visual Studio Code is a lightweight yet powerful code editor that can be customized to suit the needs of most developers. In this guide, you learned how to install and configure the PHP Intelephense extension for extra support while working on PHP projects, how to import and create new projects within VS Code, and how to customize the editor appearance for a more comfortable coding experience.

For more tutorials on Visual Studio Code, check our VS Code tag page. If you’d like to learn more about PHP development, you can refer to our How To Code in PHP series for an introduction to the language, and our PHP tag page for more PHP tutorials.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar

Developer Advocate

Dev/Ops passionate about open source, PHP, and Linux.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
4 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

If you are macOS user, ServBay.dev is a good tool, especially for the beginners. It handles all PHP, MariaDB, PostgreSQL versions, plus Redis and Memcached. Run multiple PHP instances simultaneously and switch easily. This tool has made my PHP dev simpler. Worth a shot!

Also there is an AI code suggestions extension IntelliPHP: https://marketplace.visualstudio.com/items?itemName=DEVSENSE.intelli-php-vscode

I have gone through your article which was on PHP extensions. The essential PHP extensions for specific functionalities depend on the requirements of your project. However, here are some commonly used extensions for different functionalities: 1.Database Connectivity 2.XML Processing 3.JSON Manipulation 4.Image Processing 5.Encryption and Hashing 6.compression and Archive 7.File System Manipulation 8.Date and Time Manipulation 9.Caching and Performance Optimization From my point of view, these are some points to be included in your article. Readers, If you want to develop your PHP website, you can get a free consultation from an IT company like Alakmalak technologies. They have 17+ years of experience in this field.

Just adding - for a complete PHP language support (debug, IntelliSense, format, code actions, test explorer, and more) there is all-in-one commercial extension https://marketplace.visualstudio.com/items?itemName=DEVSENSE.phptools-vscode

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.