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 


  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.

  2. Thanks for sharing, nice post!

    An thái sơn chuyên cung cấp may dua vong tự động uy tín cho bé với các blog như,, giúp bé yêu ngủ ngon giấc.

  3. can be done at home or pretty much anywhere, with special boxes. Though expensive, rising demand can lower the costs of such light boxes circadian rhythm light therapy

  4. Thanks for sharing such nice blog site list. nice collection of sites.Tutuapp APK


  5. Very Interesting and wonderful information keep sharing this post kindly check
    download qooapp for pc

  6. The first ideas that Louis Comfort Tiffany created more than 100 years prior to make his Tiffany lamps are as yet utilized today in making Tiffany generations.happy lamp

  7. Thanks for provide great informatic and looking beautiful blog, really nice required information & the things i never imagined and i would request, wright more blog and blog post like that for us. Thanks you once agian Marriage certificate , Marriage certificate delhi, Marriage certificate in delhi, Marriage certificate online, online Marriage certificate