Recommendations
What to consider ?
If you already have a good work flow up and running then you can skip this bit, however if you do not have an IDE which can do step by step debugging then I'd pause for a while and consider some of the thoughts here.
I'm not sure if you ever find yourself writing a bunch of echo statements in your code to “see” what's happening. If you are taking a long time to get to the bottom of a problem you probably should be making use of a debugger in your editor. If your editor doesn't support debugging then you should probably consider using one that does.
IDE vs Text Editor
An IDE is an editor which allows you to do debugging and version control and code refinement due to good hints and code completion. A text editor is just that, something to edit text, and it doesn't give any guidance whether one is making mistakes.
Two popular IDEs which support PHP debugging are:
* PHPStorm
The most popular PHP debugging extension is Xdebug and we recommend that you get this installed as soon as you have your PHP up and running.
Install Xdebug
Follow these instructions to install Xdebug on your system.
Step 1 - Download & Install
Windows
Head to the Xdebug page and download the corresponding version for PHP on your Operating System. For example, in this case the PHP version used is VC15 x64bit Thread Safe 7.4.1. Click on the Xdebug link
After the download is complete, extract/unpack or copy the file into the “ext” folder found in your PHP directory. (e.g. C:/php/ext)
You will notice that the Xdebug file is in .dll format and you will need to rename it from “php_xdebug-2.9.6-7.4-vc15-x86_64.dll” to something simple like “php_xdebug.dll”.
Linux
Install xdebug with the following command:
sudo apt install php7.4-xdebug
and configure it with:
sudo nano /etc/php/7.4/mods-available/xdebug.ini
Add the following code into it:
zend_extension=xdebug.so
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_log = /tmp/xdebug_remote.log
xdebug.remote_mode = req
xdebug.remote_port = 9005 #if you want to change the port you can change
and then restart the services but running each command individually:
sudo systemctl restart php7.4-fpm
sudo systemctl restart nginx //If you are using nginx server
sudo systemctl restart apache2 //If you are using apache server
Step 2 - Configure php.ini
Once the file have been extracted, you will need to enable remote debugging by editing the configuration settings file, which will be your php.ini file.
Go to your PHP folder and open “php.ini” with Notepad or your IDE tool.
Please ensure that the “php_xdebug.dll” file location is correct.
Add the following in the extensions directory list (HINT: its above Module Settings) and press Ctrl+S or save changes you just made to “php.ini” file:
[XDebug]
zend_extension="C:\php\ext\php_xdebug.dll
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
Please note that the configuration settings for Xdebug might be updated. If so, please visit their site and easily search for the required configuration setting
Step 3 - Confirm Installation
Complete the installation by restarting your system so that changes may take effect. After this you can confirm if the installation was a success by opening your command terminal (e.g Command Prompt or terminal in your IDE tool) and typing in “php -m” and pushing Enter. This will display all modules loaded in your PHP. At the bottom of the list you should see the “Zend Modules” heading and “Xdebug” will be listed underneath.
Debugging
The default port that debugging is enabled on for xdebug is 9000 and because we are not really remote there are some recommended ways to run Tina4 from the command line to make debugging work.
XDEBUG_CONFIG="remote_host=127.0.0.1" php -S localhost:7145 index.php
On windows you can put the following in the built in PHP web server environment variables
XDEBUG_CONFIG="remote_host=127.0.0.1"