I have a PHP application which is used by multiple domains. To avoid maintaining multiple vhosts, I have just setup a single "default" Apache vhost to direct any incoming request to the server to the application directory.
What I want to do is to set the Apache access and error log paths dynamically based on the hostname hitting the server.
For example, I would like to set the log paths to be something like:
/var/log/application_name/example.com/error.log
/var/log/application_name/example.com/access.log
when a request to example.com
is made.
Is there a viable way to do this? I've looked at using any of the Apache environment variables, but as these are setup as the request is captured, I don't think these would be available for use in the ErrorLog or CustomLog directives. Is it that I just need to set the log directory manually at the application level (i.e in PHP)?
Thanks
You can do this with VirtualHosts by only maintaining 1 VirtualHost for several Domains using
ServerAlias
:I use a setup like this where my logsplit.sh script writes to log files based on the %U: