I’m used to work with Visual Studio to write code in C#/.Net framework. I’ve written PHP code at school (4 years ago?) and now I’m trying OOP PHP (object oriented). I like to use an editor which can help me with functions from libraries and such so I chose to get the free Eclipse PDT (https://www.eclipse.org/pdt/).
I followed multiple manuals about how to setup Eclipse to debug your php code and nothing worked. I found out that Eclipse is not hosting the php site. You need to use another program like Xampp, so I downloaded that. Your php application needs to be in the folder: /xampp/htdocs/yourappnamefolder/. Also for the debugging in Eclipse to work the module Apache needs to be started in Xampp. In your browser (type in the bar:) localhost should direct you to: http://localhost/dashboard/. If you want to your project in htdocs the url would be like: http://localhost/yourappnamefolder/.
In the file C:\xampp\php\php.ini I added the following at the end of the file:
[xdebug] zend_extension = xdebug xdebug.remote_enable=1 xdebug.remote_connect_back=1 xdebug.remote_handler=dbgp xdebug.remote_host=localhost xdebug.remote_autostart=1 xdebug.remote_port=9000 xdebug.show_local_vars=1 xdebug.expose_remotely=always xdebug.default_enable=1 xdebug.idekey=ECLIPSE_DBGP xdebug.mode = debug xdebug.start_with_request=yes
I followed instructions from this video: https://youtu.be/MiIEF8-XAkc. Short version: you run your application with phpinfo() in a <?php block. Select all the info and copy. You paste it all in an input field on the website www.xdebug.org/wizard and press analyse. You follow the steps it suggests you have to do to get a working XDebug. The video also explains how to setup the server in Eclipse, which I will also explain the next paragraph.
Then in Eclipse I set the Run configurations (Menu Run -> Run Configurations…). Right click on PHP Web Application -> New Configuration.
Give this configuration a Name. PHP Server can be Default PHP Web Server.
Click on Configure…
- Server Tab
- Base URL could be: http://localhost
- Document Root: C:\xampp\htdocs
- Debugger Tab
- Debugger: Xdebug
- Port: 9000
- Path Mapping Tab
- Path on Server: C:\xampp\htdocs\yourappnamefolder
- Path in Workspace: select yourappnamefolder
Click on Finish.
File should be the main php file of your application (index.php), select the file through the Browse button.
In the Common Tab you can select Debug and Run, then click on Apply.
After all this you should be able to debug. Add a breakpoint and click on the debug icon (the just added configuration will be used).