我的博客同步文章 https://mr-houzi.com/2019/10/...
通常状况,开发者多使用Windows系统,PHPStorm、VSCode等软件让咱们离不开Windows,可是,可是多数开发者更倾向于在Linux上部署环境。那么这一份教程就诞生了。(MacOS用户能够绕行)
在Windows系统上安装PHPStorm和VM虚拟机,在虚拟机中安装Ubuntu系统。php
在Ubuntu安装lnmp(Linux+Nginx+MySQL+PHP)集成环境linux
wget http://soft.vpser.net/lnmp/lnmp1.6.tar.gz -cO lnmp1.6.tar.gz && tar zxf lnmp1.6.tar.gz && cd lnmp1.6 && ./install.sh lnmp
打开PHPStorm,选择Create New Project from Existing Files
浏览器
选择从远程服务器ftp同步项目服务器
输入项目名,并选择要同步到本地的项目路径app
自动上传操做选择以下,当你Ctrl+S时,PHPStorm会帮你上传当前修改的文件到服务器。这样会至关方便。工具
选择新建远程服务器spa
填写项目名,Type
选择SFTP
,填写服务器IP、用户名、密码以及远程项目所在的路径。.net
//linux下查看ip命令(不是Windows的ipconfig) ghost@ghost-virtual-machine:~$ ifconfig
直接点finish,PHPStorm会自动同步远程服务器的代码。debug
下载、编译xdebug3d
wget http://www.xdebug.org/files/xdebug-2.2.3.tgz tar xzf xdebug-2.2.3.tgz cd xdebug-2.2.3 /usr/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make make install
查看php安装路径下的lib 库目录是否生成了xdebug.so文件。(个人目录:/usr/local/php/lib/php/extensions/xdebug.so)
而后配置/usr/local/php/etc/php.ini
文件,须要注意的是xdebug是zend扩展,zend_extension= "xdebug.so"
,而不是extension= "xdebug.so"
。
[xdebug] zend_extension= "xdebug.so" xdebug.profiler_enable = on xdebug.default_enable = on xdebug.trace_output_dir="/tmp/xdebug" xdebug.trace_output_name = trace.%c.%p xdebug.profiler_output_dir="/tmp/xdebug" xdebug.profiler_output_name="cachegrind.out.%s" xdebug.remote_enable =1 xdebug.remote_handler = "dbgp" xdebug.remote_host = 10.0.100.236 //本机的ip,不是虚拟机或者远程服务器的ip xdebug.remote_mode = "req" xdebug.remote_port = 9001
若是不知道本机的ip或本机为动态ip,须要加入xdebug.remote_connect_back
,将其设置为1,此时xdebug.remote_host
会失效。
首先,设置端口,此端口要与上文配置xdebug.remote_port
保持一致。
配置远程服务器,勾选Use path mappings
,将本地文件与服务器文件相映射。
配置DBGP Proxy,输入远程服务器的ip和端口,IDE key填写为PHPSTORM
。
添加debug配置,选择刚刚建立的Server
选中debug配置,在代码中打断,点击小虫子开始调试。
PS:若是使用虚拟机中Linux,想要在本机经过浏览器访问虚拟机中的项目,须要在Nginx中将项目ip设置为虚拟机的ip,而不是127.0.0.1。若是多个项目怎么办呢?IP相同,用不一样的端口号区别不一样的项目。