In this tutorial I will walk you through on how to tune your Wordpress running on AWS t2.micro. An EC2 instance with a t2.micro is part of the amazon Free Tier which includes services with a free tier for 12 months from the date you've signup on AWS by creating your account. Those Free Tier services can be used within certain usage limits without your credit card being charged. This makes the t2.micro a good choice for a simple Wordpress blog.
After creating my Wordpress blog on AWS t2.micro instance, I started running into some issues. Sometime, I have to restart my running services and mysql service was sometime stopped for some reasons. After some investigations, I figured out that it was some low memory issues since the t2.micro only provides approximately 1 GB of memory. On top of not having too much memory, the t2.micro does not have the swap partition. The investigation has shown that 90% of the memory was constantly in use which is obviously not good.
All the apache tweaking will be done in the apache httpd.conf which is the main configuration file located under /etc/httpd/conf/httpd.conf . The following setting values or called directives will be changed.
The following tweaking is where the magic really happen, we will tell apache to generate a limited number of processes.
See below the configuration for all those directives mentioned above. And add or modify this in your httpd.conf file under /etc/httpd/conf/httpd.conf.
Timeout 30
KeepAlive On
MaxKeepAliveRequests 50
KeepAliveTimeout 10
<IfModule prefork.c>
StartServers 3
MinSpareServers 2
MaxSpareServers 5
MaxClients 10
MaxRequestsPerChild 1000
</IfModule>
And now restart your httpd service $ sudo systemctl restart httpd
For a small WordPress blog just use the small and simple my.cnf configuration file shipped with the MariaDB RPM because in this specific case, my blog doesn't really require to perform extensive analysis.
$ sudo mv /etc/my.cnf /etct/my.cnf.backup
$ sudo cp /usr/share/mysql/my-small.cnf /etc/my.cnf
Add or modify bind-address=127.0.0.1 in the [mysqld] section which will limit the connections to the localhost address. And now restart MariaDB $ sudo systemctl restart mariadb
Swapping can lead the system to run extremely slow but nevertheless, it is still much more better than a panic and a system reboot only caused by the database error [ERROR] mysqld: Out of memory
$ sudo dd if=/dev/zero of=/swap bs=`expr 1024 \* 1024` count=1024
$ sudo mkswap /swap
$ sudo swapon /swap
$ echo “/swap none swap sw 0 0” >> /etc/fstab
Since you are running your WordPress on AWS infrastructure, use the AWS RDS to load off your initial server which will be running mainly apache.