I don't know if there's any? but is php built in web server also save its error logs in a file? for tailing purposes, like when creating virtual host in apache.
UPDATE: i'm using mac osx
The built-in webserver doesn't log anywhere by default, so you need to provide a php.ini for it to customise this. For example, if you created a file called php.ini with this content:
error_log = /Users/me/test.log
log_errors = on
date.timezone = UTC
Then you can start PHP's built-in webserver like this:
php -S 127.0.0.1:8080 -c php.ini
And error_log() calls will be logged to the file you've specified.
Yes, PHP has built in error log functionality.
PHP logs errors to this file automatically.
If you want to log errors, use the function error_log()
The file's location changes depending upon enviroment.
e.g.
in Ubuntu 12.04, its
var/log/php_errors.log
In XAMPP windows,
\xampp\php\logs\php_errors.log
In Mac OS,
/var/log/apache2/php_errors.log
When using PHP builtin server on macOS, you need to specify error_log
in your php.ini
config file (php -i | grep php.ini
).
If you decide with syslog
(instead of a log file) such as:
error_log = syslog
Then to dump the logs, you can use log
command on macOS, e.g.
log stream --predicate 'processImagePath contains "php"'
Otherwise use some specific file path for the error log (e.g. /usr/local/var/log/php-error.log
).
To update for Mac OS X High Sierra (10.13.5): this worked for me with no need to change any PHP defaults. Just use
error_log('*** notice this***');
and tail the error log:
tail -f /var/log/apache2/error_log
I primarily know linux but AFAIK this works the same on whatever sytem you can run php. I recently spent an unreasonable amount of time getting linux to run on a "obsolete" macmini from 2009. I don't know how anyone tolerates that manufactured obsolescence. Android is just is bad, hiding behind that "based on linux" nonsense. I wonder how many lawyers it took to figure that one out? Of course, GPL doesn't say anything about the hardware! Thanks to them, when mobile devices inevitably replace laptops and desktops over the next decade, the threat of the ideas behind free software will have been mostly eliminated. They should put that kind of engineeringto work in consumer smoke alarm technology..
Anyway, enough about that. I'll attempt to return to topic and teach you how to do this in a way that will give you the tools to complete similar different tasks in the future. It's like that old saying goes, "Teach a man to fish and won't be able to sell him anymore fish"
I always like to begin with a man [command]
or [command] --help
if --help
or -h
doesn't work, try to pass it invalid input, that will usually get it talking. Be careful at this step, it's easy to get stuck reading man pages for several hours, try not to forget any time obligations you might be under.
php --help
Find the option to set ini variables:
-d foo[=bar] Define INI entry foo with value 'bar'
Reading an example php.ini
we find the settings of interest.
; error_reporting
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
///
; Log errors to specified file. PHP's default behavior is to leave this value
; empty.
; http://php.net/error-log
; Example:
;error_log = php_errors.log
; Log errors to syslog (Event Log on Windows).
;error_log = syslog
all the other defaults look ok so... let's try:
php -d error_reporting=E_ALL -d error_log=/desired/path/to/error.log -S 0.0.0.0:9999
You might notice the log printing to stderr
from here. Alternatively, you could redirect that by adding 2> /path/to/error.log
to the end of the above command. Simpler, but then you wouldn't have learned about -d
options to set values from php.ini and -c
to use a custom file, but you'd have learned about output redirection which i'd say is a far more important concept with countless applications.
If you are using Mac OS or Ubuntu, this the way you can easily look into the error log
tail -f /var/log/apache2/error_log
this will give you error log in realtime or you can use , which will give last error logs
tail /var/log/apache2/error_log
来源:https://stackoverflow.com/questions/27122267/php-built-in-server-error-log-location