You can disable the public display of PHP errors to improve security and professional appearance on a live website. This process ensures that technical details, such as file paths and script errors, are not visible to website visitors while still allowing you to log errors internally for troubleshooting.
Before you begin
You will need:
Access to your website's file system (via FTP, SFTP, or a File Manager)
Access to your website's configuration files
A current backup of your configuration files
Adjusting PHP settings via .htaccess or .user.ini
Depending on your server configuration, you can disable error display by modifying the .htaccess file or a .user.ini file in your website's root directory.
Connect to your server using an FTP client or your hosting control panel's File Manager.
Navigate to the root directory of your website.
Locate the
.htaccessfile (or create a.user.inifile if your environment supports it).Open the file and add the following lines:
php_flag display_errors Off # OR, if using .user.ini: ;user_ini.loader='1' ;memory_limit='256M' ;display_errors=Off
Save the file and upload it back to your server.
Adjusting PHP settings via php.ini
If you have access to the main php.ini file for your account, you can disable error reporting globally for your environment.
Locate your
php.inifile.Find the line for
display_errors.Change the value to
Off:
display_errors = Off
Save the file.
Confirm the result
To verify that errors are no longer displayed publicly:
Navigate to your website's homepage.
Trigger a known error (such as visiting a non-existent page or a broken script).
Confirm that the page displays a standard "Not Found" page or a generic error page rather than a detailed PHP stack trace or technical error message.
How to Find and Read the PHP Error Log
Since errors are no longer displayed on the screen, you must check the server's error logs to troubleshoot issues.
Log in to your hosting control panel.
Locate the Errors or Logs section.
View the most recent entries to identify the cause of any issues.
Limitations
This procedure only hides errors from the public view; it does not stop the errors from occurring. If a script fails, the site may still display a blank page or a generic "500 Internal Server Error" message.
