Why use a log?
PHP is the language many websites run on. When something breaks, a visitor may see only a blank page. The log keeps the real message, with the file and line. You can read it later and fix the cause.
On a live site, do not show errors on screen. Visitors should not see your file paths. Write them to a log file instead.
Method 1: cPanel
- Log in to cPanel.
- Open MultiPHP INI Editor.
- Choose your domain.
- Set
log_errorsto On. - Set
display_errorsto Off. - Click Apply.
- To read the log, open the Errors page in cPanel, or look for an
error_logfile in your site folder.
Method 2: php.ini
- Open File Manager and go to your site folder.
- Open or create
php.ini. Back it up first if it exists. - Add these lines:
log_errors = On
display_errors = Off
error_reporting = E_ALL
error_log = /home/username/logs/php_errors.log
These lines turn on logging, hide errors from visitors, report all error types and choose the log file. Replace username with your account name, and make sure the logs folder exists.
Method 3: WordPress
Add this to wp-config.php, above the line "That's all, stop editing":
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
Errors are saved to wp-content/debug.log. Turn WP_DEBUG off when you finish.
Keep the log from growing too big
Logs can grow large and eat your disk space.
- Check the file size every so often in File Manager.
- Download the log if you want to keep it, then delete or empty the file.
- On a VPS with root access, a tool called
logrotatecan do this for you. It rotates old logs on a schedule. Hostvento support can tell you what your plan offers.
Quick recap
- Turn on
log_errorsand turn offdisplay_errors. - Use MultiPHP INI Editor, php.ini or wp-config.php.
- Read the log to find the file and line.
- Clean the log now and then.