Server Administration & WordPress Optimization Guide
The opcache.max_accelerated_files directive defines the maximum number of PHP script files
that OPcache can store in its internal hash table. This setting directly impacts the number of scripts
that can be cached for faster retrieval, thereby improving PHP application performance.
opcache.max_accelerated_files directive.
Run these commands individually:
sudo apt updatesudo apt upgradesudo apt autoremoveCombine all commands in one line:
sudo apt update && sudo apt upgrade && sudo apt autoremoveSkip confirmation prompts with the -y flag:
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -yNavigate to home directory and edit bash aliases:
cdnano .bash_aliasesAdd the following alias:
alias server_updates='sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y'Activate the alias by exiting and re-logging:
exitCreate the script file:
sudo nano server_updates.shScript contents:
#!/bin/bash
# Check if script is run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run this script with sudo or as root."
exit
fi
# Update package lists
echo "Updating package lists..."
sudo apt update
# Upgrade installed packages
echo "Upgrading installed packages..."
sudo apt upgrade -y
# Remove unnecessary packages
echo "Removing unnecessary packages..."
sudo apt autoremove -y
echo "Update, upgrade, and autoremove completed."Change to the website directory:
cd /var/www/Count PHP files in a specific directory:
find /var/www/example.com/public_html/ -type f -name "*.php" | wc -lCreate the monitoring script:
nano opcache_files.shThis script will:
opcache.max_accelerated_files value in each PHP poolThe script automatically scans:
/etc/php/8.3/fpm/pool.d//var/www/public_html directoryNavigate to the PHP pool directory:
cd /etc/php/8.3/fpm/pool.d/View configuration for a specific site:
sudo cat example.com.confLook for the OPcache directive at the bottom of the file:
php_admin_value[opcache.max_accelerated_files] = 20000Change to website directory:
cd /var/www/example.com/List current permissions:
sudo ls -l public_html/Set ownership (replace PHP_POOL_USER with your actual pool user):
sudo chown -R PHP_POOL_USER:PHP_POOL_USER public_html/Set directory permissions:
sudo find /var/www/example.com/public_html/ -type d -exec chmod 770 {} \;Set file permissions:
sudo find /var/www/example.com/public_html/ -type f -exec chmod 660 {} \;After completing updates, reload PHP-FPM:
sudo systemctl reload php8.3-fpmSet restrictive directory permissions:
sudo find /var/www/example.com/public_html/ -type d -exec chmod 550 {} \;Set restrictive file permissions:
sudo find /var/www/example.com/public_html/ -type f -exec chmod 440 {} \;Allow write access for wp-content directories:
sudo find /var/www/example.com/public_html/wp-content/ -type d -exec chmod 770 {} \;Allow write access for wp-content files:
sudo find /var/www/example.com/public_html/wp-content/ -type f -exec chmod 660 {} \;Update and install ClamAV:
sudo apt updatesudo apt install clamavDisable automatic updates (for manual control):
sudo systemctl stop clamav-freshclamsudo systemctl disable clamav-freshclamManually update virus definitions:
sudo freshclamRun a manual scan:
sudo clamscan -r /path/to/scanUpdate and scan in sequence:
sudo freshclamsudo clamscan -r /path/to/scanInstall rkhunter:
sudo apt install rkhunterUpdate the properties database:
sudo rkhunter --propupdRun a full system check (skip keypress):
sudo rkhunter --checkall --skView the scan log:
sudo cat /var/log/rkhunter.logsudo less /var/log/rkhunter.logRemove automatic cron jobs (for manual control):
cd /etc/cron.daily/sudo rm rkhuntercd /etc/cron.weekly/sudo rm rkhunterView actual memory usage of InnoDB Buffer Pool:
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_bytes_data';View total database size:
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 size 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 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;
Navigate to MySQLTuner directory:
cdcd MySQLTuner/ls -lRun MySQLTuner (requires sudo):
sudo ./mysqltunerDisplay disk usage in human-readable format:
df -hRemove unused packages and clean cache:
sudo apt autoremove && sudo apt cleanClean up system logs (keep last 1 day):
sudo journalctl --vacuum-time=1daysNavigate to root directory:
cd /List directory sizes sorted by size:
du -ah --max-depth=1 | sort -hSet connection backlog for better performance:
backlog=2048HTTP listener configuration:
listen 80 backlog=2048;HTTPS listener configuration:
listen 443 ssl backlog=2048;Keep your server packages up-to-date with security patches and improvements.
Use WP-CLI for quick and easy WordPress updates.
Always maintain recent backups for disaster recovery.
Run ClamAV and rkhunter scans to detect security threats.
Run MySQLTuner to optimize database performance.
Initially: every 3 days. After 1-2 weeks: weekly.
Monitor disk usage to prevent server crashes due to full storage.
Verify PHP file counts don't exceed configured limits.
| Task | Frequency | Command/Tool |
|---|---|---|
| Package Updates | 3x per week | sudo apt update && sudo apt upgrade -y |
| WordPress Updates | 3x per week | WP-CLI / WordPress Dashboard |
| Backups | Daily | Backup solution of choice |
| Virus Scan | Weekly/Bi-weekly | sudo clamscan -r /path |
| Rootkit Scan | Weekly/Bi-weekly | sudo rkhunter --checkall --sk |
| MySQL Tuning | Every 60 days | sudo ./mysqltuner |
| PHP-FPM Tuning | Weekly (after initial setup) | Configuration adjustments |
| Disk Space Check | Weekly | df -h |
| OPcache File Count | Weekly | ./opcache_files.sh |