Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

How To Create A LAMP Setup (Apache2, PHP, MySQL) On CentOS 5.x In An Amazon Linux AMI 32bits Or 64bits


This tutorial explains how to create a virtual machine with CentOS 5.x on Amazon’s Elastic Compute Cloud (Amazon EC2) and how to set up a LAMP system (LAMP stands for “Linux, Apache, MySQL, PHP”) in this virtual machine. We use an AMI (Amazon Machine Image) to set this virtual machine up.

I assume you have an Amazon EC2 account.

Create An AMI Instance

You need to go to the EC2 tab and there choose Launch Instance:

1ami

Then a small window will open and there you need to choose the AMI that you need for your project – in this case Basic 32-bit Amazon linux AMI or the 64-bit version:

2ami

Then on the next screen use the default settings and click on the Continue button.

Then on the next screen you must choose a key for accessing your AMI; if this is your first AMI in EC2 you need to choose the option:

Create new key pair

and fill the Enter a name for your key pair input with the name of the key, for example myKey.

Then click on Create & Download your Key Pair button, and the browser will download the key file.

Note: It’s very important to save the file in a secure directory because you will use this key to access your AMI (from now virtual machine).

Then you need to select the security groups. This means you need to choose the open ports or the security rules of your virtual machine. By default there is one active and open port; it is port 22 which allows you to access your virtual machine via SSH.

 

Connecting To Your Virtual Machine Via SSH

For this, I propose the Tunnelier program, because it is easy to use and you have console and SFTP at the same time.

I assume that you will connect from a Windows operating system; for other cases I will write the command to connect from your console.

The steps for connecting to the virtual machine under Windows are:

  1. Download the Tunnelier program from bitvise.com (it’s free). Select Download Tunnelier (SSH Client).
  2. Install it like you normally do on Windows.
  3. Open the program.
  4. Go to your EC2 dashboard and select the Elastic IP option from the left menu.
  5. In the main window click on the button Allocate New Address; a small screen will appear where you must confirm the action, then select click on the Yes, Allocate button.
  6. The new public IP will show in the panel. Now we need to associate it to our virtual machine.
    To do this, select the IP and click on the Associate button (see the image) and then a small window named Associate Address will be displayed, and there you must choose the ID of your virtual machine from a list (in my case I have only one, therefore I can only select that one option), and then click on the Associate button.

ami5

 

Then on the next screen use the default settings and click on the Continue button.

Then on the next screen you must choose a key for accessing your AMI; if this is your first AMI in EC2 you need to choose the option:

Create new key pair

and fill the Enter a name for your key pair input with the name of the key, for example myKey.

Then click on Create & Download your Key Pair button, and the browser will download the key file.

Note: It’s very important to save the file in a secure directory because you will use this key to access your AMI (from now virtual machine).

Then you need to select the security groups. This means you need to choose the open ports or the security rules of your virtual machine. By default there is one active and open port; it is port 22 which allows you to access your virtual machine via SSH.

 

Connecting To Your Virtual Machine Via SSH

For this, I propose the Tunnelier program, because it is easy to use and you have console and SFTP at the same time.

I assume that you will connect from a Windows operating system; for other cases I will write the command to connect from your console.

The steps for connecting to the virtual machine under Windows are:

  1. Download the Tunnelier program from bitvise.com (it’s free). Select Download Tunnelier (SSH Client).
  2. Install it like you normally do on Windows.
  3. Open the program.
  4. Go to your EC2 dashboard and select the Elastic IP option from the left menu.
  5. In the main window click on the button Allocate New Address; a small screen will appear where you must confirm the action, then select click on the Yes, Allocate button.
  6. The new public IP will show in the panel. Now we need to associate it to our virtual machine.
    To do this, select the IP and click on the Associate button (see the image) and then a small window named Associate Address will be displayed, and there you must choose the ID of your virtual machine from a list (in my case I have only one, therefore I can only select that one option), and then click on the Associate button.

ami5

Once we have an IP associated to our virtual machine, in the Tunnelier program we need to import the access key for our virtual machine. For this action we click on User keypair manager and as shown in the following images, import the my Key.pem file that we created before. And then it will appear in the list.

ami6

ami7

ami8

 

  • Put special attention to the number in the list, because we use this number to make the connection.
  • Configure the rest as shown in the following image:

ami9

 

  • And connect to your virtual machine (click on the login button); then you have the console and ftp like in the following image:

ami10

In the case you use Linux or Unix as your client system, you can connect using the following command from the command line:

ssh -i myKey.pem ec2-user@myPublicIP

Install MySQL

To install MySQL we need to have an open console and put in the next instructions.

Get  root privileges:

sudo -i

Install MySQL:

yum install mysql mysql-server mysql-libs

Start the service and configure it to start automatically at boot time:

/sbin/service mysqld start

chkconfig –levels 235 mysqld on

Set a MySQL root password:

mysqladmin -u root password ‘new-password’

 

Install Apache And PHP

In the console type:

yum install httpd php php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
/etc/init.d/httpd restart
chkconfig –levels 235 httpd on

Now open a browser and go to:

http://MiPublicIP/

14

Install PhpMyAdmin

To install PhpMyAdmin we need a console again; please make sure that you have root privileges!

First we need to enable the RPMforge repository:

On Linux Amazon 32-bit:

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

On Linux Amazon 64-bit:

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm

Then we install PhpMyAdmin:

yum install phpmyadmin

Now we modify the file /etc/httpd/conf.d/phpmyadmin.conf with nano:

nano /etc/httpd/conf.d/phpmyadmin.conf

#  Web application to manage MySQL  
#  #<Directory "/usr/share/phpmyadmin">  
#  Order Deny,Allow  
#  Deny from all  
#  Allow from 127.0.0.1  
#</Directory>  
Alias /phpmyadmin /usr/share/phpmyadmin  
Alias /phpMyAdmin /usr/share/phpmyadmin  
Alias /mysqladmin /usr/share/phpmyadmin

Then we change /usr/share/phpmyadmin/config.inc.php and change the line $cfg[‘Servers’][$i][‘auth_type’] from cookies to http:

[...]  /* Authentication type */  
$cfg['Servers'][$i]['auth_type'] = 'http';  
[...]

Then we restart Apache:

/etc/init.d/httpd restart

… and go to PhpMyAdmin in the browser:

http://MiPublicIP/phpmyadmin

And that’s all.

 

  • The basic idea is from this tutorial:http://www.Kreationnext.com/installing-apache2-with-php5-and-mysql-support-on-centos-5.3-lamp
  • Amazon documentation:http://aws.amazon.com/es/documentation/

 

 

 

Comments

comments