Detailed explanation about remote debugging of PHPSTROM

藏色散人
Release: 2021-03-23 18:57:58
forward
3303 people have browsed it

The following is an introduction to PHPSTROM remote debugging from thephpstormtutorial column. I hope it will be helpful to friends in need!

Detailed explanation about remote debugging of PHPSTROM

Install DVWA project

System environment

whippet@ubuntu:~/Desktop$ cat /etc/issue
Copy after login

Check whether the PHP environment has been installed

whippet@ubuntu:~/Desktop$ dpkg -l | grep php
Copy after login

Add PPA source

whippet@ubuntu:~/Desktop$ sudo add-apt-repository ppa:ondrej/php
Copy after login

Update system

whippet@ubuntu:~/Desktop$ sudo apt-get update
Copy after login

Install php 5.6

whippet@ubuntu:~/Desktop$ sudo apt-get install php5.6
Copy after login

Install apache and start

whippet@ubuntu:~/Desktop$ sudo apt install apache2
Copy after login

Install mysql and start

whippet@ubuntu:~/Desktop$ sudo apt-get install mysql-server
Copy after login

Install DVWA

whippet@ubuntu:~/Desktop$ cd /var/www/html/
Copy after login

Detailed explanation about remote debugging of PHPSTROM

Configure PHPSTROM debugging

Environmental conditions


Machine name Operating system ip information Experimental environment
Virtual Machine Ubuntu 20.04.2 192.168.176.171 PHP 5.6.40
Local machine Windows10 192.168.176.1 phpstrom

xdebug 配置

我们直接在 xdebug 的官网上寻找历史版本^[1]^ 全局搜索 php 5.6

Detailed explanation about remote debugging of PHPSTROM

我们可以看到相较于 windows 上种类繁多的二进制文件,linux 只提供了源码文件,需要自己进行编译,下载源码之后我们复制到虚拟机内部

whippet@ubuntu:~$ tar -xcvf xdebug-2.5.5.tgz
Copy after login

Detailed explanation about remote debugging of PHPSTROM

xdebug 被安装在 /usr/lib/php/20131226/

修改php.ini配置文件,在文件中追加以下内容

[Xdebug]
Copy after login

保存之后重启 apache 服务 sudo service apache2 restart 之后访问 phpinfo 发现xdebug 的信息已经显示出来了

至此 xdebug 的相关配置就 ok 啦,接下来我们对本地的 phpstrom 进行配置

PHPSTROM 配置

首先我们从虚拟机内,把已经安装好的项目代码打包再脱下来,这是因为,有一些项目在安装之后会对源代码进行一定的修改,为了不出现偏差我们就把安装好的代码给拖取下来。利用 PHPSTROM 打开这个项目,并配置相关参数信息

File -> Settings -> Languages & Frameworks -> PHP -> Debug

Detailed explanation about remote debugging of PHPSTROM

Detailed explanation about remote debugging of PHPSTROM

配置 Servers

Detailed explanation about remote debugging of PHPSTROM

此处要注意,需要直接指定到网站的目录位置

配置PHP Web Application

Detailed explanation about remote debugging of PHPSTROM

然后我们打开登录的 login.php ,在其中添加断点,并设置 PHPSTROM 的监听模块

Detailed explanation about remote debugging of PHPSTROM

浏览网站页面,同时打开浏览器的调试插件

Detailed explanation about remote debugging of PHPSTROM

我们可以看到已经跳到我们断点的位置Detailed explanation about remote debugging of PHPSTROM

至此调试的基本过程已经完成,以下的步骤属于可做可不做,本着学习的想法,我还是把添加上吧

SSH 配置

先大致描写一下为什么要进行这个操作,就是为了方便对 php 文件的修改,有时候我们想对 php 文件进行修改,但是在本地修改之后,并不会影响远端服务器上的文件,经过这样的配置之后,本地文件修改之后,远端服务器上的文件也会同步修改。

首先,我们安装好的 Ubuntu 虚拟机上是并不存在 SSH 的,所以我们需要先将 Ubuntu 上的 SSH 进行配置。

# 安装 openssh 服务
Copy after login

验证一下,发现可以登录成功

打开 PHPSTROM

添加一个 sftp 协议

Detailed explanation about remote debugging of PHPSTROMDetailed explanation about remote debugging of PHPSTROMDetailed explanation about remote debugging of PHPSTROM

选择 ubuntu 上 php 的路径位置

Detailed explanation about remote debugging of PHPSTROM

至此已经基本配置完成,我们来进行一下验证
File -> Settings -> Languages & Frameworks -> PHP -> Debug

Detailed explanation about remote debugging of PHPSTROM

配置完成,我们修改一个文件进行验证一下

Detailed explanation about remote debugging of PHPSTROM

Detailed explanation about remote debugging of PHPSTROM

The above is the detailed content of Detailed explanation about remote debugging of PHPSTROM. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:learnku.com
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!