⚡ Installation
Global
apt-get install apache2-utils
PHP-FPM
apt-get install php7.4-fpm
⚡ Calculation
(1 CPU cores, 2 GB RAM)
Process size
Size per each single process.
wget https://raw.githubusercontent.com/pixelb/ps_mem/master/ps_mem.py -O usage.py
chmod a+x usage.py
python usage.py
lscpu
top
top -c -p `pgrep apache -d','`
top -c -p `pgrep mariadb -d','`
top -c -p `pgrep php -d','`
{Process size} = {Used RAM (Item)} / {Process (Item)}
# Apache:
# 50M / 5P
# 10M
# (~ 150)
# PHP-FPM:
# 200M / 5P
# 40M
# (~ 256M)
# MySQL:
# (~ 256M)
MaxRequestWorkers
MaxRequestWorkers = ({Total RAM} - {Used RAM (Kenel, MySQL...)}) / {Process size}
# (2000 - 600) / 50M
# 28M
PHP-FPM max-children
maxclients = ({Total RAM} - {Used RAM (Kenel, MySQL...)}) / {Process size}
# (2000 - 600) / 50M
# 28M
⚡ Configuration
Global
a2enmod deflate # GZIP
a2dismod mod_ruby # Unused
a2dismod mod_perl # Unused
@ /etc/apache2/apache2.conf
Timeout 120
KeepAlive On
MaxKeepAliveRequests 500
KeepAliveTimeout 3
Cache
a2enmod cache
a2enmod cache_disk
a2enmod expires
a2enmod headers
@ /etc/apache2/sites-available/{domain}.{tld}.conf
@ /etc/apache2/sites-available/000-default.conf
<IfModule mod_disk_cache.c>
CacheQuickHandler off
CacheLock on
CacheLockPath /tmp/mod_cache-lock
CacheLockMaxAge 5
CacheIgnoreHeaders Set-Cookie
CacheEnable disk
CacheHeader on
CacheDefaultExpire 800
CacheMaxExpire 64000
CacheIgnoreNoLastMod On
ExpiresActive on
ExpiresDefault A300
</IfModule>
MPM (Multi-Processing)
a2dismod mpm_prefork
a2dismod mpm_event
a2enmod mpm_worker
@ /etc/apache2/mods-available/mpm_worker.conf
<IfModule mpm_worker_module>
StartServers 1 # {CORES}
ServerLimit 150 # {RAM}
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 150 # {RAM}
MaxConnectionsPerChild 1000
</IfModule>
PHP-FPM
a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm
@ /etc/php/7.4/fpm/pool.d/www.conf
pm = dynamic
pm.max_children 256 # ({Total RAM} - {Used RAM (Kenel, MySQL...)}) / {Process size}
pm.start_servers 4 # ({CORES} * 4)
pm.min_spare_servers 2 # ({CORES} * 2)
pm.max_spare_servers 4 # ({CORES} * 4)
pm.max_requests 1000
Restart
service apache2 restart
service php7.4-fpm restart
systemctl start apache-htcacheclean
Test
PHP-FPM
php-fpm7.4 -t
Cache
ls -la /var/cache/apache2/mod_cache_disk/
ApacheBench
ab -n 1000 -c 100 -k -H "Accept-Encoding: gzip, deflate" [http[s]://]hostname[:port]/path
Authors:
- Jihad Sinnaour - Jakiboy (Initial work)
⭐ Support:
Please give it a Star if you like the project.
Top comments (0)