I will be doing the following through an OpenSSH connection to the server using Putty on Windows 7. If you do the same, you will connect with your servers IP Address using port 22 with your username and password.
In order do to this next part, you will need your own domain name. If you have one already, you will need to change the DNS records to point to your server. If you do not already have one, you can easily buy one from somewhere like godaddy.
If you decide to buy your own domain, you will need to change the dns records to point to your server.
If not, you can add a domain name to your host file along with your servers IP Address. To set this up, I will be editing the hosts file to route traffic internally for site1.com and site2.com. What this means is that if I was to open up the internet and navigate to these website, instead of looking on the internet for it and doing a dns lookup, it will automatically look on to your webserver. If you already have your own working domains then you can use them.To edit the hosts file, open up the start menu and search for notepad. Then click ‘Run as Administrator’
Once you have notepad open, go to file and then open. Navigate to C:\Windows\System32\drivers\etc
In the window where it says Text Document (*.txt), click the drop down box and change it to All Files and then open hosts.
Once the file is open you will want to add to the bottom of the document these lines:
<ServerIPAddress> site1.com <ServerIPAddress> site2.com
so when finished it should look like this:
# Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 18.104.22.168 rhino.acme.com # source server # 22.214.171.124 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost 10.0.0.150 site1.com 10.0.0.150 site2.com
On the Ubuntu Server
Now, we need to update the packages on our server before we can install the ones we will be using. We can do this using the following command
sudo apt-get update; sudo apt-get upgrade;
Once you have done that, you will need to install two packages. One as a web server and the other as the sql server. To do this, you type the following:
sudo apt-get install apache2 mysql-server
When installing, you may be asked if you would like to continue. You should type ‘Y’ and then click enter. Next you will be asked to choose a password for your new mysql root user.
After choosing the password, you will then need to repeat it.
We will now be setting up apache2 so that we can host multiple websites. To do this, we will need to edit the apache2 configuration file.
sudo nano /etc/apache2/sites-available/default
It should look something like this.
We will need to remove all of the contents of this file. We can do so by holding down the Ctrl key + K. Next you will need to enter the below configuration.
You will then need to enter the following information into the file.
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin firstname.lastname@example.org ServerName site1.com DocumentRoot /var/www/site1.com CustomLog /var/www/logs/site1.com.log combined ErrorLog /var/www/error_logs/site1.com.log </VirtualHost> <VirtualHost *:80> ServerAdmin email@example.com ServerName site2.com DocumentRoot /var/www/site2.com CustomLog /var/www/logs/site2.com.log combined ErrorLog /var/www/error_logs/site2.com.log </VirtualHost>
You can save this by pressing Ctrl + O and Ctrl + X to exit.
To create a server we do mkdir followed by the location. Type in the following:
mkdir /var/www/site2.com mkdir /var/www/error_logs/ mkdir /var/www/logs/ mkdir /var/www/site1.com
We now need to restart apache to make sure everything is okay.
sudo service apache2 restart
If you see a message like the following then it is okay.
It is probably a good idea to create a index page in each of the directories so that you know which is which and so you can make sure it is working. You can do so with the following:
echo "<p>This is site1</p>" > /var/www/site1.com/index.php echo "<p>This is site2</p>" > /var/www/site2.com/index.php
This way, when you go to site1.com you should see the message “This is site1″ and if you go to site two you will see “This is site2″.