1

I run a lot of VirtualHosts within Apache, none of them all that exciting. Is there an easier way than to specify php_value error_log /var/log/www-site/error.log for each VirtualHost?

Every VirtualHost always has its ErrorLog set:

<VirtualHost *:443>
  DocumentRoot /var/www-site
  ServerName site.me
  ServerAlias www.site.me

  CustomLog /var/log/www-site/access.log combined
  ErrorLog  /var/log/www-site/error.log
</VirtualHost>

Is there a setting in Apache where it enables you to log PHP errors to Apache its error log files by default, without having to specify it?

1 Answer 1

2

PHP doesn't have access to Apache's ErrorLog directive as far as I'm aware, so it can't automatically log all of its errors to the same location. If you're able to use it, you might want to look at mod_macro (https://httpd.apache.org/docs/2.4/mod/mod_macro.html). It's available by default since Apache 2.4.6, but can be manually installed on lower versions.

It would allow you to define your error log lines in one place, and then include all of them with a single line in each vhost.

error_macro.conf

<Macro error_logs $site>
    php_value error_log /var/log/$site/error.log
    CustomLog /var/log/$site/access.log combined
    ErrorLog  /var/log/$site/error.log
</Macro>

In each VirtualHost

Use error_logs www-site
Sign up to request clarification or add additional context in comments.

2 Comments

Woah, that's pretty sweet! I could expand on this by also setting DocumentRoot to /var/www-$site, right, for even less custom typing?
Yep, exactly. Anything that your vhosts will have in common with each other makes sense to put in a macro. Note that they can take additional arguments - <Macro my_macro $arg1 $arg2 $etc> - if you need to pass in more than one thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.