I’m using for most of my servers ServerPilot as the server management tool. With ServerPilot your server will be installed an optimized with Nginx and PHP-FPM. This configuration makes your server very fast.
If you host multiple WordPress websites on your VPS you need to check the RAM memory usage frequently. Even if your WP sites doesn’t have a lot of traffic, they might consume a lot of memory. One of the reason might be the dynamic PHP-FPM configuration, which is very good because each site will respond fast even after some time of inactivity. This happens because there is always at least one active task running inside the applications PHP-FPM pool. If your website becomes more active, it’s possible that a websites pool will activate (and keep) more than one tasks. At this moment your low-traffic website might consume more than 250MB of RAM memory!
NOTE, most configurations on this page are based on the settings for a VPS controlled by ServerPilot!
PHP-FPM dynamic or better ondemand?
The dynamic configuration is good for website with a decent traffic, but for smaller sites a short brute-force attack might consume all available RAM memory. The problem in that case is the PHP-FPM will reserver this higher memory amount for hours. If this is a problem on your server you use the ondemand configuration
PHP-FPM ondemand configuration for a ServerPilot controlled VPS
Start by by renaming this file (replace the php5.x with your app’s PHP version and replace your app name with APPNAME) :
Open/edit the renamed file and change the process manager configurations in that file with (this will keep/disable the old settings, just in case you like to change it later):
;pm = dynamic ;pm.start_servers = 1 ;pm.max_children = 40 ;pm.min_spare_servers = 1 ;pm.max_spare_servers = 10 pm = ondemand pm.max_children = 40 pm.process_idle_timeout = 3600s
Restart PHP-FPM now with:
service php5.x-fpm-sp restart
Disable wp_cron and use a real CRON job
I have noticed that in some situations (depends on the used WordPress themes and plugins) WordPress will execute the wp_cron.-php file very often. It’s much better to disable the wp_cron feature and to use a real CRON jog to execute that PHP file.
Open the wp-config.php file and add this row:
Add a CRON job with (replace SRVUSER with the user name which is configured with the app):
crontab -e -u SRVUSER
place this job into the file (replace also the right PHP version and the APPNAME):
*/5 * * * * php5.x-sp /srv/users/SRVUSER/apps/APPNAME/public/wp-cron.php
Disable PHP’s Opcache
The PHP Opcache is enabled by default since PHP version 5.5. If you like to save a bit of RAM memory, it’s possible to disable the Opcache feature. Note, this works the best if you use WP Super Cache in mod_rewrite mode!
To disable PHP’s Opcache, you can edit the following file(s) (replace the PHP version 5.5 or 5.6):
add the following line to the end of each of these files:
and finally restart each PHP version:
sudo service php5.x-fpm-sp restart
Don’t tweak to much at the same time, some of the modifications might work better than others. If you like to share your own tweaks, please post them as a comment.