Tune up apache and php settings

Discussion in 'Server Operation' started by Poliman, Dec 28, 2018.

  1. Poliman

    Poliman Member

    I have Ubuntu 16.04 LTS with apache 2.4.37 (with mpm_prefork) and php provided with OS. There is also newest ISP done based on Perfect Server tutorial. I have 15GB of RAM and 4x 2,3GHz CPU. I would like to adjust settings:
    a) from /etc/apache2/mods-enabled/mpm_prefork.conf
    Code:
    <IfModule mpm_prefork_module>
            ServerLimit             400
            StartServers                     5
            MinSpareServers           5
            MaxSpareServers          10
            MaxRequestWorkers         400
            MaxConnectionsPerChild   0
    </IfModule>
    
    and also from /etc/php/7.0/fpm/pool.d/www.conf:
    Code:
    pm = dynamic
    pm.max_children = 5
    pm.start_servers = 2
    pm.min_spare_servers = 1
    pm.max_spare_servers = 3
    
    I have used this script:
    Code:
    curl -sL https://raw.githubusercontent.com/richardforth/apache2buddy/master/apache2buddy.pl | perl
    to determine values like RAM used by php-fpm and apache:
    Code:
    [ -- ] PHP-FPM Detected => Using 2390.74 MB of memory.
    [ -- ] apache2 is currently using 1293.74 MB of memory.
    [ -- ] The smallest apache process is using 10.92 MB of memory
    [ -- ] The average apache process is using 19.52 MB of memory
    [ -- ] The largest apache process is using 20.54 MB of memory
    
    I have found somewhere on the Internet that systems which have more than 4GB of RAM should have:
    StartServers 25
    MinSpareServers 25

    PS
    There are also two another valuable commands to determine ram utilization by apache:
    Code:
    ps -C apache2 -o rss | sed '1d' | awk '{x += $1}END{print "Total Memory usage: " x}'
    ps -C apache2 -o rss | sed '1d' | awk '{x += $1;y += 1}END{print "Total Memory usage (KB): " x "\nAverage memory usage (KB): "(x/y)}'
    
     
    Last edited: Dec 28, 2018

Share This Page