To disable display_errors
in PHP, you can do it in several ways depending on your access level and environment (development vs. production):
1. In php.ini
(recommended for production)
Find and edit your php.ini
file (location varies by system):
ini
display_errors = Off
After changing this, *restart your web server* (e.g., Apache or Nginx):
bash
# Apache
sudo systemctl restart apache2
# Nginx with PHP-FPM
sudo systemctl restart php-fpm
2. In a PHP script (temporary override)
php
ini_set('display_errors', '0');
> Use this only for local/temporary control, not as a permanent solution.
3. In php-fpm
pool configuration (if using PHP-FPM)
Edit your pool config (e.g., /etc/php/8.1/fpm/pool.d/www.conf
) and add or change:
ini
php_flag[display_errors] = off
Then restart PHP-FPM:
bash
sudo systemctl restart php8.1-fpm
Verify Your Setting
To check whether it’s disabled:
php
<?php
echo ini_get('display_errors'); // Should output nothing or 0
?>
Or create a phpinfo();
page:
php
<?php phpinfo(); ?>