OPcache Max Accelerated Files

Server Administration & WordPress Optimization Guide

📋 Understanding OPcache Max Accelerated Files

What is OPcache Max Accelerated Files?

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.

Key Concept: Prime Number Rounding

⚠️ Important: When you configure OPcache, the actual value used is automatically rounded up to the nearest prime number from a predefined list.
Predefined Prime Numbers:
223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987, 262237, 524524, 1048793

Configuration Example

Set Value: 20,000
⬇️
Automatic Rounding
⬇️
Actual Value: 32,531
🔴 Critical Rule: The total number of PHP files in your WordPress sites must ALWAYS be less than the value you set for the opcache.max_accelerated_files directive.

🔧 Server Update Tasks

Method 1: Manual Commands

Run these commands individually:

sudo apt update
sudo apt upgrade
sudo apt autoremove

Method 2: Chained Commands

Combine all commands in one line:

sudo apt update && sudo apt upgrade && sudo apt autoremove

Method 3: Automatic Yes Flag

Skip confirmation prompts with the -y flag:

sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y

Method 4: Creating a Bash Alias

Navigate to home directory and edit bash aliases:

cd
nano .bash_aliases

Add 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:

exit

Method 5: Bash Script

Create the script file:

sudo nano server_updates.sh

Script 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."

🔍 Checking PHP File Count

Manual Method

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 -l

Automated Method: Bash Script

Create the monitoring script:

nano opcache_files.sh

This script will:

The script automatically scans:

Example Output Interpretation

Site: example.com
⬇️
PHP Files Found: 1,432
⬇️
Configured Value: 20,000
⬇️
Actual Value: 32,531
⬇️
✓ Status: Safe (1,432 < 32,531)

Checking Pool Configuration

Navigate to the PHP pool directory:

cd /etc/php/8.3/fpm/pool.d/

View configuration for a specific site:

sudo cat example.com.conf

Look for the OPcache directive at the bottom of the file:

php_admin_value[opcache.max_accelerated_files] = 20000

🔄 WordPress Update Procedures

Standard Permissions for Updates

Change 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-fpm

Hardened Permissions (After Updates)

Set 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 Workflow

1. Set Standard Permissions (770/660)
⬇️
2. Run WordPress Updates
⬇️
3. Apply Hardened Permissions (550/440)
⬇️
4. Reload PHP-FPM

🛡️ Security Scanning

ClamAV Installation and Configuration

Update and install ClamAV:

sudo apt update
sudo apt install clamav
Note: The ClamAV definition database will be updated automatically after installation.

Disable automatic updates (for manual control):

sudo systemctl stop clamav-freshclam
sudo systemctl disable clamav-freshclam

Manually update virus definitions:

sudo freshclam

Run a manual scan:

sudo clamscan -r /path/to/scan

Update and scan in sequence:

sudo freshclam
sudo clamscan -r /path/to/scan

Rootkit Hunter (rkhunter)

Install rkhunter:

sudo apt install rkhunter

Update the properties database:

sudo rkhunter --propupd

Run a full system check (skip keypress):

sudo rkhunter --checkall --sk

View the scan log:

sudo cat /var/log/rkhunter.log
sudo less /var/log/rkhunter.log

Remove automatic cron jobs (for manual control):

cd /etc/cron.daily/
sudo rm rkhunter
cd /etc/cron.weekly/
sudo rm rkhunter

💾 Database Performance Tuning

InnoDB Buffer Pool Analysis

View 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;

MySQLTuner

Navigate to MySQLTuner directory:

cd
cd MySQLTuner/
ls -l

Run MySQLTuner (requires sudo):

sudo ./mysqltuner

💿 Disk Space Management

Check Disk Space

Display disk usage in human-readable format:

df -h

Cleanup Operations

Remove unused packages and clean cache:

sudo apt autoremove && sudo apt clean

Clean up system logs (keep last 1 day):

sudo journalctl --vacuum-time=1days

Analyze Directory Sizes

Navigate to root directory:

cd /

List directory sizes sorted by size:

du -ah --max-depth=1 | sort -h
Tip: The largest directories are displayed at the bottom. You can navigate to any directory and run the same command to analyze subdirectories.

⚙️ NGINX Configuration

Backlog Configuration

Set connection backlog for better performance:

backlog=2048

HTTP listener configuration:

listen 80 backlog=2048;

HTTPS listener configuration:

listen 443 ssl backlog=2048;

📅 Server Administration Task Schedule

Recommended Maintenance Schedule

✓ Server Package Updates 3x per week

Keep your server packages up-to-date with security patches and improvements.

✓ WordPress Core, Theme & Plugin Updates 3x per week

Use WP-CLI for quick and easy WordPress updates.

✓ Site Backups Daily

Always maintain recent backups for disaster recovery.

✓ Virus & Malware Scans Weekly or Bi-weekly

Run ClamAV and rkhunter scans to detect security threats.

✓ MySQL Performance Tuning Every 60 days

Run MySQLTuner to optimize database performance.

✓ PHP-FPM Tuning Variable

Initially: every 3 days. After 1-2 weeks: weekly.

✓ Disk Space Check Weekly

Monitor disk usage to prevent server crashes due to full storage.

✓ OPcache Max Accelerated Files Check Weekly

Verify PHP file counts don't exceed configured limits.

⏱️ Time Investment: The above maintenance tasks should take no more than a few minutes per week once you have established your routine and automation scripts.

📊 Quick Reference Table

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

🎯 Best Practices Summary

🔐 Security Reminder: Always use hardened permissions (550/440) when not performing updates. Only temporarily relax permissions (770/660) during the update process, and re-harden immediately afterward.