When I log messages via error_log() in my PHP web app, the messages get logged in Apache's /var/log/httpd/error_log.
When I log messages the same way in a PHP command-line app, the messages go to PHP's own php-error.log
Is there a way to log messages to PHP's error log from a PHP web app?
In your php.ini file look for this parameter
error_log =
And set it to whatever filename and location you want.
Of course if you want to seperate your web PHP error logs from your PHP CLI error logs then you need to remember that there are normally 2 php.ini files
One that is used by Apache/PHP and the other that is used by PHP CLI possibly /etc/php5/cli/php.ini
If you change the php.ini file used by the PHP CLI you can have a different file name completely used for the error logging from PHP CLI scripts
Look for
error_log =
and change to
error_log = /var/log/php_cli_errors.log
for example.
Related
On a linux box running Apache for a public site, temporary files are being created in /tmp presumably by PHP as they have a “php” prefix. How can I correlate this to the specific web request that caused php to write this file? I believe this is from file data being posted to non-existant URLs that is being temporary saved to the file system while the various PHP code decides if the file exists.
I’ve turned on auditd watching of /tmp and can generally match the timestamp to Apache logs, buy ideally I’d like to be able to point to a log showing the request and/or php file that caused php to write the file.
I’ve turned on trace logging of apache and php logging, but not seeing any way to capture that temporary file name. Is this possible?
I have created my own PHP extension in c++ and am using Centos7 - php 5.6 version.
I wants to write the my extension debug log into the web server logging directory.We can get this from PHP by calling phpinfo() method.
from /etc/httpd location logs directory symbolic link with /var/log/httpd/
How can we get this Apache configuration location from my PHP extension in c++?
Even if you were able to parse the web server's configuration file in PHP, you wouldn't be able to create your own log file. Worker processes in web servers usually don't have permissions to create new files in the system log directory.
If you need to print debugging messages, generate them with php_error(). They will be passed to the web server for error logging.
I recently got already written php project, and I am trying to work on it. I can see that all logs are written to the specific location using file_put_contents() function.
But I can see that there's error_log() function in one place, without a destination file given. It looks like this:
error_log($str);
Where can I find logs file in this case?
The error log file is set with the error_log directoive in php.ini.
If the directive is not set, the file location is managed by the SAPI error logger, which in case of Apache it is in "Apache" logs directory.
You can find if this directive have a value with phpinfo()
Here is my actual configuration vhost conf on each of my domains :
<VirtualHost *:80>
...
php_value error_log /var/log/php-logs/domainName/error.log
...
</VirtualHost>
What can I do to keep this path (one directory by domain) but to split the php logs by day (20131218.log, 20131219.log, etc. instead of error.log) ?
Wrikken (see comments) suggests simply using logrotate - but in order for this to work, you need to close and reopen every file handle referencing the log - if you are using a Linux distribution with logrotate already configured for Apache and PHP is invoked via mod_php and you don't mind the interruption to the service, then you just need to add this file to the logs rotated for Apache. But this becomes very messy if you want to keep your server up or you are using php-fpm. But you didn't tell us about the webserver, the operating system or the SAPI version.
Other solutions
(on Linux/Unix/BSD) use the system logging daemon (error_log=syslog) nd configure that to rotate the logs
on Apache, if the error_log is ini is unset, then errors are sent to stderr, and Apahce writes these to it's error log: and you can configure this to run via a bundled filter which automatically rotates logs
We have a linux hosting from a company and if any php script on that server has any PHP FATAL errors, it is automatically written into a file separately for each directory. So, although PHP errors are off in my scripts, I can still get the error logs as log files in each directory of those PHP scripts.
What I know that I can enable PHP error from configurations for my local server and set a specific file path which will contain all PHP errors from all scripts AND from all directories. But, I would love something automatic and separate like them.
How can I achieve the function in my local servers that we have on our hosting? Have they written a special script or is that a PHP ini settings that I should know?
UPDATED
Let's say public_html directory has three A, B and C directory or folder. There are three scripts a.php, b.php and c.php in those directories respectively. So, each of those directories will have error_log file that can contain all errors of those scripts separately. Let's say, folder A has also another script called d.php. But, errors from a.php and d.php will be written under public_html/A/error_log file.
Other directories will also have following files:
public_html/B/error_log file
public_html/C/error_log file
In php.ini, I had to enable the following setting and restart the server. It worked like I needed.
error_log = "error"