For small websites or not so popular WordPress blogs a small VPS with only 256MB of RAM should be enough. If you’ve followed this guide to install a Ubuntu web server you need to optimize your server a little bit.
Start installing MySQLtuner
Download the Perl script to your (admin) home directory:
Create also a file
nano .my.cnf and add this code:
[client] user=someusername pass=thatuserspassword
After running MySQLtuner script
perl mysqltuner.pl you should get this warning:
Reduce your overall MySQL memory footprint for system stability
To resolve this an other memory related issues we need to optimize the MySQL database settings.
Open your MySQL settings file using (don’t forget to backup your settings):
sudo nano /etc/mysql/my.cnf
Add the following line into the section [mysqld]:
Next locate the line
skip-external-locking and add
skip-locking below that line.
Now find the section labeled “Fine Tuning”. Change/add the settings in that section to match those below:
key_buffer = 16K max_allowed_packet = 1M thread_stack = 64K thread_cache_size = 4 sort_buffer = 64K net_buffer_length = 2K
Save the file (ctrl+x) and restart MySQL:
sudo /etc/init.d/mysql restart
If you run MySQLtuner again you will see that the “memory” warning is gone, ignore the aother warnings for the moment (you need to run the script after a few days again to get exact test results)
Optimize Apache in prefork mode
If you followed the Ubuntu tutorial we’ve mentioned in the first paragraph, your Apache setup should run in prefork mode. The default settings are much to high, open the file
sudo nano /etc/apache2/apache2.conf andchange the following settings:
Timeout 45 KeepAlive On MaxKeepAliveRequests 200 KeepAliveTimeout 3
StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 30 MaxRequestsPerChild 2000
That’s all, restart Apache using
sudo /etc/init.d/apache2 restart. If you know more tweaks, please share.