{"id":8721,"date":"2023-03-21T11:45:48","date_gmt":"2023-03-21T11:45:48","guid":{"rendered":"https:\/\/www.geekdecoder.com\/?p=8721"},"modified":"2023-03-21T11:45:48","modified_gmt":"2023-03-21T11:45:48","slug":"de-bugging-wordpress-and-php","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2023\/03\/21\/de-bugging-wordpress-and-php\/","title":{"rendered":"De-bugging WordPress and PHP"},"content":{"rendered":"\n<p>Sometimes wordpress may have errors that you want to find out more about. Here are a few steps we can take to see more information on what&#8217;s happening.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>To debug WordPress, you can follow these steps:<\/p>\n\n\n\n<p>Enable WordPress Debugging:<\/p>\n\n\n\n<p>Open the wp-config.php file in your WordPress root directory. Search for WP_DEBUG constant. Change its value to true. Also add a path to a log file.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndefine( &#039;WP_DEBUG&#039;, true );\ndefine( &#039;WP_DEBUG_LOG&#039;, &#039;\/home\/username\/logs\/wp-errors.log&#039; );\n<\/pre><\/div>\n\n\n<p>When enabled by setting the WP_DEBUG_LOG constant to true, WordPress will write all issues to the following file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nwp-content\/debug.log\n<\/pre><\/div>\n\n\n<p>However, you can also specify a custom file path to write the log to a different location on your server.<\/p>\n\n\n\n<p>Create a debug log file in logs directory. In this example, we are creating it in a cPanel account log directory.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo touch \/home\/username\/logs\/wp-errors.log\n<\/pre><\/div>\n\n\n<p>Make sure the file is writable. To make a file writable in Linux, you can use the chmod command. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo chmod 644 \/home\/username\/logs\/wp-errors.log\n<\/pre><\/div>\n\n\n<p>Or<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo chmod +w \/home\/username\/logs\/wp-errors.log\n<\/pre><\/div>\n\n\n<p>This command adds the &#8220;write&#8221; permission for the owner of the file (wp-errors.log in this case). Check the file for errors after reproducing the issue.<\/p>\n\n\n\n<p>If you want to save problems to the log but not publicly display them within the HTML of your pages you can also use the WP_DEBUG_DISPLAY constant to keep debug mode enabled but not display messages on your site.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ Disable display of errors and warnings\ndefine( &#039;WP_DEBUG_DISPLAY&#039;, false );\n@ini_set( &#039;display_errors&#039;, 0 );\n<\/pre><\/div>\n\n\n<p><strong>Use Debugging Plugins<\/strong><\/p>\n\n\n\n<p>Install and activate a WordPress debugging plugin like Query Monitor, Debug Bar, or WP Debugging.<\/p>\n\n\n\n<p><strong>Check the Browser Console<\/strong><\/p>\n\n\n\n<p>Open the browser console to check for JavaScript errors.<\/p>\n\n\n\n<p><strong>Check Server Logs<\/strong><\/p>\n\n\n\n<p>Check the server error log to see if there are any PHP errors.<\/p>\n\n\n\n<p>By following these steps, you can effectively debug WordPress and troubleshoot any issues that you may be experiencing.<\/p>\n\n\n\n<p><strong>Enable PHP Error Logs<\/strong><\/p>\n\n\n\n<p>To enable PHP error logging in Linux, follow these steps.<\/p>\n\n\n\n<p>Edit the php.ini file: Open the php.ini file using a text editor such as vi or nano. The php.ini file is usually located in the \/etc\/php directory. For example, to edit the php.ini file using nano editor, run the command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo nano \/etc\/php\/7.x\/apache2\/php.ini\n<\/pre><\/div>\n\n\n<p>Note: Replace &#8220;7.x&#8221; with the version of PHP installed on your system.<\/p>\n\n\n\n<p>Enable error logging: Search for the following lines in the php.ini file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n;error_reporting = E_ALL\n;display_errors = Off\n<\/pre><\/div>\n\n\n<p><br>Uncomment these lines by removing the semicolon (;) at the beginning of each line, and change the values as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nerror_reporting = E_ALL\ndisplay_errors = On\n<\/pre><\/div>\n\n\n<p>Set the error log file path: Add the following line to the php.ini file to specify the path for the PHP error log file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nerror_log = \/var\/log\/php_errors.log\n<\/pre><\/div>\n\n\n<p><br>Note: You can change the file path to your desired location.<\/p>\n\n\n\n<p>Create the error log file: Create the PHP error log file by running the command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo touch \/var\/log\/php_errors.log\n<\/pre><\/div>\n\n\n<p>Change the file permissions: Change the file permissions of the error log file so that it can be written to by the web server. Run the command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo chmod 666 \/var\/log\/php_errors.log\n<\/pre><\/div>\n\n\n<p><br>Restart Apache: Restart the Apache web server to apply the changes. Run the command:<br><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo systemctl restart apache2\n<\/pre><\/div>\n\n\n<p>After these steps, PHP errors will be logged to the specified file.<\/p>\n\n\n\n<p>Enable php error log cPanel<\/p>\n\n\n\n<p>To enable the PHP error log in cPanel, you can follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log in to cPanel and navigate to the &#8220;Software&#8221; section.<\/li>\n\n\n\n<li>Click on &#8220;MultiPHP INI Editor&#8221;<\/li>\n\n\n\n<li>Under Configure PHP INI basic settings, select the home directory or a domain\u2019s document root to open the corresponding PHP configuration.<\/li>\n\n\n\n<li>Scroll down until you see the &#8220;display_errors&#8221; options.<\/li>\n\n\n\n<li>Set the slider &#8220;display_errors&#8221; option to &#8220;Enabled&#8221;.<\/li>\n\n\n\n<li>Click on the &#8220;Apply&#8221; button to save the changes.<\/li>\n<\/ol>\n\n\n\n<p>Now set the error log path in the MultiPHP INI Editor in cPanel<\/p>\n\n\n\n<p>While in MultiPHP INI Editor, <\/p>\n\n\n\n<p>Click &#8220;Editor Mode&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/03\/2023-03-21-07-36-22.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"378\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/03\/2023-03-21-07-36-22-1024x378.png\" alt=\"\" class=\"wp-image-8730\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/03\/2023-03-21-07-36-22-1024x378.png 1024w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/03\/2023-03-21-07-36-22-300x111.png 300w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/03\/2023-03-21-07-36-22-768x284.png 768w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/03\/2023-03-21-07-36-22.png 1343w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><br>Add the line error_log = &#8220;\/some\/path&#8221;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nerror_log = &quot;\/logs\/php_error.log&quot;\n<\/pre><\/div>\n\n\n<p>This should either be a filename, with no leading path, or an exact path within your home directory<br>Save the changes.<\/p>\n\n\n\n<p>Using PHP-FPM<br><br>The only way to adjust this setting is via WHM&#8217;s MultiPHP Manager<\/p>\n\n\n\n<p>Log into WHM<br>Navigate to MultiPHP Manager<br>Find the domain you&#8217;d like to change the error log location for<br>Click the &#8220;Edit PHP-FPM&#8221; link<br>Change the log location in &#8220;The error log file (error_log)&#8221; relative to the folder &#8220;logs&#8221; within the user&#8217;s home directory<br>Save your changes<\/p>\n\n\n\n<p>After following these steps, PHP errors will be logged to the file specified in the &#8220;error_log&#8221; option. You can view the contents of the error log file using a text editor or by running the &#8220;tail&#8221; command in the terminal.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes wordpress may have errors that you want to find out more about. Here are a few steps we can take to see more information on what&#8217;s happening.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128],"tags":[],"class_list":["post-8721","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/8721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=8721"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/8721\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=8721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=8721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=8721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}