Skip to content

Instantly share code, notes, and snippets.

@dhsathiya
Last active January 29, 2024 11:21
Show Gist options
  • Save dhsathiya/09c09084b3a5486d483ea3a3b7f48529 to your computer and use it in GitHub Desktop.
Save dhsathiya/09c09084b3a5486d483ea3a3b7f48529 to your computer and use it in GitHub Desktop.

useful command for debugging.

tail -f <filename>
tail -f -n <number-of-tailing-lines> <filename>

#example to tail from last 1000 files
tail -f -n 1000 <filename>

WordPress debugging

Change these variables to true in site's wp-congig.php file.

// Enable WP_DEBUG mode.
define( "WP_DEBUG", true );

// Enable Debug logging to the /wp-content/debug.log file
define( "WP_DEBUG_LOG", true );

// Disable display of errors and warnings.
define( "WP_DEBUG_DISPLAY", true );

EasyEngine [V4]

Basically when you run a EasyEngine command everything will be stored in a debug log.

This debug log can be found at :

/opt/easyengine/logs/ee.log 

access MYSQL as root user

# get root pass:
docker-compose -f /opt/easyengine/services/docker-compose.yml exec global-db bash -c 'echo ${MYSQL_ROOT_PASSWORD}'

# access as root:
docker-compose -f /opt/easyengine/services/docker-compose.yml exec global-db bash -c 'mysql -uroot -p${MYSQL_ROOT_PASSWORD}'

access PHP shell

# As www-data user
ee shell <site-name>

# As root user
ee shell <site-name> --user=root

Nginx Logs :

#error.log
/opt/easyengine/sites/<sitename>/logs/nginx/error.logs

#access log
/opt/easyengine/sites/<sitename>/logs/nginx/access.logs

PHP Logs :

#error.log
/opt/easyengine/sites/<sitename>/logs/php/error.logs

#access log
/opt/easyengine/sites/<sitename>/logs/php/access.logs

Other service's logs

such as Nginx-Proxy, MariaDB, Redis etc. can be found at their respective directories at location:

/opt/easyengine/services/

Helpful when you want to purge single page cache or want to check if cache exists or not. This operation supports regex so that if you want to remove all cache key having a specific keyword you can do that.

Redis key purge

docker-compose -f /opt/easyengine/services/docker-compose.yml exec global-redis redis-cli --eval purge_all_cache.lua 0 , '<cachekey>'

Redis list keys

[displays the keys available maching the regex]

docker-compose -f /opt/easyengine/services/docker-compose.yml exec global-redis redis-cli keys "<cachekey>"

Redis display key

content [what content has been stored at that key] [helpful when key is generated but has different content than expected]

docker-compose -f /opt/easyengine/services/docker-compose.yml exec global-redis redis-cli get "<cachekey>"

EE Admin

To access Nginx status, PHP status, phpMyAdmin, and other admin tools run the following

ee admin-tools enable <site-name>

Admin-tools will be available at http://<sitename>/ee-admin/

To view admin-tools credentials run the following

ee auth list global

Mailhog

Mailhog captures the outgoing emails. To enable mailhog use

ee mailhog enable <sitename>

Mailhog UI will be available at http://<sitename>/ee-admin/mailhog

To view mailhog credentials run the following

ee auth list global

HTTP Auth

Enable HTTP Auth

ee auth create <sitename> --user=username --pass=password

Disable HTTP Auth

ee auth delete <sitename>

Get statistics of nginx body_bytes_sent

cd /opt/easyengine/sites/example.com/logs/nginx/

#Max out of last 20000

echo max: $(tail -n 20000 access.log | awk '($8 ~ /200/)' | awk '{print $11}' | sort -nr | head -n 1)

#Average of last 20000

total=$(tail -n 20000 access.log | awk '($8 ~ /200/)'  | wc -l ) && sum=$( tail -n 20000 access.log | awk '($8 ~ /200/)' | awk '{print $11}' | awk '{s+=$1} END {print s}') && expr $sum / $total

#Top 20 from last 20000
tail -n 20000 access.log | awk '($8 ~ /200/)' | awk '{print $11}' | sort -nr | head -n 20

Parse Nginx logs

# Get number of requests
#--General
cat access.log | cut -d '"' -f5 | cut -d ' ' -f10 | sort | uniq -c | sort -rn
awk '{print $10}' access.log | sort | uniq -c | sort -rn 
#--Precise
awk -F\" '{print $1}' access.log |   awk '{ if ($3 ~ /^[0-9]*\.*[0-9]+$/) {print $11} else {print $10}}' | sort | uniq -c | sort -rn

# Error 404 URLs
#--General
awk '($10 ~ /404/)' access.log | awk '{print $8}' | sort | uniq -c | sort -rn
#--Precise
awk -F\" '{print $1}' access.log |  awk '{ if ($3 ~ /^[0-9]*\.*[0-9]+$/) { if ($11 ~/404/) {print $9} } else { if ($10 ~/404/) {print $8} }}' | sort | uniq -c | sort -rn 

# Number of top URLs
#--General
awk -F\" '{print $1}' access.log | awk '{print $9}' | sort  | uniq -c | sort -rn
#--Precise
awk -F\" '{print $1}' access.log | awk '{ if ($3 ~ /^[0-9]*\.*[0-9]+$/) {print $9} else {print $8}}' | sort | uniq -c | sort -rn | head

# 5xx Errors with list of URLs
awk -F\" '{print $1}' access.log | awk '{ if ($3 ~ /^[0-9]*\.*[0-9]+$/) { if ($11 ~/5[0-9][0-9]/) {print $11"  "$9} } else { if ($10 ~/5[0-9][0-9]/) {print $10"  "$8} }}' | sort | uniq -c | sort -rn

# Print whole line if 5xx
awk -F\" '{print $1}' access.log | awk '{ if ($3 ~ /^[0-9]*\.*[0-9]+$/) { if ($11 ~/5[0-9][0-9]/) {print '$1'} } else { if ($10 ~/5[0-9][0-9]/) {print '$1'} }}' | sort | uniq -c | sort -rn

# A bash one liner to get response code.
(echo $line | awk '{ if ($3 ~ /^[0-9]*\.*[0-9]+$/) {print $11} else {print $10}}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment