Apache2 / MySQL optimization

If you are experiencing slowdowns on one of your sites hosted on your private server, it is likely that your Apache or MySQL is not optimized for your server.

However, we can do this intervention for your Apache or MySQL service on our side within the framework of outsourcing.

Access the APACHE configuration file

First of all, you need to connect to your server by SSH.

Then, depending on the version of Linux you have, you need to access the Apache configuration file thus:

if it is a debian 5/6/ the apache modification is to be done in :

  • etc/apache2/httpd.conf
    followed by /etc/init.d/apache2 restart after the changes are made.

if it is a debian 7 the apache modification is to be done in :

  • etc/apache2/conf.d/tuning-nuxit.conf
    followed by /etc/init.d/apache2 restart after the changes are made.

if it is a debian 8 the apache modification is to be done in :

  • etc/apache2/conf-available/tuning-nuxit.conf
    followed by a2enconf tuning-nuxit and then by systemctl restart apache2.service after the changes are made.

Access the MySQL configuration file

the modification in mysql is done in the :

  • /etc/mysql/conf.d/tuning-nuxit.cnf
    then /etc/init.d/mysql restart once the modifications are done.

Modification to be made

Depending on the type of server you have, here are the configuration changes you need to make for Apache or MySQL :

VPS 2G

  • Apache: If you use the prefork module 
    <IfModule mpm_prefork_module>
    ServerLimit 256
    StartServers 5
    MinSpareServers 5
    MaxSpareServers 30
    MaxClients 35
    MaxRequestsPerChild 250
    </IfModule>
    If you use the event module
    <IfModule mpm_event_module>
    ServerLimit 6
    StartServers 2
    MaxRequestWorkers 120
    MaxConnectionsPerChild 2000
    ThreadsPerChild 20
    ThreadLimit 64
    </IfModule>
  • MySQL: 
    [mysqld]
    query_cache_type = 1
    query_cache_size = 32M
    join_buffer_size = 8M
    tmp_table_size = 32M
    max_heap_table_size = 32M
    innodb_file_per_table = 1
    innodb_log_buffer_size = 64M
    innodb_log_file_size = 256M
    innodb_buffer_pool_size = 64M
    table_open_cache = 1024
    open_files_limit = 100000
    max_connections = 100

VPS 4G

  • Apache: If you use the prefork module 
    <IfModule mpm_prefork_module>
    ServerLimit 256
    StartServers 10
    MinSpareServers 10
    MaxSpareServers 50
    MaxClients 80
    MaxRequestsPerChild 250
    </IfModule>
    If you use the event module
    <IfModule mpm_event_module>
    ServerLimit 10
    StartServers 2
    MaxRequestWorkers 200
    MaxConnectionsPerChild 2000
    ThreadsPerChild 20
    ThreadLimit 64
    </IfModule>
  • MySQL: 
    [mysqld]
    query_cache_type = 1
    query_cache_size = 64M
    join_buffer_size = 16M
    tmp_table_size = 64M
    max_heap_table_size = 64M
    innodb_file_per_table = 1
    innodb_log_buffer_size = 128M
    innodb_log_file_size = 256M
    innodb_buffer_pool_size = 128M
    table_open_cache = 1024
    open_files_limit = 100000
    max_connections = 120

VPS 8G

  • Apache: If you use the prefork module
    <IfModule mpm_prefork_module>
    ServerLimit 256
    StartServers 25
    MinSpareServers 25
    MaxSpareServers 70
    MaxClients 150
    MaxRequestsPerChild 250
    </IfModule>
    If you use the event module
    <IfModule mpm_event_module>
    ServerLimit 10
    StartServers 2
    MaxRequestWorkers 200
    MaxConnectionsPerChild 2000
    ThreadsPerChild 20
    ThreadLimit 64
    </IfModule>
  • MySQL: 
    [mysqld]
    query_cache_type = 1
    query_cache_size = 256M
    join_buffer_size = 16M
    tmp_table_size = 256M
    max_heap_table_size = 256M
    innodb_file_per_table = 1
    innodb_log_buffer_size = 512M
    innodb_log_file_size = 256M
    innodb_buffer_pool_size = 512M
    table_open_cache = 1024
    open_files_limit = 100000
    max_connections = 120

VPS 16G

  • Apache: If you use the prefork module 
    <IfModule mpm_prefork_module>
    ServerLimit 512
    StartServers 80
    MinSpareServers 80
    MaxSpareServers 200
    MaxClients 400
    MaxRequestsPerChild 450
    </IfModule>
    If you use the event module
    <IfModule mpm_event_module>
    ServerLimit 16
    StartServers 2
    MaxRequestWorkers 400
    MaxConnectionsPerChild 2000
    ThreadsPerChild 25
    ThreadLimit 64
    </IfModule>
  • MySQL: 
    [mysqld]
    query_cache_type = 1
    query_cache_size = 512M
    join_buffer_size = 32M
    tmp_table_size = 512M
    max_heap_table_size = 512M
    innodb_file_per_table = 1
    innodb_log_buffer_size = 1G
    innodb_log_file_size = 256M
    innodb_buffer_pool_size = 1G
    table_open_cache = 1024
    open_files_limit = 100000
    max_connections = 120

VPS 24G

  • Apache: If you use the prefork module
    <IfModule mpm_prefork_module>
    ServerLimit 512
    StartServers 100
    MinSpareServers 100
    MaxSpareServers 300
    MaxClients 512
    MaxRequestsPerChild 500
    </IfModule>
    If you use the event module
    <IfModule mpm_event_module>
    ServerLimit 20
    StartServers 2
    MaxRequestWorkers 500
    MaxConnectionsPerChild 2000
    ThreadsPerChild 25
    ThreadLimit 6
    </IfModule>
  • MySQL: 
    [mysqld]
    conf:
    query_cache_type = 1
    query_cache_size = 512M
    join_buffer_size = 32M
    tmp_table_size = 1G
    max_heap_table_size = 512M
    innodb_file_per_table = 1
    innodb_log_buffer_size = 1G
    innodb_log_file_size = 256M
    innodb_buffer_pool_size = 1G
    table_open_cache = 1024
    open_files_limit = 100000
    max_connections = 170
Updated on 12 June 2020

Was this article helpful?

Related Articles

Leave a Comment