Installing LAMP-Memcached on AWS EC2 Linux
I recently got into a situation where I had to restore a crashed Amazon EC2 instance. One of the most taxing problems was that the server used Memcached, along with LAMP. While there are plenty of websites which tell you how to install LAMP, I found little help regarding Memcached. What made things a bit worse was that there are different flavors of Linux, each having different ways of installing software packages. And there are different versions of Apache, MySQL (or MariaDB) and PHP.
The guy who had configured the server initially, did not keep any documentation nor did he keep a backup of the server (and that guy actually was me (:|) ). Very intelligent!
So anyway, after 2 days of tireless efforts, I finally got the server up and running. And I've now adopted a habit of taking regular backups and stuff (which I'll discuss in another post later).
So in the interest of others (and myself) who are facing or may face this scenarios, I am documenting the steps below as to how do I install this LAMP-M combo on AWS EC2 Linux.
A. Prerequisites:
- You to know how to configure EC2
- You to know how to operate Linux remotely (using shell or putty) and,
- You also have Admin rights to the EC2 instance
B. The Steps:
(i) Installation
sudo yum update -y
sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd
sudo service httpd start
sudo yum install -y php-memcached
sudo service httpd restart
sudo chkconfig httpd on
sudo chkconfig mysqld on
sudo chkconfig memcached on
Note: You should install the mysql55-server on another instance of EC2, or create one of the RDS instance for Production servers. You must always separate Database server and application server.
Explanation
You first update all existing package to the latest version. Then you download and install Apache (httpd24), PHP (php56), MySQL (mysql55-server) and the bridge (php56-mysqlnd) packages through YUM.
Then you need to install the Memcached (php-memcached) package and start the Apache server.
In the last 3 steps, you configure the daemons to start automatically when your instance boots up.
(ii) Configuration
Now, since everything we have done till now was done as an Admin (using sudo), the main user of the instance doesn't actually have rights to create files/folders in the Apache's root folder(/var/www). So we need to assign the rights to ec2-user, who will be the main user normally to access these files. To do this, we go as follows:sudo groupadd www
sudo usermod -a -G www ec2-user
exit
Then relaunch Putty or Shell and enter the following to see if the group "www" is listed in there:
groups
If the group is there, do the following:
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 {} +
sudo service mysqld start
sudo chkconfig mysqld on
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
This will create a php file named "phpinfo.php" in the root www directory. You can open the link by entering the public IP address of the instance (should be something like this: 123.123.123.123/phpinfo.php ) on your browser and verify if Memcached and MySQL (along with PHP and Apache) are working properly.
If everything is working properly, you can then login to your MySQL console:
mysql -u root
On the mysql console, you can configure your database and (More importantly) setup the root password.
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
I guess that should get you up and running. If you think anything else should be added, just drop in a comment and I'll modify/update accordingly (with due credit as well :).
Comments