如何获得Netbeans和Xdebug与NginX合作
我有一台Ubuntu 16.10笔记本电脑,用于测试我开发的网站,最近我从Apache2切换到NginX。我使用Netbeans和Xdebug来调试我的PHP脚本。如何获得Netbeans和Xdebug与NginX合作
使用NginX设置Xdebug的说明看起来很简单。简而言之以下行/etc/php/7.0/fpm/conf.d/20-xdebug.ini
:
zend_extension=/usr/lib/php/20160303/xdebug.so
xdebug.remote_port=9000
xdebug.remote_enable=On
xdebug.remote_connect_back=On
xdebug.remote_log=/var/log/xdebug.log
...然后用sudo service nginx restart
重启Nginx的。但这不起作用。
我检查堆栈溢出的答案,我发现this one,它说我需要把下面的代码放在一个配置文件中,但它似乎是特定于PHP 5,我正在运行PHP 7.0,也它只涉及一个NginX配置文件,没有指定哪一个,所以我不知道该把它放在哪里。
location/{
root /var/www/bresson/web/;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/dispatch.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
如何连接到Xdebug的Nginx的,这样我可以调试PHP使用Netbeans?
找到了答案here。
它说,要得到的东西叫“Redis的”,虽然我不能完全肯定这是必要的:
apt-get install php-redis
在任何情况下,我做到了。下一步是运行此命令:
所有手动编译指令都可以忽略,因为所有需要的东西现在都在存储库中。我已经安装了Xdebug,NginX和所有的东西。所以我跳到这一行:
sudo echo "zend_extension=xdebug.so" > /etc/php/7.0/mods-available/xdebug.ini
但是,长话短说,我发现通过试验和错误,这是不够的。相反,我不得不打开它,并添加如下内容:通过运行php -m | grep -i xdebug
,应返回
ln -sf /etc/php/7.0/mods-available/xdebug.ini /etc/php/7.0/fpm/conf.d/20-xdebug.ini
ln -sf /etc/php/7.0/mods-available/xdebug.ini /etc/php/7.0/cli/conf.d/20-xdebug.ini
service php7.0-fpm restart
检查结果:
zend_extension = xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.var_display_max_depth = -1
xdebug.var_display_max_children = -1
xdebug.var_display_max_data = -1
xdebug.idekey = "PHPSTORM"
在那之后,我跑这些命令
xdebug
Xdebug
然后我重新启动了一切,但这可能不是必需的:
sudo service php7.0-fpm restart
sudo service nginx restart
然后我通过在NetBeans中调试一个站点来测试它,它工作正常!
附录:
我不停地调试我的本地站点时,得到一个503 Bad Gateway
错误。看起来问题在于Xdebug连接超时。解决方案似乎是为您正在调试的站点配置文件,例如/etc/nginx/sites-available/local_example.conf
,并且您想要将名为fastcgi_read_timeout
的参数添加到PHP部分。例如,这是它现在看起来像在我的网站conf
文件:
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 600;
}
我将它设置为fastcgi_read_timeout 600;
让我有10分钟,坐下来,想想我在做什么,而挂在一个断点。我寻找更全球化的设置,但无法找到它,所以这是现在为我工作的解决方案。