LAMP with php 5.4 and Apache 2.4

Published on Author adventurerLeave a comment

After having a few issues with my t1.micro instance running out of memory and causing the hosted sites to become unavailable, I looked in to the reasons why. According to this post and this post a key culprit is the use of the somewhat outdated PHP 5.3, and upgrading to PHP 5.4 significantly reduces memory usage. Unfortunately even the latest Amazon Linux AMI (2015.03) only installs PHP 5.3 and Apache 2.2 by default, and this is what you will get if you follow the tutorials in the EC2 documentation. This post describes how to build an EC2 LAMP and WordPress server which uses PHP 5.4 and Apache 2.4.

After launching your new EC2 instance update  all the installed packages:

sudo yum -y update

Then install the specific packages for PHP 5.4 and Apache 2.4:

sudo yum install httpd54 php54

And install the MySQL database packages:

sudo groupinstall "MySQL Database"

And install the PHP 5.4 specific packages for MySQL

sudo yum install php54-mysql

And start Apache 2.4 server

sudo service httpd start

Set the server so that Apache 2.4 always starts on boot

sudo chkconfig httpd on

Create a group for the Apache server to run as and set file permissions on the webroot (as per the LAMP tutorial in the EC2 user guide):

sudo groupadd www
sudo usermod -a -G www ec2-user
sudo chown -R root:www /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} +
find /var/www -type f -exec sudo chmod 0664 {} +


Leave a Reply

Your email address will not be published. Required fields are marked *