PHP built-in server error log location

后端 未结 6 1438
长发绾君心
长发绾君心 2021-01-01 16:17

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.

UP

6条回答
  •  星月不相逢
    2021-01-01 16:26

    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.

提交回复
热议问题