Learn to Turn Off PHP Error Reporting
If you have ever visited a website and suddenly the website displayed a strange message that looked like a bunch of gibberish code, there is a good chance that this was a PHP error being displayed. This type of error is very informative when developing your website, but may be somewhat embarrassing (and dangerous) on a live site.
So, let’s take a look at exactly how to turn off PHP error reporting in a few simple ways, whether you use cPanel, edit a WordPress site or work with the server files directly.
Why Should You Turn Off PHP Error Reporting?
PHP error reporting is a great tool for debugging during development. It shows warnings, notices, and critical issues in your code. But on a live or production site, it can
- Look unprofessional
- Leak sensitive information (like file paths or database structures)
- Confuse or scare your users
The best practice? Turn off error display for users and log errors instead so you can fix them quietly.
Method 1: Turn Off Error Reporting via php.ini
This is the main configuration file for PHP on your server.
Steps:
1. Find the php.ini file
Use a script with phpinfo() to find it, or check typical locations like:
/etc/php.ini, /etc/php/8.1/apache2/php.ini, etc.
2. Edit the file
Open it in a text editor and set the following:
display_errors = Off display_startup_errors = Off log_errors = On error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED & ~E_STRICT
3. Restart your web server
If you’re using Apache or Nginx:
sudo service apache2 restart
OR
sudo systemctl restart nginx
This will turn off all visible error reporting but still log errors for review, which is ideal.
Method 2: Use .htaccess File (For Apache Servers)
If you don’t have access to php.ini (like on shared hosting), the .htaccess file is your next best friend.
Steps:
1. Find or create a .htaccess file in your project’s root folder.
2. Add these lines:
php_flag display_errors Off php_flag display_startup_errors Off php_value error_reporting 22527
Note: 22527 is the numeric value for E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED & ~E_STRICT
3. Save and upload the file. Done!
Method 3: Control PHP Errors with Inline Code (Per Script)
Sometimes you only want to suppress errors in one specific file. You can do that with a few lines of PHP at the top of the file:
<?php error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED & ~E_STRICT); ini_set('display_errors', 'Off'); ini_set('display_startup_errors', 'Off'); ?>
This doesn’t affect other files, making it perfect for temporary suppression.
Method 4: Disable Error Reporting via cPanel
Using a web hosting panel like cPanel? This is probably the easiest way.
Steps:
1. Login to your cPanel dashboard.
2. Scroll to “Software” and click “Select PHP Version”.
3. Go to the “Options” tab.
4. Set display_errors to Off.
5. Optionally adjust error_reporting to a value like E_ALL & ~E_NOTICE & ~E_WARNING.
That’s it! No coding required.
Bonus: Disable PHP Errors in WordPress
WordPress sites display PHP warnings if debugging is turned on.
In your wp-config.php file, add or edit:
ini_set('display_errors','Off'); define('WP_DEBUG', false); define('WP_DEBUG_DISPLAY', false);
This ensures your visitors don’t see any ugly PHP errors on your blog or store.
Tips & Best Practices
- Always keep log_errors = On in production. Logs help you debug safely.
- Use error logging tools or services like Sentry, New Relic, or your host’s error log viewer.
- Test after making changes to ensure errors are hidden and logs still work.
- In development, do the opposite: turn error reporting on to catch bugs early!
Final Thoughts
Disabling PHP error reporting is an important step before your website can be viewed by real users. If you were ever wondering about disabling PHP errors, either on your VPS or cPanel, you now have several options to make changes to keep everything looking more professional and secure.
Keep PHP error messages hidden from users, log them properly, and you are heading for a smoother, more secure experience for your users – something all good developers or site owners do.
Frequently Asked Questions (FAQs)
What is the most effective way to hide PHP errors when a website is live?
The best way is to turn off display_errors and enable log_errors in your php.ini file or .htaccess. This way, users won’t see the errors, but you can still track and fix them through logs.
Will turning off PHP error reporting affect my site’s performance?
No, disabling the display of PHP errors won’t impact performance. In fact, hiding errors from users enhances security and user experience. Just make sure logging is still enabled to track issues.
What is the difference between display_errors and log_errors?
- display_errors: Controls whether errors are shown to users in the browser.
- log_errors: Controls whether errors are saved to a server log file.
Best practice: Keep display_errors off and log_errors on in production environments.
How do I find my PHP php.ini file?
Make a new PHP file with this php code and open it in a browser:
<?php phpinfo(); ?>
Look for the “Loaded Configuration File” entry — that’s your active php.ini path.
How can I suppress specific PHP error types like warnings or notices?
Use the error_reporting() function or set it in php.ini or .htaccess. For example, to hide warnings and notices:
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);