Where can I find error log files for PHP? - php

Where can I find error log files?
I need to check them for solving an internal server error shown after installing suPHP.

You can use lsof to find open logfiles on your system. lsof just gives you a list of all open files.
Use grep for "log" ... use grep again for "php" (if the filename contains the strings "log" and "php" like in "php_error_log" and you are the root user you will find the files without knowing the configuration).
lsof | grep log
... snip
gmain 12148 12274 user 13r REG 252,1 32768 661814 /home/user/.local/share/gvfs-metadata/home-11ab0393.log
gmain 12148 12274 user 21r REG 252,1 32768 662622 /home/user/.local/share/gvfs-metadata/root-56222fe2.log
gvfs-udis 12246 user mem REG 252,1 55384 790567 /lib/x86_64-linux-gnu/libsystemd-login.so.0.7.1
==> apache 12333 user mem REG 252,1 55384 790367 /var/log/http/php_error_log**
... snip
lsof | grep log | grep php
**apache 12333 user mem REG 252,1 55384 790367 /var/log/http/php_error_log**
... snip
Also see this article on finding open logfiles: Find open logfiles on a Linux system

It works for me. How can we log all PHP errors to a log file?
Just add the following line to file /etc/php.ini to log errors to specified file – file /var/log/php-scripts.log
vi /etc/php.ini
Modify the error_log directive:
error_log = /var/log/php-scripts.log
Make sure display_errors is set to Off (no errors to end users):
display_errors = Off
Save and close the file. Restart the web server:
/etc/init.d/httpd restart
How do I log errors to syslog or Windows Server Event Log?
Modify error_log as follows:
error_log = syslog
How can we see logs?
Login using ssh or download a log file /var/log/php-scripts.log using SFTP:
sudo tail -f /var/log/php-scripts.log

On CentOS with cPanel installed, my logs were in:
/usr/local/apache/logs/error_log
To watch: tail -f /usr/local/apache/logs/error_log

It depends on what OS you are using and which web server.
On Linux and Apache, you can find the Apache error_log in folder /var/log/apache2/.

This will definitely help you,
Enable PHP error logging
Or
In php.ini (vim /etc/php.ini or sudo vim /usr/local/etc/php/7.1/php.ini)
display_errors = Off
log_errors = On
error_log = /var/log/php-errors.log
Make the log file, and writable by user www-data:
sudo touch /var/log/php-errors.log
/var/log/php-errors.log
sudo chown <owner>:www

I am using CentOS 6.6 with Apache and for me error log files are in:
/usr/local/apache/log

This is a preferable answer in most use cases, because it allows you to decouple execution of the software from direct knowledge of the server platform, which keeps your code much more portable. If you are doing a lot of cron or CGI, this may not help directly, but it can be set into a configuration at web runtime that the cron and CGI scripts pull from to keep the log location consistent in that case.
You can get the current log file assigned natively to PHP on any platform at runtime by using:
ini_get('error_log');
This returns the value distributed directly to the PHP binary by the web server, which is what you want in 90% of use cases (with the glaring exception being CGI). CGI will often log to this same location as the HTTP web server client, but not always.
You will also want to check that it is writeable before committing anything to it to avoid errors. The configuration file that defines its location (typically either file apache.conf globally or vhosts.conf on a per-domain basis), but the configuration does not ensure that file permissions allow write access at runtime.

For Unix CLI users:
Most probably the error_log ini file entry isn't set. To verify:
php -i | grep error_log
// error_log => no value => no value
You can either set it in your php.ini CLI file, or just simply quickly pipe all standard error yourself to a file:
./myprog 2> myerror.log
Then quickly:
tail -f myerror.log

Related

Force defined php.ini log file

php.ini:
error_log = /var/log/php.log
Running on shell:
php#> error_log("test");
// WRITES TO /var/log/php.log
Running on apache index.php:
error_log("test");
// WRITES to apache/error_log
Apache 2.4.6 / Php 5.4.16
I already checked for alternative php.ini files
What i need is the apache directive that controls it, already looked in the man page.
Already checked permissions and file ownership
You may set this path directly from the PHP code. For example:
ini_set("log_errors", 1);
ini_set("error_log",$_SERVER['DOCUMENT_ROOT']."/logs/php-error.log");
My new vps have SELinux enabled so i had to add this attr to the file
sudo chcon -t httpd_log_t php.log

I lost my php-fpm.sock file from / var / run / php-fpm /

I installed PHP 7 on Red Hat Linux server, but apparently due to running a few commands on the server to configure PHP I have the lost the php-fpm.sock file.
Could anyone please assist me with contents of the file?
Yes that file should be auto generated, do not create the file manually! Ensure that the service is running service php-fpm start If it still fails, check the permissions. Check here for help: /etc/php-fpm.d/www.conf This is your main php-fpm config file. Make sure user, group, listen.owner, listen.group are set to your either nginx or apache user, depending on what web server you use. Also note that listen point to the actual socket file.

Allow Apache/PHP a read/write access to a mounted directory

