Skip to content

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

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.

FieldField meaning
IP_ADDRESSIP 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_TIMEThe date and time of when the request was received.
METHODThe request method such as GET or POST.
PHP_REQUEST_URIThe request path and query string after processing by Apache RewriteRule directives.
RESPONSE_CODEThe status code of the response such as 200 or 404.
CONTENT_LENGTHThe size of the response in bytes.
MASTER_PIDThe process ID of the PHP-FPM master process.
CHILD_PIDThe process ID of the PHP-FPM child process.
REQUEST_SECONDSThe execution time of the request in seconds.
PEAK_MEMORY_MBThe peak memory usage while executing the request.
USER_CPU_PCTThe percentage of CPU used (user space CPU only).
SYSTEM_CPU_PCTThe percentage of CPU used (kernel space CPU only).
ORIG_REQUEST_URIThe 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).

Terminal window
LOGFILE=log/APPNAME/APPNAME_php8.4.access.log

To see the value of the LOGIFLE variable you’ve set, run the command:

Terminal window
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.

Terminal window
cat "${LOGFILE}" | awk '{print $1}' | sort | uniq -c | sort -n | tail -n 20

View requests from a specific IP address

Terminal window
IP_ADDRESS=1.2.3.4
grep -F "${IP_ADDRESS}" "${LOGFILE}"

Count total requests

Terminal window
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.

Terminal window
head -n 1 "${LOGFILE}"

View the most recent requests

Terminal window
tail -n 50 "${LOGFILE}"

Count requests by response code

Count 404 responses.

Terminal window
grep -cF " 404 " "${LOGFILE}"

Count 301 and 302 responses.

Terminal window
grep -cF -e " 301 " -e " 302 " "${LOGFILE}"

View requests by response code

View the 100 most recent 404 responses.

Terminal window
grep -cF " 404 " "${LOGFILE}" | tail -n 100

View the 100 most recent 301 and 302 responses.

Terminal window
grep -cF -e " 301 " -e " 302 " "${LOGFILE}" | tail -n 100