search
HomeDevelopment ToolsVSCodeTeach you step by step how to set up a PHP development environment in VSCode

How to develop PHP in VSCode? The following article will introduce to you how to configure the PHP development environment in VSCode. I hope it will be helpful to you!

Teach you step by step how to set up a PHP development environment in VSCode

##Configure the PHP development environment in VSCode

1 PHP

Official website address:

PHP

Interface:

Teach you step by step how to set up a PHP development environment in VSCode

2 Download

Official website download address:

Download PHP

Teach you step by step how to set up a PHP development environment in VSCode

3 Installation

① Download php as shown below.

Teach you step by step how to set up a PHP development environment in VSCode ② Unzip to the location where you want to install php (note that you should double-click to open the compressed package first to see if there is a root directory).
As shown below, if there is no root directory after opening, do not decompress it directly, otherwise the files will be mixed together. [Recommended learning:
vscode tutorial, Programming video]

Teach you step by step how to set up a PHP development environment in VSCode

It is recommended to create a new root directory and then unzip it (or right-click and select "Extract to xxx"), as shown in the figure below.

Teach you step by step how to set up a PHP development environment in VSCode

4 Configure environment variables

① Right-click My Computer- > Properties -> Advanced System Settings -> Environment Variables or search "System Environment Variables" directly using win s -> Open "Edit System Environment Variables", as shown in the figure below.

Teach you step by step how to set up a PHP development environment in VSCode ② Open the php installation directory and copy the address as shown below.

Teach you step by step how to set up a PHP development environment in VSCode ③ Modify the path in "System Variables" and add the path copied in step ②.

Teach you step by step how to set up a PHP development environment in VSCode

Note: Don’t forget to click OK after configuring the system variables.

④ Test: Enter

php -v

Teach you step by step how to set up a PHP development environment in VSCode

##5 in cmd Xdebug download

Xdebug To download the version corresponding to php, the php version we downloaded is 8.1.11, and it is the thread safe version, which corresponds to the version with TS.

Download address:
Xdebug: Downloads

## Download the php_xdebug-3.2.0RC1-8.1-vs16-x86_64 .dll file, copy it to the ext directory in the php root directory, and then find the php.ini file in the php root directory. There are two situations as follows. Teach you step by step how to set up a PHP development environment in VSCode ① (With php.ini file) Just add the following configuration directly at the end of the php.ini file in the php directory (remember to modify the path).

[xdebug]zend_extension="D:\software\php-8.1.11-Win32-vs16-x64\ext\php_xdebug-3.2.0RC1-8.1-vs16-x86_64.dll"xdebug.remote_enable = 1xdebug.remote_autostart = 1

② (No php.ini file) Here we can find two files, php.ini-development (for development environment) and php.ini-production (for production environment) in the php root directory. Although there is no php.ini file here, php will still load php.ini as the configuration file. We only need to select one of them, back it up, then rename it to php.ini, and finally add our own personalized configuration. It is recommended to rename the php.ini-development file backup to php.ini, as shown in the figure below:

Finally, add the following configuration to the end of the php.ini file.

[xdebug]zend_extension="D:\software\php-8.1.11-Win32-vs16-x64\ext\php_xdebug-3.2.0RC1-8.1-vs16-x86_64.dll"xdebug.remote_enable = 1xdebug.remote_autostart = 1
Teach you step by step how to set up a PHP development environment in VSCode

6 Configure PHP in VSCode

① 首先安装 PHP Debug 插件,如下图所示:

Teach you step by step how to set up a PHP development environment in VSCode

② 接着点击 文件 -> 首选项 -> 设置,输入 php,并点击“在 settings.json 中编辑”,如下图所示:

Teach you step by step how to set up a PHP development environment in VSCode

③ 然后添加如下配置(记得修改路径):

"php.validate.executablePath": "D:/software/php-8.1.11-Win32-vs16-x64/php.exe"

④ 随便创建个测试文件夹,用 vscode 打开,新建个 php 文件,如下图所示:

Teach you step by step how to set up a PHP development environment in VSCode
⑤ 设置断点调试,如下图所示:

Teach you step by step how to set up a PHP development environment in VSCode

⑥ 安装插件 PHP Server

Teach you step by step how to set up a PHP development environment in VSCode

这个插件可以让 .php 文件直接右击运行于浏览器中,不需要借助于 xampp 的 Apache。

Teach you step by step how to set up a PHP development environment in VSCode

注意:该插件用于个人测试及小网站的开发是没有任何问题的,不过大型应用还是要配合 Nginx 或 Apache 以达到最高效率。

