This article describes, step by step, the process of setting up a LAMP stack(Linux Apache MySQL PHP) on Amazon’s cloud platform – Amazon Web Services (AWS). Once the stack is setup, it can be used to host any PHP – MySQL application/framework, such as WordPress, Drupal, Joomla, etc.
The article assumes that you have already set up an EC2 instance using the free tier Amazon Linux AMI. It is also assumed, you have already assigned an Elastic IP to your instance. The steps listed below need to be performed using a terminal / SSH client, such as PUTTY.
Step 1: Login to your EC2 instance using putty. Enter the following command to gain root access to the system.
sudo su
Step 2: Next step is to setup the webserver. Enter the following commands one after the other, confirming with Y every time you are prompted.
yum install httpd yum install phpphp-mysql yum install mysql-server
Step 3: Start the Apache and MySQL services.
service httpd start service mysqld start
At this stage, you can navigate to the Elastic IP assigned to your EC2 instance. If you see the default Apache page, the web server is setup correctly.
Step 4: Configure both Apache and MySQL to auto start on boot.
chkconfighttpd on chkconfigmysqld on
This ensure that in the rare case that you need to shut down and restart the EC2 instance, the services come back on automatically.
Step 5: Install and configure phpMyAdmin
yum –enablerepo=epel install phpmyadmin ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
Step 6: Configure phpMyAdmin to be accessible from the Elastic IP. For this we need to edit the phpMyAdmin.conf file. Open the file using any text editor – I have used nano.
nano /etc/httpd/conf.d/phpMyAdmin.conf
Step 7: Make changes as mentioned below –
# Apache 2.2 Order Allow,Deny Deny from All 2.2 Allow from 127.0.0.1 Allow from ::1
To
# Apache 2.2 Order Allow,Deny Allow from All 2.2
Save the file overwriting the changes made.
Step 8: Restart the apache service.
service httpd restart
Step 9: By default, MySQL does not assign a password to the root account. Change this by running the command as follows –
mysql_secure_installation
This will present a series of settings that can be configured. Accept all the recommendations and set a new password for the root account.
Step 10: In order to upload files, we will need to change permissions to our web root folder. Use the following commands to do the same –
chown -R ec2-user /var/www/html
The above command grants access to web root for uploading files via a secure FTP client such as WinSCP.
chown -R apache:apache /var/www/html
The above command lock down access the web server user, once the files have been uploaded.