Enable PHP error logging

 

Overview

This article explains how to enable and control PHP errors on your website. This may be necessary when troubleshooting a website as DreamHost disables all PHP warnings by default, so you should never see them on your website when making changes to PHP.

Enabling PHP warnings temporarily

See this article to learn more about how to temporarily enable PHP warnings in the panel. Once enabled, the error.log displays these additional entries:

  • PHP Deprecated
  • Notices
  • Strict messages
  • Warnings

Enabling PHP error logging via phprc

To display the warnings on your site instead of in the panel, add the following line to your phprc file using an FTP client or SSH:

display_errors = on

If any PHP errors are thrown, they will now display on your site.

Live websites

This is not recommended on a live website since visitors will see the errors.

Configuring custom error logging

The following steps add code to your phprc file to log all PHP errors in a new file named php.log.

 

Decide where the php.log file should go

You must first decide where you want your php.log file to be created. This can be in any directory you like as long as your user is able to write to that directory. The most simple location would be in your user's home directory. For example:

/home/username/php.log

It's not possible to create your php.log file in your /home/username/logs directory. This directory is created by DreamHost and owned by dhapache, therefore it's not possible for your user to write to this directory.

Edit the phprc file

Add these lines to your phprc file using an FTP client or SSH. Make sure to replace username with your shell user.

log_errors = 1 
error_log = /home/username/php.log

Kill off all running php processes

Make sure to kill running php processes to ensure your new settings take effect.

Confirm your changes

After you've edited the file and killed off all PHP processes, you should check to confirm the values have updated. You can do this by creating a phpinfo.php file.

If you do not see your changes have updated, try killing off your PHP processes again.

Test the php.log file

The new php.log file will not exist at first. It is created automatically after a PHP error is thrown. This file will then continue to log any future PHP errors.

To test the php.log file, create a PHP file that throws an error. For example, create a file named error.php with the following content and upload it to your site.

<?php 
$file=fopen("welcome.txt","r");
?> 

When you visit the example.com/error.php page in a browser, an error is thrown. If you then check your user's home directory, you'll see the php.log file has been created and that it logged this PHP error. Use the cat command to read the file's contents.:

[server]$ cat ~/php.log

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?