Small Memory

The purpose of this document is to explain how to make a small-memory instance of httpd (say, for running on Amazon). This generated 134M used on a Micro for a small Wordpress Blog.

Part 1: With Apache 2.4

1. Get httpd 2.4.x and php-fpm

yum -y remove httpd httpd-tools yum -y install httpd24 php php-fpm php54 ph54-fpm

2. Configure httpd 2.4.x

rm /etc/httpd/conf.d/welcome.conf vim /etc/httpd/conf/httpd.conf *** DirectoryIndex index.php Listen 10.0.0.202:80 <VirtualHost 10.0.0.202:80> ServerAdmin hostmaster@jgspratt.com ServerName blog.jgspratt.com ServerAlias blog.jgspratt.com DocumentRoot /mnt/blog/html ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/mnt/blog/html/$1 <Directory "/mnt/blog/html"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Require all granted </Directory> </VirtualHost> LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so KeepAlive On MaxKeepAliveRequests 32 KeepAliveTimeout 2 *** vim /etc/httpd/conf.modules.d/00-mpm.conf *** LoadModule mpm_event_module modules/mod_mpm_event.so <IfModule event.c> ServerLimit 5 MaxClients 32 StartServers 2 ThreadsPerChild 16 ThreadLimit 16 MinSpareThreads 8 # must be >= (MinSpareThreads + ThreadsPerChild) MaxSpareThreads 32 MaxRequestsPerChild 32 </IfModule> *** vim /etc/php-fpm.d/www.conf *** [www] listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 user = apache group = apache pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 2 pm.max_spare_servers = 2 pm.max_requests = 32 slowlog = /var/log/php-fpm/www-slow.log php_admin_value[error_log] = /var/log/php-fpm/www-error.log php_admin_flag[log_errors] = on ***

3. Configure mysqld

vim /etc/my.cnf [mysqld] datadir = /var/lib/mysql socket = /var/lib/mysql/mysql.sock symbolic-links = 0 ignore-builtin-innodb default-storage-engine = myisam thread-concurrency = 0 # let MySQL pick key_buffer = 1M max_allowed_packet = 1M table_cache = 30 query_cache_limit = 256K query_cache_size = 4M [mysqld_safe] log-error = /var/mysql/mysql-server/mysqld.log pid-file = /var/mysql/mysql-server/mysqld.pid

4. Here's another config from a blag

[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mysqld according to the # instructions in http://fedoraproject.org/wiki/Systemd default-storage-engine = innodb thread-concurrency = 0 # let MySQL pick # MEMORY key_buffer = 1M max_allowed_packet = 1M query_cache_limit = 256K query_cache_size = 4M [mysqld_safe] log-error = /var/mysql/mysql-server/mysqld.log pid-file = /var/mysql/mysql-server/mysqld.pid

Part 2: With Apache 2.2

Sadly, you can only configure the httpd.conf, MySQL, and PHP, to really help here.

KeepAlive On MaxKeepAliveRequests 32 KeepAliveTimeout 2 <IfModule prefork.c> StartServers 2 MinSpareServers 2 MaxSpareServers 8 ServerLimit 64 MaxClients 32 MaxRequestsPerChild 400 </IfModule> <IfModule worker.c> StartServers 2 MaxClients 32 MinSpareThreads 8 MaxSpareThreads 16 ThreadsPerChild 8 MaxRequestsPerChild 400 </IfModule>

[Edit]