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()
Related
Title pretty much says it all. I've been tearing my hair out trying to get this working all day. I'm in the process of creating a PHP-based login system and I need to do some debugging. The most useful thing to me right now would be the ability to write debugging messages to a file at certain points throughout a PHP program. Based on the documentation, it looks like this is what error_log() is supposed to do, but despite everything I've tried, I have had absolutely no success. Full list of everything I've tried below:
Added the following to /etc/php/7.0/apache2/php.ini
error_reporting = E_ALL
display_errors = On
log_errors = On
Additionally, tried setting error_log to locations within /usr/, /var/www/http/, and /home/
Used ini_set() and error_reporting() to set all of those variables, including error_log from within a PHP file
Manually creating the files that are supposed to be written to, and setting their owning user and group to www-data and their permissions to 777
Last but not least, reinstalling libapache2-mod-php7.0 and php7.0, to no avail
Basically everything short of using my laptop to break the 3rd story window of my office building immediately prior to jumping to my prospective death
I really can't find anthing else to try on Google, so I figured I'd ask the experts, and here I am. If anyone can provide any suggestions, it would be greatly appreciated.
I guess the logs are written to sys logs because in error_log() you didn't provide the destination.
Try the following code
error_log("An error occured", 3, "/var/tmp/my-errors.log");
Be sure this file can be read by php either fpm or www-data depending on your configuration you can create it before with touch and add permissions manually with chmod
3 means that destination is a file
If you use apache then check in httpd.conf or any other place(v where it may be present the location of ErrorLog
ErrorLog "/var/log/apache2"
Then check if this file has following user group with ls -la ll etc.
-rwxrwxr-x 1 www-data www-data
Something like this should appear.
The other option is to set following in proper php.ini (CLI and apache have different php.ini files)
error_log = /var/log/phperrors.log
then
touch /var/log/phperrors.log
chown www-data: /var/log/phperrors.log
chmod +rw /var/log/phperrors.log
There are no miracles but if it still doesn't work you can write and register your own error handler with set_error_handler() you can find examples how to do it in php manual. It's more like hack but it will work for sure. If it won't then it means that errors are not triggered at all then you should look if you edit the correct php.ini or use ini_set() before error is triggered.
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.
i have error in my page but it is not logs in to the log file
i have set
display_errors:Off
display_startup_errors:Off
error_log:error_log
log_errors:On
i have restarted apache after configuration
but it is not working
just checked the apache file /etc/httpd/logs/error_log file
it contain the error but why the error_log does not creating in the folder in which error occurs
try this in your php file
ini_set("log_errors", 1);
ini_set("error_log",$_SERVER['DOCUMENT_ROOT']."/logs/php-error.log");
Give write permission to the folder logs and its file, then check the file in logs folder.
error_log:error_log
error_log not has correct path, set a correct path like below
log_errors = On
error_log = "C:\xampp\php\logs\php_error_log"
You said:
just checked the apache file /etc/httpd/logs/error_log file it contain the error ...
which means:
loggine php errors works
all errors are written to /etc/httpd/logs/error_log
You also said:
... but why the error_log does not creating in the folder in which error occurs
Your php.ini directove error_log specifies where your want your error log to be. Now it is default. Specify different log file location and you'll have it in different place. There is no why - it lands where it is said to be.
I have configured Amazon EC2 Server and install PHP and MySQL. I have uploaded my website on it. it is in smarty.
Problem is when I update any .tpl file, then the server return white page as output in Firefox and Chrome return 500 Internal Server Error. I have surfed everywhere on internet but got nothing.
When I update any .php file then the code work nicely. problem is only with .tpl file.
I'm willing to bet that your templates_c directory is not writable by Apache (identified as apache or httpd, and you can check in your httpd.conf file), or it hasn't been configured correctly during Smarty initialization.
You can try temporarily setting your templates_c directory to 777 permissions to test this hypothesis.
If this ends up being the case, then you'll want to assign group ownership of templates_c to apache, and set the folder permissions to 775. (They explain this in their documentation.)
An HTTP status of 500, with no page content (Chrome is just being nice and rendering a default error message for you) means that PHP encountered a Fatal Error.
You will need to find out where PHP is configured to log to (usually a file called php_errors.log) and see what the error was.
Alternatively, you could temporarily allow PHP to output errors to screen, using the error_reporting setting.
Currently, when a PHP error occurs, it will log it into a file called error_log in the same directory the error occurred in.How can I keep the error_log files outside of the web root so that users cannot view them, for security?
Edit your php.ini file. Find the error_log setting and change it to the full path of where you want the error_log file to be written.