SERVER SETUP 1 - SETTING UP LAMP & AMAZON WEB SERVICES
Link to this article:
Many things in software development rely on winning recipes. This is one of them, and the one that kicks it all off--one that’s required if you have any hope of getting anywhere in PHP coding and getting your application production ready. Quick note: if you don’t already know the, the acronym, “LAMP,” stands for Linux, Apache, MySQL and PHP, i.e. the 4 applications necessary to run the sort of apps these tutorials are written for.
The goal is this: to install LAMP using the Ubuntu flavor of Linux on an Amazon EC2 server. This by the way is the official FaceySpacey recipe. Ubuntu Linux is what we live by, and quickly become the best Linux distribution, especially for newbies like you. Here’s the official Amazon EC2 Ubuntu setup guide:
On that page is links to the latest Amazon EC2 AMIs to install. If you don’t know what an AMI is, it’s basically a template that you generate your Amazon EC2 server from. As of August 2011, here’s the latest set of AMIs:
On that page is a table. You will be clicking the link in the AMI column. Find the row that corresponds to the region closest to you that has a 32 bit architecture and a “root store” of “EBS.” Click the link in that row, and it will link to your Amazon account and begin the process of creating an EC2 instance based on that AMI/template.
If you haven’t signed up for Amazon AWS yet, do so here:
Lately, they’ve been making you signup for each service you will use. Signup for EC2 to begin with.
Ok, so back to creating your instance. Go through the steps, and choose the following options when presented with them:
set the instance type to m1 small
create a new keypair and download the corresponding files to your computer
for everything use the defaults--at least for now
After you’ve created your instance, go to the Security Groups link in the left column. Click the “default” security group which was assigned to your EC2 instance. Set the rules so HTTP traffic is allowed from all IP addresses, and allow SSH traffic from the ip address of your computer. Find your IP address here: http://whatismyipaddress.com/ .
The next thing you will do is set your server up so you can login to it without using the keys provided by the Amazon EC2 web interface. Though experts will not recommend accessing your server via “root access,” I’m going to teach you how to do it since if you’re new to this you’re most likely dependent on root access for much of what you do.
But let’s first login once with the keys provided by the EC2 web interface, since that’s the only way to initially get in. Click the “Instances” link in the left column. Then right-click your instance row and click “connect.” There will be a set of directions there to follow. Basically it boils down to executing a command (from Putty on windows), or the Terminal on Macs and linux, and making sure the private key you created when you first created your instance is associated with the connection command. One thing to note is that you will connect as the “ubuntu” user, rather than the root user. That’s how Ubuntu AMIs are setup.
Once you’re logged in as the Ubuntu user, setup the password for the root user with this command:
# sudo passwd root
After following the steps to change the root password the above command will lead to, navigate to /etc/ssh/sshd_config and uncomment this line: PasswordAuthentication yes
Then restart your SSH server with this command:
# sudo /etc/init.d/ssh restart
Now you can connect to the server remotely via the root and the password you set. Do that, i.e. login via SSH from the terminal with with user “root” and the password you set.
Next, now that we’re basically in control of your fresh EC2/Ubuntu Linux server, it’s time to install the applications you will need. First you need to update your server so that it gets the latest patches and updates from the internet, i.e. like your Mac or Windows computer regularly--and automatically--updates itself. Run this command:
# apt-get update
Now execute the following commands one after another. Wait for each to complete before doing the next one:
We installed a few tools we commend there such as “mercurial,” which is a version control application--we’ll talk about that stuff in other articles. Just know this is our recipe to get everything done efficiently all at once, and that’s why installing such apps are in this article.
Ok, so next go back to the EC2 web panel. Go to the “Elastic IPs” link in the left column. Click the “Allocate New Address” button and create a new IP address. Then right-click the row that appears corresponding to your new IP address, and choose the “Associate” option from the menu that appears, and associate the IP address with the EC2 instance you previously created.
Now copy/paste that IP address into your web browser and visit that URL. You should see a message saying that your server is setup. Next go back to the terminal where you’re connected to your server, and navigate to /var/www. In that directory will be a file called index.html. Rename it to index.php like this
# mv index.html index.php
Now in that file, replace all the code there with:
One final thing: you need to enable Apache's mod_rewrite so you can have pretty URLs. Do this:
# a2enmod rewrite
Now you should be able to revisit that IP address URL and see a bunch of info about your server in pretty blue tables. That’s all the information about your server, the settings, and what is installed on it. This also means that PHP is working on your server, as well as of course Apache, which is your “web server” application that works in conjunction with PHP to display web pages to remote web browsers trying to connect to your server.
What next? Basically from here, you will create your applications in directories such as /var/www/application-name . After that, you will need to point your domains from godaddy (or wherever your domain names are hosted) to your server, and then on your server, you will associate an incoming domain name with directory path such as the aforementioned /var/www/application-name. We’ll describe this in the next tutorial.