注意:这里我们在浏览器中输入的是 http://localhost:80/index.php,然而在浏览器地址中为什么显示的却是 localhost/index.php 呢?这是因为浏览网页服务默认的端口号都是 80,因此只需输入网址即可,不用输入": 80"了。另外如果 .php 页面为 index 命名,则只需要在浏览器输入 localhost 即可,因为服务器会自动为我们找到 index.php 这个页面。

Teach you step by step how to set up a PHP development environment in VSCode

最后推荐一些 PHP 的插件,以及其他常用VSCode 必备插件推荐

更多关于VSCode的相关知识,请访问:vscode基础教程

The above is the detailed content of Teach you step by step how to set up a PHP development environment in VSCode. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete
Visual Studio Professional and Enterprise: Paid Versions and FeaturesVisual Studio Professional and Enterprise: Paid Versions and FeaturesMay 10, 2025 am 12:20 AM

The difference between VisualStudioProfessional and Enterprise is in the functionality and target user groups. The Professional version is suitable for professional developers and provides functions such as code analysis; the Enterprise version is for large teams and has added advanced tools such as test management.

Choosing Between Visual Studio and VS Code: The Right Tool for YouChoosing Between Visual Studio and VS Code: The Right Tool for YouMay 09, 2025 am 12:21 AM

VisualStudio is suitable for large projects, VSCode is suitable for projects of all sizes. 1. VisualStudio provides comprehensive IDE functions, supports multiple languages, integrated debugging and testing tools. 2.VSCode is a lightweight editor that supports multiple languages ​​through extension, has a simple interface and fast startup.

Visual Studio: A Powerful Tool for DevelopersVisual Studio: A Powerful Tool for DevelopersMay 08, 2025 am 12:19 AM

VisualStudio is a powerful IDE developed by Microsoft, supporting multiple programming languages ​​and platforms. Its core advantages include: 1. Intelligent code prompts and debugging functions, 2. Integrated development, debugging, testing and version control, 3. Extended functions through plug-ins, 4. Provide performance optimization and best practice tools to help developers improve efficiency and code quality.

Visual Studio vs. VS Code: Pricing, Licensing, and AvailabilityVisual Studio vs. VS Code: Pricing, Licensing, and AvailabilityMay 07, 2025 am 12:11 AM

The differences in pricing, licensing and availability of VisualStudio and VSCode are as follows: 1. Pricing: VSCode is completely free, while VisualStudio offers free community and paid enterprise versions. 2. License: VSCode uses a flexible MIT license, and the license of VisualStudio varies according to the version. 3. Usability: VSCode is supported across platforms, while VisualStudio performs best on Windows.

Visual Studio: From Code to ProductionVisual Studio: From Code to ProductionMay 06, 2025 am 12:10 AM

VisualStudio supports the entire process from code writing to production deployment. 1) Code writing: Provides intelligent code completion and reconstruction functions. 2) Debugging and testing: Integrate powerful debugging tools and unit testing framework. 3) Version control: seamlessly integrate with Git to simplify code management. 4) Deployment and Release: Supports multiple deployment options to simplify the application release process.

Visual Studio: A Look at the Licensing LandscapeVisual Studio: A Look at the Licensing LandscapeMay 05, 2025 am 12:17 AM

VisualStudio offers three license types: Community, Professional and Enterprise. The Community Edition is free, suitable for individual developers and small teams; the Professional Edition is annually subscribed, suitable for professional developers who need more functions; the Enterprise Edition is the highest price, suitable for large teams and enterprises. When selecting a license, project size, budget and teamwork needs should be considered.

The Ultimate Showdown: Visual Studio vs. VS CodeThe Ultimate Showdown: Visual Studio vs. VS CodeMay 04, 2025 am 12:01 AM

VisualStudio is suitable for large-scale project development, while VSCode is suitable for projects of all sizes. 1. VisualStudio provides comprehensive development tools, such as integrated debugger, version control and testing tools. 2.VSCode is known for its scalability, cross-platform and fast launch, and is suitable for fast editing and small project development.

Visual Studio vs. VS Code: Comparing the Two IDEsVisual Studio vs. VS Code: Comparing the Two IDEsMay 03, 2025 am 12:04 AM

VisualStudio is suitable for large projects and Windows development, while VSCode is suitable for cross-platform and small projects. 1. VisualStudio provides a full-featured IDE, supports .NET framework and powerful debugging tools. 2.VSCode is a lightweight editor that emphasizes flexibility and extensibility, and is suitable for various development scenarios.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft