Home > Backend Development > PHP Tutorial > How to configure the PHP development environment in VSCode (detailed version)

How to configure the PHP development environment in VSCode (detailed version)

慕斯
Release: 2023-04-10 06:48:02
forward
9413 people have browsed it

How to configure the PHP development environment in VSCode (detailed version)? Friends who don’t understand, come and learn! I believe you will gain something after reading this article

How to configure the PHP development environment in VSCode (detailed version)

1. Download XAMPP

XAMPP is an easy to install Apache distribution, which includes MariaDB, PHP and Perl. Just download and launch the installer.

XAMPP download address

Official website download: https://www.apachefriends.org/zh_cn/download.html

How to configure the PHP development environment in VSCode (detailed version)

Other address for downloading: http://xiazai.zol.com.cn/detail/38/372445.shtml
(It is recommended to download this, choose local download-Telecom channel or China Unicom channel is acceptable)

After downloading, the PHP version number is as follows. You will need to use it later
How to configure the PHP development environment in VSCode (detailed version)to install XAMPP

All the way NEXT, it is best not to choose the C drive as the installation address. The author installed the English version.

Installation successful

How to configure the PHP development environment in VSCode (detailed version)
Enable according to requirements. If I write PHP, I choose to enable Apache.

Add system variables

Add the path to the folder where PHP.exe is located (the author's is "D:\XAMPP\php") to the environment variable- System variables-Path (you can find it by searching for system variables in the search box directly).

Enter php -v in cmd to check whether the configuration is successful
Configuration is successful
How to configure the PHP development environment in VSCode (detailed version)

2. Download the xdebug plug-in

Download address: https://xdebug.org/download
Which PHP version to download can be seen in the README in XAMPP
(The author's is PHP 7.4.0, and it is Thread safe version, corresponding to the version with TS, download the corresponding version without nts, file name: php_xdebug-2.9.7-7.4-vc15-x86_64.dll)
How to configure the PHP development environment in VSCode (detailed version)

Add configuration

Copy the downloaded x-debug file (php_xdebug-2.9.7-7.4-vc15-x86_64.dll) to the php\ext folder
Use Notepad to modify the php.ini file , add a few lines of configuration information at the end of the file, and save it.

[xdebug]zend_extension="D:/xampp/php/ext/php_xdebug-2.9.7-7.4-vc15-x86_64"//这个地址以及文件名一定要正确xdebug.remote_enable = 1xdebug.remote_autostart = 1
Copy after login

3. Download and install VSCode

Download address: https://code.visualstudio.com/

In VSCode Install the debugging plug-in

1. Click the extension bar, enter PHP, and select PHP Debug to install.

How to configure the PHP development environment in VSCode (detailed version)
2. Click VSCode’s File-Preferences-Settings (different versions may display differently, pay attention to search for user settings), find php in the extension in the settings, click setting.json and add the following One-line configuration:

"php.validate.executablePath": "D:/xampp/php/php.exe",//地址是php.exe文件所在的位置
Copy after login

How to configure the PHP development environment in VSCode (detailed version)
3. Configure the launch.json that Debug

will pop up by default, no need to change.

4. Then simply debug and verify whether the configuration is successful.
Note that you must open a folder to successfully set breakpoint debugging. A single file is invalid. You can choose D:/xampp/php/www

<?php $a = &#39;hello world&#39;;echo $a;?>
Copy after login

to set a breakpoint and then start debugging.

5. Open the php to be debugged in the browser (not the file path but the address of the server (http://localhost:3000/hello.php)), VSCode will hit the Breakpoint location.

6. Finally, it is recommended to install this plug-in: PHP Server
You can choose to right-click PHP Server: Serve project and jump directly to the browser

How to configure the PHP development environment in VSCode (detailed version)

7 , Running results
How to configure the PHP development environment in VSCode (detailed version)

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to configure the PHP development environment in VSCode (detailed version). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template