PHP setup
Here are the steps to set up PHP in VS Code with mise:
- Install the mise-vscode extension (if not already installed)
- 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.
brew install autoconf automake bison freetype gd gettext icu4c krb5 libedit libiconv libjpeg libpng libxml2 libxslt libzip pkg-config re2c zlib
sudo apt-get update && sudo apt-get install -y autoconf bison build-essential curl gettext git libgd-dev libcurl4-openssl-dev libedit-dev libicu-dev libjpeg-dev libmysqlclient-dev libonig-dev libpng-dev libpq-dev libreadline-dev libsqlite3-dev libssl-dev libxml2-dev libxslt-dev libzip-dev openssl pkg-config re2c zlib1g-dev
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:
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.
brew install autoconf automake bison freetype gd gettext icu4c krb5 libedit libiconv libjpeg libpng libxml2 libzip pkg-config re2c zlib
sudo apt-get update && sudo apt-get install -y autoconf bison build-essential curl gettext git libgd-dev libcurl4-openssl-dev libedit-dev libicu-dev libjpeg-dev libmysqlclient-dev libonig-dev libpng-dev libpq-dev libreadline-dev libsqlite3-dev libssl-dev libxml2-dev libzip-dev openssl pkg-config re2c zlib1g-dev
You can now install php
using mise
:
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 VS Code to run the PHP linter.
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 VS Code, 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 VS Code.
Debugging PHP files
You will need to install xdebug
. Open a terminal in VS Code and run the following command:
pecl install xdebug
Inspect the output of the command. The last line you should like this:
# ...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 VS Code:
- 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.
Example with laravel
mise exec vfox:version-fox/vfox-php -- composer create-project laravel/laravel example-appcd example-appmise use vfox:version-fox/vfox-phpphp 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 VS Code.
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,debugxdebug.idekey=VSCODExdebug.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