Install Apache, PHP, APC, & MySQL on Amazon EC2 with Amazon Linux AMI

The following guide is a step by step guide on installing and configuring Apache, PHP (with APC) & MySQL (LAMP Stack) on an Amazon EC2 instance running Amazon Linux AMI.The procedure has been tested on Amazon Linux AMI

1. Install Linux updates, set time zones, followed by GCC and Make

sudo yum -y update
sudo ln -sf /usr/share/zoneinfo/America/Indianapolis \
sudo yum install -y gcc make


2. Install PHP and PHP extensions

sudo yum install -y php
sudo yum install -y php-devel php-mysql php-pdo
sudo yum install -y php-pear php-mbstring
sudo pear install Log
sudo yum install -y pcre-devel


3. Install Apache httpd

sudo yum -y install httpd
sudo service httpd start


4. Install MySQL

sudo yum -y install mysql-server mysql
sudo service mysqld start


5. Install PHP APC module

sudo yum -y install httpd-devel
sudo pecl install apc-beta
echo "" | sudo tee /etc/php.d/apc.ini
Or Simply:
sudo yum install -y php-pecl-apc


6. MySQL Configuration

sudo vi /etc/my.cnf
server-id= 1
key_buffer_size = 128M
max_allowed_packet = 3M
table_open_cache = 64
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 16M
thread_cache_size = 8
query_cache_size= 32M
thread_concurrency = 8
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_additional_mem_pool_size = 8M
innodb_log_buffer_size = 4M
Log Slow Queries:
sudo touch /var/log/log-slow-queries.log
sudo chown mysql.mysql /var/log/log-slow-queries.log
sudo /sbin/chkconfig --levels 235 mysqld on
sudo service mysqld start


7. PHP Configuration Changes in php.ini

sudo nano /etc/php.ini
expose_php = Off
memory_limit = 128M
date.timezone = America/Indianapolis
Note: Location of error file


8. Auto Start Apache in EC2 Amazon Linux

sudo /sbin/chkconfig --levels 235 httpd on
sudo service httpd start

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.