Skip to content

PHP setup

Here are the steps to set up PHP in VS Code with mise:

  1. Install the mise-vscode extension (if not already installed)
  2. Open a project with a mise.toml file (or any other files supported by mise)

Installing PHP

vfox-php

I would recommend using the vfox-php toolchain for PHP development.

This will require you to install some system dependencies, see https://github.com/version-fox/vfox-php?tab=readme-ov-file#prerequirements for more information.

Terminal window
brew install autoconf automake bison freetype gd gettext icu4c krb5 libedit libiconv libjpeg libpng libxml2 libxslt libzip pkg-config re2c zlib
Terminal window
mise use vfox:version-fox/vfox-php

This will compile and install the latest version of PHP on your system (note that this may take a few minutes).

If you want to install it globally, use:

Terminal window
mise use -g vfox:version-fox/vfox-php

asdf-php

This will show you how to install PHP using the default mise provided asdf-php plugin.

Installation details Currently, the default php provided mise is the asdf-php plugin. This plugin requires a few dependencies to be installed on your system. See the asdf-php README for more information.

Terminal window
brew install autoconf automake bison freetype gd gettext icu4c krb5 libedit libiconv libjpeg libpng libxml2 libzip pkg-config re2c zlib

You can now install php using mise:

Terminal window
mise use asdf:asdf-community/asdf-php

This will compile and install the latest version of PHP on your system (note that this may take a few minutes).

Default PHP support

The default PHP support in vscode is limited to syntax highlighting and basic code completion. It also runs the php linter on save by default. mise-vscode will configure the php.validate.executablePath allowing VSCode to run the PHP linter.

PHP setup

You can find the default php extension by searching for @builtin php-language-features in the extensions view.

PHP debugger setup

If you wan to run and debug PHP files from VSCode, you will need to install additional extensions. The extension supported by mise-vscode is PHP X-Debug extension

If you install it, mise-vscode will automatically configure the php.debug.executablePath setting in your workspace settings.

Running PHP files

You should now be able to run PHP files from VSCode.

PHP run example

Debugging PHP files

You will need to install xdebug. Open a terminal in VSCode and run the following command:

Terminal window
pecl install xdebug

Inspect the output of the command. The last line you should like this:

Terminal window
# ...
You should add "zend_extension=/home/dev/.local/share/mise/installs/vfox-version-fox-vfox-php/8.4.1/lib/php/extensions/no-debug-non-zts-20240924/xdebug.so" to php.ini

Open the php.ini file (you can find it by running php --ini) and add the line to the end of the file.

You can now debug PHP files from VSCode:

  • Go to the debug view in the sidebar
  • Create the default launch.json file
  • The default target “Launch currently open script” should allows you to run and debug PHP files.

php-debug

Example with laravel

Terminal window
mise exec vfox:version-fox/vfox-php -- composer create-project laravel/laravel example-app
cd example-app
mise use vfox:version-fox/vfox-php
php artisan serve

Open http://127.0.0.1:8000/ in your browser to see the Laravel welcome page.

You can now open the example-app folder in VSCode.

To enable debugging, update your php.ini (use php --ini to find it) file with the following:

zend_extension=... # same as in the `PHP debugger setup` section
xdebug.start_with_request=yes ;
xdebug.mode=develop,gcstats,coverage,profile,debug
xdebug.idekey=VSCODE
xdebug.client_port=9003 ;

You can now set breakpoints in your code and start debugging.

  • Run php artisan serve in the terminal
  • Go to the debug view in the sidebar
  • Click the Listen for XDebug button

php-laravel-debug