With the VPS expansion you can now get a (very) small virtual private server (VPS) for a very affordable price. However, when you get a server with something like 256MB or 512MB RAM and a portion of CPU power, using default LEMP settings is a pretty bad idea.
Performance and scalability tuning of a server is more of an art than science, in the sense that there’re no ready-to-use formulas. Optimal server settings depend on many unique factors: web-app code, traffic to the site, site’s information architecture among other things. It’s virtually impossible to really optimize server settings without thorough understanding of the web application and a lot of testing.
Prerequisites
Before you begin this guide, there are some important steps that you need to complete on your server.
You’ll need to have a LEMP (Linux, Nginx, MariaDB, and PHP) stack installed on your VPS instance. If you don’t have these components already installed and configured, you can use this guide to learn how to install LEMP.
When you are finished with these steps, you can continue with this guide.
Following are some variables for various settings files that have been modified from their default values.
Tuning PHP
Edit the file /etc/php.ini
and change the this
1 2 3 |
post_max_size = 10M upload_max_filesize = 10M max_file_uploads = 20 |
Object Cache
An object cache stores potentially computationally expensive data such as database query results and serves them from memory. This greatly improves the performance of WordPress as there is no longer a need to query the database on every page load for information already stored within the object cache.
Redis is the latest and greatest when it comes to object caching. However, popular alternatives include Memcache and Memcached.
To install Redis, issue the following commands.
1 |
yum --enablerepo=remi,remi-test,remi-php56 install redis php-pecl-redis |
It’s also a good idea to set a maximum memory usage. As I’m only using a 512Mb server, I set mine to 64mb.
1 |
vi /etc/redis.conf |
Uncomment the line # maxmemory
and set the desired value.
1 |
maxmemory 64mb |
Save the configuration and restart both Redis and PHP-FPM.
1 |
/etc/init.d/redis restart && /etc/init.d/php-fpm restart |
Enable Redis service to start on boot:
1 |
chkconfig redis on |
verify that redis is running and working as expected
1 2 |
# netstat -nlp | grep "redis" tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 9457/redis-server 1 |
OR
1 2 |
# redis-cli ping PONG |
Tuning PHP-FM
Edit file /etc/php-fpm.d/www.conf
and change the this
1 2 3 4 |
pm = ondemand pm.max_children = 75 pm.process_idle_timeout = 10s; pm.max_requests = 500 |
Save the configuration and restart PHP-FPM.
1 |
/etc/init.d/php-fpm restart |
to be continues …
zzzzzzzzzzzzzzzzzz