{"id":8769,"date":"2017-09-01T15:48:12","date_gmt":"2017-09-01T19:48:12","guid":{"rendered":"https:\/\/www.boldgrid.com\/support\/?p=8769"},"modified":"2021-04-28T10:44:13","modified_gmt":"2021-04-28T14:44:13","slug":"displaying-and-logging-php-errors-warnings-and-notices","status":"publish","type":"post","link":"https:\/\/www.boldgrid.com\/support\/troubleshooting\/displaying-and-logging-php-errors-warnings-and-notices\/","title":{"rendered":"Displaying and Logging PHP Errors, Warnings, and Notices"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<?xml encoding=\"utf-8\" ?><html><body><p>In order to <a href=\"\/support\/troubleshooting\/php-troubleshooting-for-boldgrid\/\">troubleshoot PHP issues<\/a> with your BoldGrid website, <strong>PHP errors<\/strong> can be enabled to display on your site or log to a file using your php.ini. This article will explain how to properly log PHP errors, display them on your site, and explain the ini_set() function for individual error checking on specific pages.<\/p>\n<div class=\"alert alert-info\" role=\"alert\">Once you enable PHP error logging, you should be aware that those log files can grow quite large over time. It is recommended to either disable error_logging or reporting when it is not needed, or periodically remove the error_log files to avoid this from causing further problems. <\/div>\n<h2 id=\"logging-php-errors\">Logging PHP Errors<\/h2>\n<p>In most cases you can set the <strong>PHP error log<\/strong> or <b>error reporting<\/b> in the php.ini file. For most errors, it is best to use logging, as <b>PHP errors<\/b> can cause the entire site to stop working. By default, error reporting is disabled, and you would need to turn it on to get more information about what may be causing the problems you are having. The following guide will explain how to enable <b>error_logging<\/b>, as well as how to set the location of the log files.<\/p>\n<p>Within the php.ini file, you can set the following line of code to <b>On<\/b> to log errors or off to turn error logging off.<\/p>\n<pre>log_errors = On<\/pre>\n<p>Using the php.ini, you can dictate where the error log will be located, based upon the location you provide. <\/p>\n<p>This will place the error_log in the directory the error occurs in, as it is relative and not given a path. <\/p>\n<pre>; Log errors to specified file.\r\nerror_log = error_log<\/pre>\n<p>This will place all <strong>PHP errors<\/strong> in the error_log file located in the directory you specify, as it is an absolute path to the file.<\/p>\n<pre>; Log errors to specified file.\r\nerror_log = \/path\/to\/site\/error_log<\/pre>\n<p>If you are not sure where the <b>php.ini file<\/b> is located to make these changes, it is recommended that you contact your host. <\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"displaying-php-errors\">Displaying PHP Errors<\/h2>\n<p>In the case you do not want errors to display site wide, and you only want to check errors on a single page, you can use the ini_set() function to have them displayed. The syntax for this is as follows::<\/p>\n<pre>string ini_set ( string $varname , string $newvalue )<\/pre>\n<p>This can be placed at the top of your PHP page with the error_reporting variable in it to allows error checking for that particular page. <\/p>\n<ol class=\"article-list\">\n<li>Navigate to the PHP file you want to check errors for.<\/li>\n<li>Add the following code to the top of the page.\n<pre>ini_set('display_errors', '1');\r\n1 = On, 0 = Off<\/pre>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2 id=\"error-reporting\">Error Reporting<\/h2>\n<p>PHP has a list of different <a href=\"http:\/\/php.net\/manual\/en\/function.error-reporting.php\" target=\"_blank\" rel=\"noopener noreferrer\">error reporting settings within the php.ini file<\/a>a&gt; itself. For example if you just want to display warnings only you can change the error_reporting to the following:<\/p>\n<pre>error_reporting = E_WARNING<\/pre>\n<p>To set multiple options, you can follow the format outlined here:<\/p>\n<pre>error_reporting =  E_ALL &amp; ~E_NOTICE &amp; ~E_STRICT &amp; ~E_DEPRECATED<\/pre>\n<p>The following is a list of all available options for php.ini:<\/p>\n<ul>\n<li>E_ALL: All errors and warnings<\/li>\n<li>E_ERROR: fatal run-time errors<\/li>\n<li>E_WARNING: run-time, non fatal warnings<\/li>\n<li>E_PARSE: compile-time parse errors<\/li>\n<li>E_DEPRECATED: notices for the use of functions that will not be present in a future version<\/li>\n<li>E_NOTICE: run-time notices (these are warnings which often result from a bug in your code, but it&rsquo;s possible that it was intentional <\/li>\n<li>E_CORE_ERROR: fatal errors that occur during PHP&rsquo;s initial startup<\/li>\n<li>E_CORE_WARNING:\twarnings (non-fatal errors) that occur during PHP&rsquo;s initial startup<\/li>\n<li>E_COMPILE_ERROR: fatal compile-time errors<\/li>\n<li>E_COMPILE_WARNING: compile-time warnings (non-fatal errors)<\/li>\n<li>E_USER_ERROR: user-generated error message<\/li>\n<li>E_USER_WARNING:\tuser-generated warning message<\/li>\n<li>E_USER_NOTICE: user-generated notice message<\/li>\n<\/ul>\n<div class=\"alert alert-info\" role=\"alert\">For further information regarding Error Reporting, you can view the <a href=\"http:\/\/php.net\/manual\/en\/errorfunc.configuration.php#ini.error-reporting\" target=\"_blank\" rel=\"noopener noreferrer\">full guide on php.net.<\/a><\/div>\n<p>Congratulations! Once you have <strong>error reporting<\/strong> set to log or display, you will be able to see more information about the issue at hand and should help you find a solution!<\/p>\n<\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>In order to troubleshoot PHP issues with your BoldGrid website, PHP errors can be enabled to display on your site or log to a file using your php.ini. This article will explain how to properly log PHP errors, display them on your site, and explain the ini_set() function for individual error checking on specific pages. [&hellip;]<\/p>\n","protected":false},"author":529,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"bgseo_title":"Displaying and Logging PHP Errors, Warnings, and Notices - BoldGrid","bgseo_description":"In order to troubleshoot any issues with your PHP code, PHP errors can be enabled to display on your site or log to a file using your php.ini or .htaccess. ","bgseo_robots_index":"index","bgseo_robots_follow":"follow","footnotes":""},"categories":[74],"tags":[],"class_list":["post-8769","post","type-post","status-publish","format-standard","hentry","category-troubleshooting"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts\/8769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/users\/529"}],"replies":[{"embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/comments?post=8769"}],"version-history":[{"count":12,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts\/8769\/revisions"}],"predecessor-version":[{"id":36931,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts\/8769\/revisions\/36931"}],"wp:attachment":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/media?parent=8769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/categories?post=8769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/tags?post=8769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}