SERVER SETUP 2 - CONNECTING YOUR DOMAIN NAME TO YOUR APPLICATION DIRECTORY
Link to this article:
Ok, so this is a turning point for all those that have never setup code to be accessed through the internet. The end goal is simply so you can access www.yoursite.com in a web browser and see the result of your code displayed in the web browser. The first time I executed this, it made me really happy, and you’ll be sure to have the same reaction.
The high level explanation of what’s happening is simply that you matchup a domain name with a directory on your server. You tell your server that any traffic coming for www.yoursite.com should connect to the code located at /var/www/yoursite.com.
Navigate to /etc/apache2/sites-available. Open up the file there called “default”. Also note that if you don’t have a tool like SCP on windows you’ll have to edit these files at the command line using an application that comes with Linux called “vim”. So for example to access that file would type the following:
# cd /etc/apache2/sites-available
# vim default
Vim is a text editor for use over SSH in the terminal. Google “Vim tutorial” to learn how to use it, as it’s out of the scope of this tutorial. It will be a little abnormal at first, but it won’t be hard to get the hang of.
Also, what I love about running Ubuntu Linux on my own desktop is that you can connect to servers and access their file system the same way you access your local file system. You can easily drag and drop files back and forth between your server and your desktop computer without having to do so in an FTP/sFTP program. I highly recommend anyone serious about getting their startup going that they install Ubuntu on their home computer. It’s really not that difficult to install. Just go here and follow their directions: http://www.ubuntu.com/ . Once you have it installed, just go to Places > Connect to Server and then connect to your EC2 instance via your root ssh credentials. That’s one reason why I violate the security precautions of using the Amazon-provided SSH keys...The other thing you can do is open up files on your server in text editors and IDEs just as you would files on your own computer.
Anyway, you’ve gotten to the point where you can edit the text files on your server. You’re now going to setup some Apache configurations to make your site accessible from yoursite.com . Open up that “default” file and add the following configuration lines to the bottom of the file (these are the bare minimum you need--there’s a lot more you can do to configure it, but to convey the main concept here, we’ll only show the minimum):
Note that /var/www/yoursite.com is actually the name of a folder, i.e. “yoursite.com” there is a name of a folder. You don’t have to put the .com, but I like to in order to be very consistent and connote that this folder contains a full-fledged website.
Now in that folder put a file similar to that index.php file made in the previous Setup tutorial. Now go to www.yoursite.com or yoursite.com and you should see the same result, i.e. the information about your server. If you do, you’re money and good to go.
If you haven’t setup your domain on Godaddy to point to your server, do so now. I won’t go into deep detail about it because you can google something like “godaddy dns tutorial” to figure it out very easily. But basically, you’re going to navigate to My Domains, and then to the yoursite.com domain, and then to “Manage DNS Settings” and then enter the IP address of your server near the top of the page, and save the settings. I won’t go into much about the technical terminology about how you’re essentially making your “A record” (i.e. a DNS record) point out your ip address. Just make it happen. It’s no big deal.
You may need to restart your server, so at the command line type:
# /etc/init.d/apache2 restart
It also may take some time for Godaddy to successfully point your domain at your server, but I’ve found it almost always to be instantaneous.