Wednesday, 11 January 2012

LAMP on AWS

Rent an ec2 instance

You can set up an account with Amazon Web Services and rent out a ec2 instance here The Amazon Web Service Console
I used an instance of the Amazon Linux AMI based on Elastic Block Store. Using an instance based on an Elastic Block Store gives you more options for backing up your disks later. The "Amazon Linux AMI" is based on CentOS and is a pared down version of linux with only the bare essentials included, that should be more secure. You can use the yum command to install anything extra necessary on your server.

Attach an 'elastic ip' and open necessary ports on firewall

Again through the The Amazon Web Service Console :
  • I created and attached an elastic ip address to the ec2 instance I had launched with the Amazon Linux AMI.
  • I opened ports 22 and 80. For my purposes I did not intend to make the server accessible through https so these were sufficient.
You may want to map a domain name to point to your elastic IP address. You will need a dns provider to do this. Amazon does not provide this service at the time of writing.

Connect to your ec2 instance with putty or another ssh client

Through the The Amazon Web Service Console you can set up an ssh key and attach it to the ec2 instance you have running.
Your username for an ec2 instance using the Linux AMI will be ec2-user and no password will be required if you have the private key set up correctly.

Accessing ec2 instance using putty ssh client

In order for this key to work with putty on Windows you need to import it using puttygen and then save the private key in a safe location possibly with a pass phrase (local password) to protect it. You can then associate the key file with the ssh connection in putty by opening settings in Connection/SSH/Auth and browsing for the correct 'Private Key for Authentication'

Setting up a web server on Amazon Linux AMI

Make sure all your currently installed packages are up to date.
sudo yum -y update
You use yum to install all the software you need on your server. You can use the following command to install apache, mysql and php and the php extensions and all dependencies required by Moodle with this command :
sudo yum -y install aspell aspell-en aspell-fr aspell-es cvs httpd mysql mysql-server php php-cli php-gd php-intl php-mbstring php-mysql php-pdo php-soap php-xml php-xmlrpc php-pspell
You can list all your installed packages (including dependencies) with this command :
sudo yum list installed

Start server services and have them start up automatically on a reboot

Configure the new services to start automatically.
sudo  /sbin/chkconfig httpd on
   sudo   /sbin/chkconfig mysqld on
   
   sudo  /sbin/service httpd start
   sudo   /sbin/service mysqld start

Edit httpd.conf

If you need to edit httpd.conf it is in /etc/httpd/conf
But by default the directory /var/www/html/ is the root web directory and you can install Moodle in there.
If you do edit httpd.conf then you must restart apache using this command for the changes to take effect :
sudo  /sbin/service httpd restart

Set up MYSQL

sudo mysqladmin -u root password 'new-password'
Make additional security-related changes to mysql.
sudo mysql -u root -p
mysql> DROP DATABASE test;                            [removes the test database]
mysql> DELETE FROM mysql.user WHERE user = ;        [Removes anonymous access]
mysql> FLUSH PRIVILEGES;
 
http://docs.moodle.org/22/en/Installation_Guide_for_Installing_on_Amazon_EC2

No comments:

Post a Comment