Sunday, May 20, 2012

LAMP Server on Amazon EC2

This article shows how to build a LAMP on Amazon Cloud.

I assume that you already have an Amazon EC2 account and Amazon Linux AMI is launched. After you launched your image you can connect to it via ssh and get access to your machine shell to run your commands.

List below shows the steps to build Apache, PHP, MySQL on your Linux:

sudo yum update
sudo yum install httpd
sudo yum install mod_ssl
sudo yum install mysql
sudo yum install mysql-server
sudo yum install php
sudo yum install php-mysql

After you installed them you need to start all the services like below:

sudo /etc/rc.d/init.d/mysqld start
sudo /etc/rc.d/init.d/httpd  start

If you reboot the system you have to restart them or you can do something like below:

sudo rm /etc/rc.d/rc3.d/K15httpd
sudo rm /etc/rc.d/rc3.d/K36mysqld
sudo ln -s ../init.d/mysqld /etc/rc.d/rc3.d/S30mysql
sudo ln -s ../init.d/httpd /etc/rc.d/rc3.d/S85httpd

You can find config files for services as needed :

sudo mcedit /etc/httpd/conf/httpd.conf
sudo mcedit /etc/my.cnf
sudo mcedit /etc/php.ini

There are some useful additional packages :

sudo yum install mysql-devel -> For Sphinx Search Engine
sudo yum install php-bcmath  -> For some PHP function like bcadd  
sudo yum install php-xml     -> For XML support in PHP      
sudo yum install mlocate gcc gcc-c++ autoconf automake 
sudo yum install mc            -> mcedit command        
sudo yum install poppler-utils -> pdftotext

After installation, you need to add HTTP or HTTPS to your instance security group from your AWS Cosole  to be accessible via web. Also you can assign your Elastic IP to any domain.

At the end I like to mention some useful commands for Linux shell :

Connect to MySQL:
mysql -p --password='yourMySQLPassword' -u dbUser;

Secure MySQL for the first time after installation:
sudo /usr/bin/mysql_secure_installation

Backup you MySQL Database into a file:
mysqldump -p --password=' yourMySQLPassword ' -u dbUser dbName > fileName.sql 

Move Files between servers:
scp -v -i yourInstanceKeyPair.pem fileToBeTransferd 
ec2-user@YourPublicDNSFromAwsConsole:/path/to/destination  



1 comment:

  1. Nice post, I bookmark your blog because I found very good information on your blog, Thanks for sharing more information. Regards aws jobs in hyderabad.

    ReplyDelete