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 manner how to introduce xdebug, which is a favorite of 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 supported version of xdebug varies depending on the php version, so check in advance.
To confirm, please copy and paste all the information output by "php -i" to the site below.
https://xdebug.org/wizard
Copy the download link of the resulting xdebug file that is output.
install xdebug
Use wget to obtain the file from the download link you copied in advance.
cd /usr/local/src wget http://xdebug.org/files/xdebug-3.0.4.tgz
Introducing php-devel to use 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, an xdebug.so file will be created in the modules directory of the current directory, so copy it.
sudo cp modules/xdebug.so /usr/lib64/php/modules
The installation is now complete.
Add settings to php.ini
Next, add xdebug settings to the php.ini file.
Instead of directly writing the configuration information in 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 to be added and how to specify them differ depending on the version of xdebug.
Also, for version 2 series, the xdebug port number is set to "9000" by default, but it
may already be in use, so we recommend setting it to something other than "9000".
In version 3 series, the default has been changed to "9003", so I think it is okay without specifying it.
For version 2 series
[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 series
[xdebug] zend_extension=/usr/lib64/php/modules/xdebug.so xdebug.client_port=9003 xdebug.mode=debug xdebug.start_with_request=yes
Settings in vscode
Open the extension installation screen with "ctrl+shift+x" on vscode,
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"
".vscode/launch.json" will be created in the current directory, so open it. Masu.
I think the default settings are as follows.
{ // Learn the available attributes using IntelliSense. // Hover to display the description of an existing attribute. // For more information check: 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 php.ini file in the "port" field of "Listen for Xdebug".
If not set, specify 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/)
All settings are now complete and xdebug is ready to use.
That's all, thank you for your hard work.