Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

different PHP error log for each virtualhost in apache 2?

Status
Not open for further replies.

shadedecho

Programmer
Oct 4, 2002
336
US
(duplicate post from Apache Forum)

Is there a way to either:

1. have a different php.ini for each virtualhost in apache, or

2. in the virtualhost configuration in apache, manually specify some different php environment/config variables?

What I am trying to do is be able to have EACH virtual host have it's own PHP error log, in their own directory, instead of all php errors going into one master php error log file.

I know I can set "error_log=..." in php.ini, but that sets a global value which applies to all php scripts, and I want to have each virtualhost set their own value for that.

I know each php script in each virtualhost's directory COULD set:


Code:
ini_set("error_log","/path/to/error.log");

HOWEVER, I do not want to force those virtual hosts to set that, I just want it to default to the correct location for each virtualhost, which I can control when setting up the virtual host in apache, for instance.

Any way to do this?
 
as a follow up to this, since this is being discussed over in the Apache forum, I'm noticing what appears to be a PHP bug of some sort:

I cannot change the value of the error_log IN a script, using ini_set(), and have it be respected. I change it, and print out phpinfo(), and then throw a php error by calling an undefined function...

phpinfo's output shows it has changed (from the php.ini original setting), but... the error still doesn't get into the correct log file, it still goes into the apache error log file.

Is there some overridding thing that Apache is doing which is trapping ALL errors or something, by default? or is there some other reason why PHP would not be able to change its own error_log variable at run time?

I know i've changed it at run time before, on other servers and in other configurations. Maybe this is a php 5 bug?
 
I'm getting the same behavior. Here's my workaround:

On my LAMP (RH9/2.0.52/4.1.17/5.0.2) box, when I set the error_log value in httpd.conf:

Code:
<VirtualHost [hidden]:80>
        DocumentRoot /home/sites/test/html
        ServerName [hidden]
        ServerAlias [hidden]
        ExpiresDefault now
        ExpiresActive on
        CustomLog /home/sites/test/logs/access.log combined
        ErrorLog /home/sites/test/logs/error.log

        <Directory /home/sites/test/html/val_test>
                [red]php_value error_log "/home/sites/test/html/val_test/foo.txt"[/red]
        </Directory>
</VirtualHost>

This works for me. I don't know if you can use this, though.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I tried putting that php_value thing into a directory directive, i get the same behavior. Don't know why.
 
btw, 4.1.17? I thought the highest was 4.1.8, which is what I have.... did ya mean 4.1.7? :)
 
I dunno why it doesn't work for me, the way you did it. That is strange. I have LAMP(Deb3.0, 2.0.52, 4.1.8, 5.0.3), which is quite similar to your setup, and for some reason it doesn't want to work for me. Have you verified that it does in fact inject the errors into that log? Because my phpinfo() does report the change, with the method you suggested, but it doesn't actually WORK when i force a php error. The error instead gets stuck in my general apache error log for that <virtualhost>.
 
On my system, when I specify the error_log directive in httpd.conf, it definitely sends the errors to that file.

And I compiled Apache from source, too.



Could you be having a permissions problem? Does the user as which Apache runs have the right to write to the directory?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
i know it does, because the apache error log that the PHP errors DO get sent to is in the same directory, and so it obviously has no trouble writing to THAT file... it's a very simliar name, in fact, but slightly different (the php error log file should have the word "php" in it, to distinguish it).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top