How to install xdebug with vagrant + vscode

Good evening!
This is Nagato from the System Development Department.

This time, I will explain in an easy-to-understand way how to install xdebug, a favorite tool among PHP programmers, into a Vagrant + Vscode environment.
The installation environment is as follows:
Vagrant: 2.2.9
PHP: 8.0.3
Vscode: 1.55.1
Xdebug: 3.0.4

Advance preparation

The version of Xdebug that is supported varies depending on the version of PHP, so please check in advance.
To check, copy and paste all the information output by "php -i" into the following website:
https://xdebug.org/wizard

Copy the download link for the resulting xdebug file

Install xdebug

Use wget to get the file from the download link you copied in advance

cd /usr/local/src wget http://xdebug.org/files/xdebug-3.0.4.tgz

Install php-devel to use the phpize command

sudo yum install php-devel

After extracting the downloaded file, execute the commands in order

tar -xzvf xdebug-3.0.4.tgz phpize ./configure make sudo make install

After executing the make command, the xdebug.so file will be created in the modules directory in the current directory, so copy it

sudo cp modules/xdebug.so /usr/lib64/php/modules

The installation is now complete

Add the setting to php.ini

Next, add the xdebug settings to the php.ini file.
Instead of writing the settings directly to the php.ini file, create a new ini file for xdebug and load it.

sudo vi /etc/php.d/15-xdebug.ini

Add the following settings to the newly created ini file.
Please note that the settings and how to specify them will vary depending on the version of xdebug.
Also, in version 2.0, the default port number for xdebug is "9000," but
this may already be in use, so we recommend setting it to a value other than "9000."
In version 3.0, the default has changed to "9003," so it should be fine without specifying it.

For version 2

[xdebug] zend_extension=/usr/lib64/php/modules/xdebug.so xdebug.defaul_enable=1 xdebug.remote_enable=1 xdebug.remote_port=9001 xdebug.remote_handler=dbgp xdebug.remote_autostart=1 xdebug.remote_connect_back=1

For version 3

[xdebug] zend_extension=/usr/lib64/php/modules/xdebug.so xdebug.client_port=9003 xdebug.mode=debug xdebug.start_with_request=yes

Setting in vscode

In vscode, press "ctrl+shift+x" to open the extension installation screen,
search for "php debug", and install it.

Once the extension installation is complete,
click "Run" ⇒ "Add Configuration" on the toolbar at the top of vscode, select "php", and
".vscode/launch.json" will be created in the current directory, so open it.


The initial settings are probably as follows:

{ // Use IntelliSense to learn available attributes. // Hover over existing attributes to see their descriptions. // For more information, see: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Listen for Xdebug", "type": "php", "request": "launch", "port": 9001 }, { "name": "Launch currently open script", "type": "php", "request": "launch", "program": "${file}", "cwd": "${fileDirname}", "port": 9000 } ] }

Here, specify the port number set in the "port" field of "Listen for Xdebug" in the php.ini file.
If not set, use the default port number.
xdebug2 series: 9000
xdebug3 series: 9003

lastly

I have opened the system development service site "SEKARAKU Lab" to which I belong.
Beyond is a one-stop service for everything from server design and construction to operation, so if you have any trouble with server-side development, please feel free to contact us.
SEKARAKU Lab: [https://sekarakulab.beyondjapan.com/](https://sekarakulab.beyondjapan.com/)

Now all the settings are complete and you can use xdebug.
That's it, congratulations on your hard work.

If you found this article helpful , please give it a like!
3
Loading...
3 votes, average: 1.00 / 13
6,787
X facebook Hatena Bookmark pocket

The person who wrote this article

About the author

Masaki Nagato

Joined as a new graduate in April 2020.
My name is Nagato and I belong to the System Development Department. He mainly develops web systems and game APIs using PHP.
Qualification: PHP7 engineer certification beginner level