PHP app access logs
An app’s PHP access log contains records of every PHP request received by an app along with information about the response sent by PHP.
View the logs
An app’s PHP error logs can be viewed from within the ServerPilot dashboard or through SSH.
Log file location
Relative to the home directory of the app’s system user, the path to an app’s PHP access log is:
log/APPNAME/APPNAME_php8.4.access.log
log/APPNAME/APPNAME_php8.3.access.log
log/APPNAME/APPNAME_php8.2.access.log
log/APPNAME/APPNAME_php8.1.access.log
log/APPNAME/APPNAME_php8.0.access.log
log/APPNAME/APPNAME_php7.4.access.log
log/APPNAME/APPNAME_php7.3.access.log
log/APPNAME/APPNAME_php7.2.access.log
log/APPNAME/APPNAME_php7.1.access.log
log/APPNAME/APPNAME_php7.0.access.log
log/APPNAME/APPNAME_php5.6.access.log
where APPNAME
is the name of the app.
Log file format
The format of each log entry is:
IP_ADDRESS - [DATE_TIME] "METHOD PHP_REQUEST_URI" RESPONSE_CODE CONTENT_LENGTH - MASTER_PID CHILD_PID REQUEST_SECONDS PEAK_MEMORY_MB USER_CPU_PCT SYSTEM_CPU_PCT "ORIG_REQUEST_URI"
For example:
203.0.113.0 - [04/Mar/2025:06:52:33 -0500] "GET /index.php" 200 0 - 1955 24792 0.001 2097152 0.00% 0.00% "/blog"
The fields in each log entry are described in the following table.
Field | Field meaning |
---|---|
IP_ADDRESS | IP address of the client that made the request. For servers behind proxies, this field will be the full contents of the X-Forwarded-For header. |
DATE_TIME | The date and time of when the request was received. |
METHOD | The request method such as GET or POST . |
PHP_REQUEST_URI | The request path and query string after processing by Apache RewriteRule directives. |
RESPONSE_CODE | The status code of the response such as 200 or 404 . |
CONTENT_LENGTH | The size of the response in bytes. |
MASTER_PID | The process ID of the PHP-FPM master process. |
CHILD_PID | The process ID of the PHP-FPM child process. |
REQUEST_SECONDS | The execution time of the request in seconds. |
PEAK_MEMORY_MB | The peak memory usage while executing the request. |
USER_CPU_PCT | The percentage of CPU used (user space CPU only). |
SYSTEM_CPU_PCT | The percentage of CPU used (kernel space CPU only). |
ORIG_REQUEST_URI | The request path and query string before processing by Apache RewriteRule directives. |
Example commands
To set a LOGFILE
variable in your shell session, run the following command
(replace APPNAME
with the app’s name).
LOGFILE=log/APPNAME/APPNAME_php8.4.access.log
LOGFILE=log/APPNAME/APPNAME_php8.3.access.log
LOGFILE=log/APPNAME/APPNAME_php8.2.access.log
LOGFILE=log/APPNAME/APPNAME_php8.1.access.log
LOGFILE=log/APPNAME/APPNAME_php8.0.access.log
LOGFILE=log/APPNAME/APPNAME_php7.4.access.log
LOGFILE=log/APPNAME/APPNAME_php7.3.access.log
LOGFILE=log/APPNAME/APPNAME_php7.2.access.log
LOGFILE=log/APPNAME/APPNAME_php7.1.access.log
LOGFILE=log/APPNAME/APPNAME_php7.0.access.log
LOGFILE=log/APPNAME/APPNAME_php5.6.access.log
To see the value of the LOGIFLE
variable you’ve set, run the command:
echo "${LOGFILE}"
Count requests per IP address
Print the number of requests per client IP address for the 20 addresses that have made the most requests.
cat "${LOGFILE}" | awk '{print $1}' | sort | uniq -c | sort -n | tail -n 20
View requests from a specific IP address
IP_ADDRESS=1.2.3.4grep -F "${IP_ADDRESS}" "${LOGFILE}"
Count total requests
wc -l "${LOGFILE}"
See when the current log file began
The first entry in the log file shows the time of the first request received since the most recent log rotation.
head -n 1 "${LOGFILE}"
View the most recent requests
tail -n 50 "${LOGFILE}"
Count requests by response code
Count 404 responses.
grep -cF " 404 " "${LOGFILE}"
Count 301 and 302 responses.
grep -cF -e " 301 " -e " 302 " "${LOGFILE}"
View requests by response code
View the 100 most recent 404 responses.
grep -cF " 404 " "${LOGFILE}" | tail -n 100
View the 100 most recent 301 and 302 responses.
grep -cF -e " 301 " -e " 302 " "${LOGFILE}" | tail -n 100