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.
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:
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.
You can now install php
using mise
:
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.
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.
Debugging PHP files
You will need to install xdebug
. Open a terminal in VSCode and run the following command:
Inspect the output of the command. The last line you should like this:
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.
Example with laravel
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:
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