Imagine a couple of sites-enabled available from /etc/apache2/sites-available. (Only Debian-based distros work like this.)

Is it possible to mute warning messages from php scripts from a specific site, without touching the actual htdocs?

Normally there are a couple of solutions to achieve someting related:

  1. Add an error_reporting() directive e.g. error_reporting(E_ERROR); to the scripts executed.
  2. Set php_flags in .htaccess files like so: php_flag display_errors off
  3. Use ini_set inside scripts:

    ini_set('display_errors', 'Off');
    ini_set('display_startup_errors', 'Off');
  4. Prepend @ to functions that throw warnings or errors.

  5. Change php.ini to actually say
    error_reporting = E_ALL ^ E_WARNING
    display_errors = 1

However, these all mean touching the htdocs or having the change applied globally. Imagine the htdocs are mounted read-only. How would I suppress warnings (or notices) for certain sites only?

I am assuming Debian/Ubuntu has a2ensite specific configurations for a reason and I am hoping I can alter those. There is a log_level directive in the example 'site available' configuration, but this handles the amount of messages logged. Not the messages output by the php scripts.

Manually adding sections in php.ini or apache2.conf or httpd.conf will also work. If it is possible.

See also:


If you have access to the apache vhost configurations, of course you can also use php_flag directives inside a Virtual Host in the sites-available directory. This way, they're only applied to this vhost.

Add something like this inside your Virtual Host:

<IfModule mod_php5.c>
    php_admin_flag display_errors off


If you want only actual errors displayed, you can use the php directive error_reporting with an integer value that describes the types of error levels you want to be displayed:

<IfModule mod_php5.c>
    php_admin_flag display_errors on
    php_admin_value error_reporting 22517

This is equivalent to a setting of

error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED;

in php.ini. More possible values for example here:


Error reporting value calculator:


  • Yes, this is what I am looking for. The vhost configuration is site-specific and inside /etc/apache2/sites-available. Do you know any trickery to change this so that errors are in fact displayed, but warnings are not? – Redsandro May 21 '13 at 20:27
  • I've edited my answer. – etagenklo May 22 '13 at 10:16
  • This is [Thrift Shop] awesome! Accepted. – Redsandro May 23 '13 at 0:17

I added :

<IfModule mod_php5.c>
 php_admin_flag display_errors on
 php_admin_value error_reporting 30711

to /etc/apache2/sites-enabled/work and thats working just fine.

Yes I know I should fix those notices, but I'm working on a old script, and will need to come back to that, for now this has solved my problem, and was what the op was looking for. Hope this helps someone.

  • 1
    Can you please explain the meaning of 30711? I assume this is an or'ed bitmask of the E_* error reporting constants. If so, it's horrible practice to write it as you did. – Andrew Schulman Feb 25 '15 at 6:26
  • @AndrewSchulman - The constants E_* are only available within php, and apache doesn't know what they are. See "Note: PHP Constants outside of PHP" on php.net/manual/en/errorfunc.configuration.php – Kevin Jones Jan 24 '19 at 12:12

There is no way to do this without .htaccess or applying the configuration globally. Apache cannot "see" files outside its root folder (htdocs) and .htaccess files only work when in the site's folder. php_flag doesn't function outside of .htaccess, either.

So basically, it's not possible to do on a site-by-site basis without some modification or an .htaccess file.

  • Actually, Apache knows exactly what site we are talking about because we can specify sections for specific directories in the configuration. The answer by etagenklo is close to doing just that. :) Just need to find a way to alter it so it applies to warnings. – Redsandro May 21 '13 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.