Reputation: 1956
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
Upvotes: 2
Views: 4322
Reputation: 2400
I use a setup like this where my logsplit.sh script writes to log files based on the %U:
<VirtualHost *:80>
ServerName myserver.com
ServerAlias *.myserver.com
VirtualDocumentRoot /home/%1/www/
LogFormat "%U %h %l %u %t \"%r\" %>s %b" common
CustomLog "|/usr/local/logsplit.sh" common
</VirtualHost>
Upvotes: 8
Reputation: 32290
You can do this with VirtualHosts by only maintaining 1 VirtualHost for several Domains using ServerAlias
:
<VirtualHost *:80>
ServerAdmin ...
ServerName domain1.bla.com
ServerAlias service.bla.com domain5.domain.xxx
DocumentRoot /www/vhosts/xxx/public
ErrorLog /www/vhosts/xxx/log/error.log
CustomLog /www/vhosts/ccc/log/access.log combined
LogLevel warn
<Directory "/www/vhosts/ccc/public">
Options FollowSymLinks MultiViews
php_admin_flag safe_mode On
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Upvotes: -1