MySQL and Apache Optimization Guide

From LinodeWiki

Jump to: navigation, search

Please see the article in the Linode Library on Troubleshooting Memory and Networking Issues for more information and additional resources.

[edit] Tuning MySQL

Lets first tune MySQL to use less memory for cache.

Open up your MySQL config:

    nano /etc/mysql/my.cnf

Below is an example of what you should put in /etc/mysql/my.cnf. Make sure these settings are set in your default file:

    [mysqld]
    port = 3306
    socket = /var/lib/mysql/mysql.sock
    skip-locking
    set-variable = key_buffer=16K
    set-variable = max_allowed_packet=1M
    set-variable = thread_stack=64K
    set-variable = table_cache=4
    set-variable = sort_buffer=64K
    set-variable = net_buffer_length=2K

MySQL uses 10MBs of RAM for InnoDB tables. Remove support for InnoDB tables if you do not use them. To remove support for InnoDB, uncomment the line (remove #)

    [mysqld]
    skip-innodb


[edit] Tuning Apache/PHP

Now lets tune Apache to only have a small number of spare children running. First open your apache2.conf:

    nano /etc/apache2/apache2.conf

Now make sure to modify or adjust these settings (case sensitive):

    StartServers 1
    MinSpareServers 1
    MaxSpareServers 5
    ServerLimit 64
    MaxClients 64
    MaxRequestsPerChild 4000

Also, only load the modules you require. If you do do not use PHP, mod_perl, etc then do not install them.

THATS it tuned and ready to go!

Sources: Router Mods I am the writer.

Personal tools