Best Practice: Run manual scans regularly, especially after installing new software or
receiving suspicious files.
7. RKHunter (Rootkit Hunter)
Installation
sudo apt install rkhunter
Update Properties Database
sudo rkhunter --propupd
Perform Complete System Check
sudo rkhunter --checkall --sk
Flags:
--sk or --skip-keypress: Skip pressing Enter after each test
View Log Files
sudo cat /var/log/rkhunter.logsudo less /var/log/rkhunter.log
Remove Automatic Cron Jobs
cd /etc/cron.daily/sudo rm rkhuntercd /etc/cron.weekly/sudo rm rkhunter
Note: Removing cron jobs allows manual control over when security scans are performed.
8. Database Tuning (MariaDB/MySQL)
View InnoDB Buffer Pool Actual Memory Usage
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_bytes_data';
View All Database Sizes
SELECT table_schema AS "Database", ROUND(SUM(data_length + index_length) /
1024 / 1024, 2) AS "Size (MB)" FROM information_schema.tables GROUP BY table_schema;
View InnoDB Database Sizes Only
SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 /
1024 AS "Size (MB)" FROM information_schema.tables WHERE engine = 'InnoDB' GROUP BY
table_schema;
View Buffer Pool Usage by Database
SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 /
1024 AS "Size (MB)" FROM information_schema.tables WHERE engine = 'InnoDB' GROUP BY
table_schema;
View Database Table I/O Statistics
SELECT object_schema AS 'Database', object_name AS 'Table', COUNT_READ AS
'Reads', COUNT_WRITE AS 'Writes', SUM_TIMER_READ / 1000000000 AS 'Read Time (ms)', SUM_TIMER_WRITE /
1000000000 AS 'Write Time (ms)' FROM performance_schema.table_io_waits_summary_by_table ORDER BY
SUM_TIMER_READ + SUM_TIMER_WRITE DESC;
Run MySQLTuner
cdcd MySQLTuner/ls -lsudo ./mysqltuner
MySQLTuner: A Perl script that analyzes your MySQL/MariaDB installation and provides
recommendations for optimization.
9. Disk Space Management
Critical: Monitor disk space regularly. Running out of disk space can cause server
crashes.
Check Disk Space Usage
df -h
The -h flag displays sizes in human-readable format (KB, MB, GB).
Clean Package Cache
sudo apt autoremove && sudo apt clean
Clean System Logs
sudo journalctl --vacuum-time=1days
This removes journal logs older than 1 day.
Analyze Directory Sizes
cd /du -ah --max-depth=1 | sort -h
Largest directories are displayed at the bottom. You can navigate to any directory and repeat the
command.
Disk Space Monitoring Workflow
Check Disk Space df -h
↓
Identify Large Directories du -ah --max-depth=1
↓
Clean Packages & Logs apt clean, journalctl
10. Nginx Connection Backlog Configuration
Configure the connection backlog for better handling of concurrent connections:
Backlog: Defines the maximum queue length for pending connections. Higher values can
improve performance under heavy load.
11. PHP OPcache Files Monitoring Script
Create the Script
nano opcache_files.sh
Script Contents
#!/bin/bashround_to_prime() { local value=$1 primes=(223 463 983 1979 3907 7963 16229 32531 65407 130987 262237 524524
1048793) closest=0 min_diff=$((value - primes[0])) for prime in "${primes[@]}"; do diff=$((value - prime)) if [ $diff -lt 0 ]; then closest=$prime break elif [ $diff -lt $min_diff ]; then min_diff=$diff closest=$prime fi done echo "$closest"}echo ""echo "Checking for opcache.max_accelerated_files directive in PHP pool
files..."echo ""echo "The value used (actual value) will be the first number in the set of
prime numbers"echo "223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987, 262237,
524521, 1048793"echo "that is greater than or equal to the configured value (value
set)"echo ""POOL_DIR="/etc/php/8.3/fpm/pool.d/"for file in "$POOL_DIR"*.conf; do filename=$(basename "$file") if grep -q "opcache.max_accelerated_files" "$file"; then value=$(grep "opcache.max_accelerated_files" "$file" | awk -F'=' '{print
$2}' | tr -d ' ') rounded_value=$(round_to_prime "$value") echo "File: $filename - opcache.max_accelerated_files: set value ($value)
actual value ($rounded_value)" else echo "File: $filename - opcache.max_accelerated_files directive not
found" fidoneecho ""echo "Listing domain names and number of PHP files in public_html
directories..."echo ""WWW_DIR="/var/www/"for domain_dir in "$WWW_DIR"*/ ; do if [ "$domain_dir" == "/var/www/html/" ]; then continue fi domain_name=$(basename "$domain_dir") public_html_dir="$domain_dir/public_html/" if [ -d "$public_html_dir" ]; then php_file_count=$(find "$public_html_dir" -type f -name "*.php" | wc
-l) echo "WordPress site: $domain_name - PHP files: $php_file_count" else echo "Domain: $domain_name - public_html directory not found" fidoneecho ""
Purpose: This script checks OPcache configuration and counts PHP files per domain to
help optimize the opcache.max_accelerated_files setting.
12. Common WordPress Update Issues
Issue 1: "Another update is currently in progress"
This occurs when WordPress fails to remove the core updater lock.
Solution: Remove Lock via SQL
mysql -u root -pSHOW DATABASES;USE your_database_name;DELETE FROM wp_options WHERE option_name = 'core_updater.lock';exit
Important: Change wp_ to your actual table prefix if different.
Issue 2: "Briefly unavailable for scheduled maintenance"
This indicates a stuck maintenance mode, usually from an interrupted update.
Solution: Delete Maintenance File
cd /var/www/example.com/public_html/sudo rm .maintenance
Post-Fix Recommendation
After resolving either issue, reload PHP-FPM to clear the opcache:
sudo systemctl reload php8.3-fpm
13. Best Practices Summary
System Maintenance
Run system updates regularly (weekly recommended)
Monitor disk space usage proactively
Review security scan logs regularly
Keep database optimized with MySQLTuner recommendations