Today, I wanted to debug PHP code under MAC, but found that netbeans could not set breakpoints and could not debug at all. After some searching, I found that there is a third-party module for PHP called xdebug. Although I only found some information on Windows, I still tried to set up the debugging environment successfully.
Configuration process:
Install xdebug
Modify php.ini
Restart apache
Confirm that the debugging port of netbeans is consistent with xdebug
(1) Download xdebug
I use brew here. If you are not familiar with the brew tool, you can Google it.
First, habitually search:
Execute the command in the terminal: brew search xdebug and find that there is indeed a software xdebug.
Then brew install xdebug and everything will be smooth sailing. After the installation is complete, there will be a prompt to install.
It’s okay if you don’t remember: brew info xdebug
[hechangmin@hecm-mac ~]$brew info xdebug
xdebug 2.1.2
http://xdebug.org
/usr/local/Cellar/xdebug/2.1.2 (348K)
To use this software:
* Add the following line to php.ini:
zend_extension="/usr/local/Cellar/xdebug/2.1.2/xdebug.so"
* Restart your webserver.
* Write a PHP page that calls "phpinfo();"
* Load it in a browser and look for the info on the xdebug module.
* If you see it, you have been successful!
http://github.com/mxcl/homebrew/commits/master/Library/Formula/xdebug.rb
We will see a prompt to modify php.ini. This is the second step we need to do.
(2) Modify the php.ini file
Because I installed xmapp, I found the default path: sudo vi /Applications/XAMPP/etc/php.ini
Added:
zend_extension="/usr/local/Cellar/xdebug/2.1.2/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
(3) Restart apache
Log in as the system administrator root in the terminal:
sudo su
Start XAMPP using the following command:
/Applications/XAMPP/xamppfiles/xampp start
You should see a message similar to the following on your screen:
Starting XAMPP for MacOS X 1.7.3...
XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Starting MySQL...
XAMPP: Starting ProFTPD...
XAMPP for MacOS X started.
(4) Confirm nb debugging port
Open netbeans, select preferences, and select port 9000 in the debugger port as in the second step. And check 'Stop on the first line' (optional) to prevent the program from finishing running directly due to the break point.
This is all done. One thing to note is that when creating a PHP project, you will be asked to select the hosts for debugging. Remember not to write the wrong URL for debugging.
Author -274°C