Debugging in PHP

When you want to debug certain sections of code with in an environment without restarting Apache or NGINX, there’s a template I use for displaying print messages.

ini_set('display_errors', 1);

echo "<pre>".json_encode($VALUE, JSON_PRETTY_PRINT)."</pre>";

ini_set('display_errors', 0);

PHP Ini File

Sometimes when you are using php you need to change some of the settings, this can be done by using the ini file.

Before you change anything in the ini file you should check the phpinfo. This can be done by creating a file containing <?php phpinfo(); ?> and then navigating to the path for that file in a browser.

Once you have confirmed where the php ini file is, make your changes. To apply these changes you will have to restart apache. The code to do this depends on which platform you are running. One of the common ones can be done by systemctl restart apache2. Hope this helps someone.