Below are ideal PHP settings for WordPress in production, focused on performance, stability, and security, used on medium to high traffic websites.
🔧 Recommended version
- PHP 8.2 or 8.3
- Improved performance
- Compatible with current WordPress versions
- Avoid PHP 7.4 (EOL)
📁 php.ini – Recommended configuration
; Memória memory_limit = 512M ; Uploads upload_max_filesize = 64M post_max_size = 64M max_file_uploads = 20 ; Execução max_execution_time = 300 max_input_time = 300 max_input_vars = 5000 ; Timezone date.timezone = America/Sao_Paulo ; Erros (produção) display_errors = Off display_startup_errors = Off log_errors = On error_log = /var/log/php_errors.log ; Segurança expose_php = Off allow_url_fopen = On allow_url_include = Off disable_functions = exec,passthru,shell_exec,system,proc_open,popen ; OPcache (MUITO IMPORTANTE) opcache.enable=1 opcache.memory_consumption=256 opcache.interned_strings_buffer=16 opcache.max_accelerated_files=100000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=0 ; Sessões session.gc_probability=1 session.gc_divisor=1000 session.gc_maxlifetime=1440
⚙️ PHP-FPM – Ajustes críticos
File, local example:/etc/php/8.2/fpm/pool.d/www.conf
pm = dynamic pm.max_children = 40 pm.start_servers = 10 pm.min_spare_servers = 10 pm.max_spare_servers = 20 pm.max_requests = 500 request_terminate_timeout = 300
📌 How to calculate pm.max_children
See in: PHP-FPM: How to Calculate pm.max_children Correctly
🚀 OPcache – direct impact on speed
Check if it’s active:
php -i | grep opcache
Para WordPress de alto tráfego:
memory_consumption: 256 MB max_accelerated_files: 100000
🧠 WordPress – adjustments to wp-config.php
define('WP_MEMORY_LIMIT', '512M');
define('WP_MAX_MEMORY_LIMIT', '512M');
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
🔐 Additional security
If you don’t use remote functions:
allow_url_fopen = Off
Block XML-RPC in Nginx/Apache if you don’t use it.
📊 To WooCommerce
Increase:
memory_limit = 1024M max_input_vars = 10000
🧪 Load test
After applying:
sudo systemctl restart php8.2-fpm
Monitor:
htop journalctl -u php8.2-fpm
🔥 Resumo rápido (produção)
| Item | Valor |
|---|---|
| PHP | 8.2 / 8.3 |
| memory_limit | 512M |
| OPcache | Active (256M) |
| pm.max_children | Based on RAM. See: PHP-FPM: How to Calculate pm.max_children Correctly |
| display_errors | Off |
