Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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');
    error_reporting(0);
  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:

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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
</IfModule>

EDIT:

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
</IfModule>

This is equivalent to a setting of

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

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

http://www.websitefactors.co.uk/php/2013/01/php-error-reporting-settings/

share|improve this answer
    
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

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.

share|improve this answer
    
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

Watch this youtube video this is axactly what you want its easy and helpfull and don't forget to change resolution to 460 before watching https://www.youtube.com/watch?v=i5Hq6t8Z6Fo

share|improve this answer
1  
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  kasperd Sep 15 at 23:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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