I just want to only turn on PHP errors and disable all notices and warnings in PHP files.
Asked
Active
Viewed 1.5e+01k times
44
-
1possible duplicate of [Turn off warnings and errors on php/mysql](http://stackoverflow.com/questions/1645661/turn-off-warnings-and-errors-on-php-mysql) – mario Dec 28 '11 at 07:12
6 Answers
59
It is probably not the best thing to do. You need to at least check out your PHP error log for things going wrong ;)
# PHP error handling for development servers
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_log /home/path/public_html/domain/PHP_errors.log
php_value error_reporting -1
php_value log_errors_max_len 0

Peter Mortensen
- 30,738
- 21
- 105
- 131

imp
- 1,110
- 8
- 13
-
6Remembet to never send an error_log file to a public access location. – glerendegui Oct 28 '15 at 14:34
-
@glerendegui indeed, I am not suggesting this is best practice. Like the comment says for a simple development environment, not production its very handy to access the error log on your localhost||network. – imp Oct 31 '15 at 06:27
-
@glerendegui can you explain why not send an error_log file to a public access location? – Tarik Nov 15 '16 at 09:31
-
@Tarik error_log file may contain very sensitivy info about your app bugs. Leaving this file in a public environment looks very unsure. Anyone could try access yourdomain/error_log and access that info – glerendegui Nov 15 '16 at 14:02
-
Does this also disable the error show in mysql ? can anyone post related hide show error from sql that php handles and shows. – zero8 Feb 11 '19 at 05:55
29
If you are in a shared hosting plan that doesn't have PHP installed as a module you will get a 500 server error when adding those flags to the .htaccess file.
But you can add the line
ini_set('display_errors','off');
on top of your .php file and it should work without any errors.

Peter Mortensen
- 30,738
- 21
- 105
- 131

Fortes
- 938
- 12
- 24
23
Try:
php_value error_reporting 2039

Peter Mortensen
- 30,738
- 21
- 105
- 131

Sudhir Bastakoti
- 99,167
- 15
- 158
- 162
-
1Nice! Can you please provide the logic behind the integer 2039? – Binod Kalathil Jul 03 '13 at 06:55
-
4The value 2039 stands for E_ALL & ~E_NOTICE. Found that here: http://www.ibm.com/developerworks/library/os-debug/ – qwerty Oct 07 '13 at 11:37
-
4
-
1@RajeshPatel this works with mod_php but not php-fpm. With php-fpm you can use SetEnv PHP_VALUE "error_reporting = 2039" – mpchadwick Jan 26 '18 at 02:29
-
1The value comes from the values of the constants PHP assigned to E_ALL and others. You can get the number using a simple echo on a php file doing as example `echo E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_WARNING & ~E_NOTICE` which should be a string used usually on the php.ini – NetVicious Jan 14 '22 at 10:01
6
Fortes is right, thank you.
When you have a shared hosting it is usual to obtain an 500 server error
.
I have a website with Joomla and I added to the index.php
:
ini_set('display_errors','off');
The error line showed in my website disappeared.

Peter Mortensen
- 30,738
- 21
- 105
- 131

Rich
- 69
- 1
- 1
2
Use:
ini_set('display_errors','off');
It is working fine in WordPress' wp-config.php
.

Fa11enAngel
- 4,690
- 2
- 39
- 38

user5637954
- 29
- 1
-
1this is the only one that works. I have tried 20 different lines. This, works. – Duck Aug 08 '16 at 00:07
-
Do you mean file *wp-config.php*? Where is that file supposed to be located? – Peter Mortensen Apr 22 '20 at 03:16
0
I used ini_set('display_errors','off');
and it worked great.

Peter Mortensen
- 30,738
- 21
- 105
- 131

Mohamed Badr
- 59
- 1
- 8