Enable swap file on Amazon EC2 instance

This was done on a t2.medium instance with 4GB of RAM and a 50GiB EBS volume. The primary reason was to give the webserver a bit of leeway during high traffic periods. Stops it running out of memory and falling over.

Most of this is taken from the Amazon docs.

# Create a 6GB swap file
sudo dd if=/dev/zero of=/swapfile bs=1G count=6

#Update the permissions
sudo chmod 600 /swapfile

#Set up the swap
sudo mkswap /swapfile

#Make the swap available
sudo swapon /swapfile

#Enable swap at boot
sudo nano /etc/fstab

#Add this line at the bottom
/swapfile swap swap defaults 0 0

Hide website listing in Amazon EC2 AMI

By default Amazon’s AMI allows directory listings for your website. In WordPress this exposes you /wp-content/uploads folder to the web. Not a big deal but could be a security risk if you upload anything sensitive to your site for some reason. You need to change the default httpd.conf file:

sudo nano /etc/httpd/conf/httpd.conf

Change the following line:

Options Indexes FollowSymLinks

to

Options FollowSymLinks

as shown below (I’ve left the original line commented out)

# Further relax access to the default document root:
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
#Options Indexes FollowSymLinks
Options FollowSymLinks

Restart your webserver:

sudo service httpd restart