Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 352
Mervin Avatar asked May 26 '11 07:05

Mervin


People also ask

Where does PHP store error log?

The location of the error log file itself can be set manually in the php. ini file. On a Windows server, in IIS, it may be something like "'error_log = C:\log_files\php_errors. log'" in Linux it may be a value of "'/var/log/php_errors.

How do I create a PHP error log?

Enable Error Logging in php. To log errors in PHP, open the php. ini file and uncomment/add the following lines of code. If you want to enable PHP error logging in individual files, add this code at the top of the PHP file. ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

Can I delete my PHP error log?

Yes. You can delete it. However PHP is going to continue to write its errors there, re-creating the file if it doesn't exist. You can modify error_log in your php.

How do I view PHP error logs?

Press CTRL + F for Windows or Command + F for MacOS to open the search bar on your web browser. Type log_errors to find the log_errors row. If the value is Off, then the PHP error logging is disabled.


2 Answers

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"
like image 169
T0xicCode Avatar answered Sep 19 '22 23:09

T0xicCode


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.

like image 35
Tudor Constantin Avatar answered Sep 17 '22 23:09

Tudor Constantin