简体   繁体   中英

store PHP error log file in 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 info:

  • Single VPS Account
  • Debian GNU/Linux 6.0 'Squeeze'
  • 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.

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.

Edit your php.ini and uncoment this:

error_log = php_errors.log

Save changes, restart apache, be happy.

If you'r using linux , open terminal and type this to restart:

sudo services apache2 restart

If you have access to WHM you can search for SERVICES and than restart HTTPD or Apache

If your using Easyphp or Vertrigo , you can do that trough the program it self.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM