PHP远程调试之XDEBUG_PHP
开发的时候我都是使用XDebug在本地调试,但是最近加入一些项目中去,环境太复杂了,要在本地搭建一个开发环境真的太麻烦了,那么我们怎么使用xdebug来远程调试呢?
我这里使用虚拟机搭建了一个模拟环境来实验说明:
1.虚拟机IP:192.168.174.130 ,虚拟机用于搭建lampp环境
2.实体机IP:192.168.174.1,这个是IDE的开发环境。
首先我在虚拟机里面安装了一个lampp,而且增加了一vhosts,具体如下:
vim /opt/lampp/etc/extra/httpd-vhosts.conf <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/data/web" <Directory "/data/web"> Options All AllowOverride All Require all granted </Directory> ServerName www.test.com ErrorLog "test-error_log" CustomLog "test-access_log" common </VirtualHost>
这里为了方便给vhosts设置一个域名,这个需要修改实体机的/etc/hosts后才能访问:
192.168.174.130 www.test.com
关键的一步我们需要设置虚拟机中的php.ini来支持xdebug远程调试,增加了如下代码:
vim /opt/lampp/etc/php.ini zend_extension="/opt/lampp/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so" [xdebug] xdebug.default_enable=1 xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_host=192.168.174.130 xdebug.remote_port=9000 xdebug.remote_connect_back=1 xdebug.remote_autostart=1
最关键的两个设置xdebug.remote_host和xdebug.remote_connect_back,remote_host要设置成服务器的ip,remote_connect_back要设置成1或者on
到这里,服务端就设置好了,接下来我们来设置ide了,请原谅我是一个ide工具党。我使用的Intellij IDEA,而PHPStorm的设置也是一样的。
第一设置项目的server
在Host那里要填上,能够正常访问到虚拟机服务器的地址,我们之前设置的虚拟域名是www.test.com,所以我图上也是写得这个。
最关键的设置地方就是要勾上这个路径映射,然后将需要调试的文件写上它在服务器上的路径,比如我这里需要调试a.php,而在虚拟机服务器上我们设置的web目录是/data/web/,那么它映射的路径就应该是/data/web/a.php了。
一切设置好了以后,就可以像本地调试那样开始了。
OK了,没有什么技术含量,但希望能帮到需要的朋友,注意把文章中得ip地址,修改你自己的服务器的地址。
以上内容给大家分享了PHP远程调试之XDEBUG的相关知识,希望大家喜欢。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Alipay PHP...
