Amazon Web Services is an advanced cloud platform which offers lots of features. As cloud platforms go it is mostly for larger projects that need to be able to scale. That said Amazon offers a free tier, which means that you can test out their features for one year for free. Yes, you get cloud services to play with for free! More info on Amazon’s Free Tier page.
AWS can have a slightly steep learning curve if you haven’t worked with cloud administration before so here is a straight forward guide to get your own LAMP box up and running on AWS.
- Create a new AWS account here, if you are an existing Amazon customer you can simply login with that account. Once you are logged in go into the AWS Management Console, from the menu in the upper right of the page.
- Now we need to set up your security group, the basics for allowing you to login to your server. Click on EC2 to enter the EC2 Dashboard. EC stands for Elastic Cloud which is Amazon’s name for their Cloud Servers. Click on Security Groups under Network & Security in the left menu and select the default group in the table. Select the Inbound tab and add rules for SSH, HTTP and HTTPS, then click Apply Rule Changes. If you need other protocols for your server you need to add them here.
- Let’s create an instance. Click on Instances under Instances in the left menu and click Launch Instance. Select the Quick Launch Wizard and type in a descriptive name for your instance. Choose to create a new key pair and download the key, which is a .pem file you need to access your server securely. Then select a launch configuration from the list, my suggestion is one of the Ubuntu Server configurations which are eligible for the free tier. You always need to keep an eye on what you do in the AWS Management Console since you don’t want to enable stuff Amazon will charge you for. Click Continue and then Edit Details. Make sure that under Security Settings the default security group is selected. It is important that you configure the security groups before launching the respective instance, since you won’t be able to change it after launch. Click Launch and in a couple of seconds your instance will be up and running. Congratulations you have a new LAMP box to play with.
- In order to connect to the instance we need to assign an IP address. In the left menu in the EC2 Management Console select Elastic IPs under Network & Security. Allocate a new address and assign it to your instance. Elastic IPs are free as long as they are assigned to an instance, so remeber not to leave any unallocated IP addresses as you will get charged by the hour. Remember the assigned IP.
- On your local machine use the pem key to SSH into your instance. On OS X change the permission of the key to 600 and use following command in terminal:
ssh -i yourkeyname.pem ubuntu@yourelasticip
and boom you are in.
- Update the Ubuntu package manager and the installed packages:
sudo apt-get update sudo apt-get dist-upgrade
- Install Apache:
sudo apt-get install apache2
- Enable .htaccess files by editing the /etc/apache2/sites-available/default file, fx with vi. Look for the /var/www directory and make sure it contains AllowOverride All.
- Enable the rewrite module in Apache:
sudo a2enmod rewrite
- Install PHP5:
sudo apt-get install libapache2-mod-php5
- Restart Apache:
sudo /etc/init.d/apache2 restart
- Ensure that Apache is running by typing the instance IP in your browser.
- Allow the Ubuntu user to work with the /var/www folder:
sudo adduser ubuntu www-data sudo chown -R www-data:www-data /var/www sudo chmod -R g+rw /var/www
Logout and login again to pick up the new user group. Test by creating a directory and deleting it again in www without having to sudo. This will make your life easier since permissions will get messed up less once you start adding frameworks and tools to your web service.
- Test PHP by cd into /var/www folder and typing sudo vi phptest.php. Hit i key to enter insert mode and just write a simple php script with a phpinfo() call.
Hit ESC to exit insert mode and type :wq to save and quit the vi editor. Go to instanceIP/phptest.php in your browser and you should see the phpinfo displayed.
- Install MySQL:
sudo apt-get install mysql-server sudo apt-get install php5-mysql
Insert root password for the database and remember it.
- To test MySQL let’s install PHPMyAdmin:
sudo apt-get install phpmyadmin
Select Apache2 as server and Create Databases, just follow the instructions. Go to instanceIP/phpmyadmin to test. If there are any issues check the ubuntu community for help.
You can use FTP with your instance by setting up SFTP. I recommend using Git though, as described in my web development setup post as well as configuring MySQL Workbench instead of PHPMyAdmin. Also once you have your instance configured create an AMI image of it in your EC2 Management Console so that you can just launch a new instance from your image next time or if you need to add another to your setup.