I have tried two different things on my server:
created a directory php in /var/log/
changed owner:group to www-data:www-data (apache owner)
changed permissions of the directory to 775
php.ini has error_log = "/var/log/php/php.log"
php.ini already had error logging set to on, and error reporting set to all
restarted apache
in the code, changed error_log('message') to error_log('message',3,path_to_logfile)
Neither results in messages in the applicable log file.
You say you created /var/log, but you're trying to write to /var/log/php. Try creating a directory called php in /var/log.
Related
I'm having an issue where Xampp isn't logging my errors. The file path doesn't exist when I search for it. I read some stuff about this that said I need to enable php_error_log from the php.ini file but i don't know what values to change.
It should be a permissions issue (depending where you installed XAMPP). The XAMPP panel is sometimes unable to create the logs folder. Just create this directory:
...\xampp\php\logs
and the next time PHP error occurs it will create the php_error_log file inside and the logging will start.
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.
In my first PHP script in many years, I'm trying to log an error:
error_log("my error message", 3, $error_log);
I'm getting an error in the general Apache error log:
PHP Warning: error_log(/var/log/apache2/my_php_errors.log): failed to open stream: Permission denied in /var/www/html/blahblah/my_script.php on line 88
This is what I've checked and tried:
Created $error_log with the same ownership (root.adm) and permissions (640) as the Apache error log.
Changed the owner to www-data, which is the user PHP is running as.
log_errors is On.
open_basedir is not set.
Using PHP 5.5.x, so safe mode does not exist.
What am I missing?
Edit: It's able to write to the general Apache error log. The mystery is why it can't write to another file in the same directory with the same ownership and permissions.
Edit 2: Another developer told me that this works on his WAMP, so it's something specific to my LAMP stack or config.
I had the same problem.
https://serverfault.com/questions/831444/php-error-log-per-vhost/831666#831666
touch /path/to/php_error.log
chown www-data:www-data php_error.log
chmod 755 php_error.log
thanks for leading me to the answer!
TL;DR: check that all the ancestor directories allow reads/lists by the web server.
On my system, my equivalent of /var/log/apache2/my_php_errors.log was giving this same error. I eventually did an ls -ld at every level of the path (/, /var/, /var/log/, /var/log/apache2/, /var/log/apache2/my_php_errors.log).
Four of those had permissions that made them readable by the web server. One of them, /var/log/apache2/ did not. When I moved my file out of the apache2 directory, everything started working. E.g. /var/log/php/ and set appropriate permissions/ownership (e.g. 750 by www-data.adm) on the new directory.
prompt> ls -ld /var/log/php/
drwxr-x--- 2 www-data adm 4096 Nov 1 13:31 /var/log/php/
You could also change the permissions on /var/log/apache2/, but that seems like a security/privacy issue. It's safer to make a new directory and leave the existing structure as is.
The reason why the permissions have to change is that it is no longer using some version of syslog to publish to the log files. The syslog variants run as root and accept messages from non-root. But in my case, I was specifying the file from the web server, which made the permissions wrong.
There is a fix that uses syslog so that it could keep the same ownership. I did not try to make that work, as this is for a test server.
This may not have been the problem that you were having, but I'm pretty sure that I was using the default permissions for /var/log/apache2/. So it's quite possible that it was the problem. And even if it wasn't, this is one of the places I was searching for troubleshooting advice. So next time something like this happens to me, I'll have a reminder of what to check.
I'm getting an error on production server but am unable to figure out what it is. Blank page with 500 response code isn't very helpful and adding ini_set to output the error doesn't help because I'm using Symfony and that has another way of dealing with errors that will take me 2 days to figure out.
Apache logs php errors and php is supposed to log php errors, phpinfo tells me that log_errors is on and error_log is /var/log/php.log. That file contains a warning of 1.5 years ago so I guess Symfony is messing things up somewhere.
Try Apache/httpd log. After figuring out what config files are used and where the log is I can't find anything in there after getting a 500 error. Does it take a while before that gets written?
Stuck here and not sure how to figure out what it is that's causing the error. Are there any other options? I guess Symfony should log it somewhere but Symfony/app/logs is empty, there was a very large dev.log there but after renaming it it isn't created again.
Make sure that the file that you have set PHP to log to in the php.ini file is in the group for which the http server runs as. Typically this user is www-data
chown /var/log/php_errors.log root::www-data
chmod 664 /var/log/php_errors.log
sudo apache2 restart
Nothing was written to the php error log because the permissions were set wrong and user running httpd could not write to it.
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.