We have websites running on a linux server with apache httpd and php. On that server a certain directory from a windows server is mounted as let's say /mnt/some_directory/. I can browse this directory with both WinSCP or SSH, using my own user account.
I can also perform the following in SSH:
php -r "print_r(file_get_contents('/mnt/some_directory/file_name.txt'));"
and see contents of that file.
We need to read a file and parse from that directory in order to import it in the database that is used by the website. But when an fopen or a file_get_contents on the website we get a permission denied error.
I have limited access to the web server (and limited knowledge of *nix and apache configuration), but the administrator that is supposed to resolve this apparently is also lacking this knowledge and I need to have this task resolved,that's why I am asking here.
What the admin did was to set the group and ownership of the mounted directory to"apache", which is the user the httpd process is running as. But that didn't help.
As far as I know access to files outside of the webroot is disallowed by default. Would it be sufficient to set a DIRECTORY directive in httpd.conf for /mnt/some_directory/? Or is there anything else that has to be done?
our team had the same issue, my team-mate was able to resolve this by adding context to mount options.
we are using the following format for mounting windows shared folder to linux that apache will be able to access:
mount -v -t cifs <//$hostname/$(windows shared dir)> <mount directory> -o username="<username>",password=<password>,domain=<domain name>,iocharset=utf8,file_mode=0777,dir_mode=0777,context="system_u:object_r:httpd_sys_content_t:s0"
For example:
mount -v -t cifs //192.168.1.19/sample_dir /mnt/mount_dir -o username="admin",password=adminpwd,domain=MIINTER,iocharset=utf8,file_mode=0777,dir_mode=0777,context="system_u:object_r:httpd_sys_content_t:s0"
Link the mounted directory to your www root dir and name the link "share"
ln -s /mnt/some_directory /path/to/your/www/root/directory/share
than try reading the file
php -r "print_r(file_get_contents('/path/to/your/www/root/directory/share/file_name.txt'));"
...or you can allow (if you have enough privileges to edit the webserver's configuration)
<Directory /mnt/somedirectory >
Allow from All
</Directory>
i have seen the same problem with a cifs mount
linux/unix apache that user can have access to the mounted volume, but not apache.
see also this: EnableSendfile off
but when turned off, apache may work slowly,
in .htaccess, only for the cifs mount path, it should work ... .
http://httpd.apache.org/docs/current/en/mod/core.html
best regards
L.Tomas

Can't get PHP errors to go to a log file (other than the Apache log)

On a Ubuntu web server [LAMP], I'm trying to get PHP errors to write into a php_error file, but no matter what I do, they keep going to the apache log.
Here's what I have tried/done:
Edited the php.ini file:
error_reporting = E_ALL | E_STRICT
display_error = Off
log_errors = On
error_log = /var/log/php_errors.log
Restarted Apache
Checked the phpinfo() output to verify that the changes I made to the php.ini file took -- they did.
After verifying that the errors were still going to the Apache log, I physically created the php_errors.log and tried again. Still going to the Apache log!
Rebooted the web server! Still...!
Anybody have a solution?
Check the directory permissions for /var/log. Ensure that the user your Web service is running as has write permissions to that folder. Alternatively, create a subfolder (/var/log/phplogs?) and assign explicit permissions on that for the user in question then change the error_log value to be a file in that folder
It had to do with ownership. One or the other has worked [for reasons that are not clear to me]:
chown www-data:www-data /var/log/php_error.log
chown same-user-as-www-home:same-user-as-web-home /var/log/php_error.log
Also, the following has made a difference:
chmod 664 /var/log/php_error.log
[as opposed to chmod 644...again for reasons that are not clear to me]
For the record, Ubuntu uses AppArmor and it limits what Apache does.
Additionally, to change the permissions to the file and editing the php.ini file, you must do the next steps:
Go to the next file
/etc/apparmor.d/abstractions
Edit this file
apache2-common
Add the next line
/var/log/php_errors.log rw,
where rw means the process could read and write this file
or you could also do:
sudo nano /etc/apparmor.d/abstractions/apache2-common
And finally, reload the configuration of apparmor
systemctl reload apparmor
Note: Centos/Redhat/Oracle Linux uses SELinux and it requires the same step but the configuration is different.

Store PHP error log file in the script directory without adding PHP code to existing scripts

I have been busy setting up my own VPS after being used to cPanel, but I can't seem to find out how to let PHP create an error_log file in the same directory as the script that throws the errors.
I would like this to happen without me having to add a line of code to each .php file. In cPanel this works out of the box somehow.
Example:
Error in: /var/www/webapp1/index.php
Logfile location: /var/www/webapp1/error_log
Error in: /var/www/info/system/test.php
Logfile location: /var/www/info/system/error_log
Basically, I want PHP to store an error_log file in each directory for the scripts in that directory.
Additional information:
Single VPS account
Debian 6.0 (Squeeze) GNU/Linux
Apache 2.2.16
Set the error_log value to the name of the error log you want to appear in the directory, but do not put any slashes. The file will be saved in the directory from which the script is ran, so the same directory.
error_log = "php_error.log"
For this, there is the error_log directive in php.ini like:
error_log string
Where string represents the name of the file where script errors should be logged. The file should be writable by the web server's user. If the special value syslog is used, the errors are sent to the system logger instead. On Unix, this means syslog(3) and on Windows NT it means the event log. The system logger is not supported on Windows 95. See also: syslog(). If this directive is not set, errors are sent to the SAPI error logger. For example, it is an error log in Apache or stderr in CLI.
Edit your php.ini file and uncomment the line with error_log:
error_log = php_errors.log
Save the changes, restart Apache, and be happy.
If you're using Linux, open a terminal and type this to restart:
sudo services apache2 restart
If you have access to WebHost Manager (WHM) you can search for SERVICES and then restart HTTPD or Apache.
If you're using EasyPHP or Vertrigo, you can do that through the program it self.
basically I want php to store an error_log file in each directory for the scripts in that directory
Assuming you're using Apache, you can use Apache's error_log directive in the VirtualHost to accomplish this behaviour. If memory serves me right, PHP itself doesn't decide where it stores its errors.

Categories