Tuesday, 11 January 2011

How to Set Up Virtual Hosting on Apache

If you are running an Apache Web server on a DSL or faster link, you can become a hosting provider for other people. You can even host their domains, without needing an IP for each domain. This is called virtual hosting, and you'd be surprised at how easy it is. Remember, some access providers have rules against running hosting services, check your hosting agreement for more information.

Register a Domain

The first thing that needs to happen is you need to register a domain at Internic or Register.com. Follow the instructions at these sites (links on the right), to register your new domain. If you're creating this for a customer, you can have them register the domain or you can do it yourself.

Domain Name Service

This is the hardest part. If you don't host your own DNS, you'll need to contact your hosting provider to have the new domain added to the DNS server. If you're hosting your own DNS this consists of:

  1. edit Bind or NameD or DNS to add the new domain name
  2. point it to the IP of your virtual hosting server
  3. restart your DNS service

Apache Configuration

Once you have the DNS pointing to your virtual domain server, you need to tell your Web server where to find the Web files for the domain. The way Apache works, if you have set up virtual domains, the first domain entered is the default. This is the directory that will be displayed when a virtual domain is not listed in the configuration. (In other words, if the DNS entry made above sends the URL to your IP, but you don't have the virtual host in your httpd.conf file.)

An Example

You have bought the domain www.adogslife.com and you want to host it at the hosting service with the IP (which you also own).

DNS is set up to point to that IP.

Now you must edit your Apache httpd.conf file:

  1. Go to the section of the httpd.conf file on Virtual hosting (sometimes it's in srm.conf)
  2. Make sure that the NameVirtualHost points to your IP:NameVirtualHost
  3. The first virtual host entry should be your default domain:
    ServerName www.defaultdomain.com
    DocumentRoot /www/domain
  4. Then list the new domain, with any options you'd like to add:
    ServerName www.adogslife.com
    DocumentRoot /www/dogslife
    ErrorLog logs/adogslife.com-error_log
    TransferLog logs/adogslife.com-access_log

Note, I added two lines to the second virtual host. These allow you to separate out the Error and Transfer logs for the new domain from your default domain. If you are going to host virtual domains for other people, they will almost certainly want their server logs, and this makes it easy to provide that to them as well.

Friday, 7 January 2011

How can I install PHP5 under IIS 6.0?

Download the latest PHP version for Windows from http://www.php.net/downloads.php, right-click on the PHP folder, and select "Extract All..."

Select "Next"

Choose C:\Program Files\PHP5 as extract directory and click on "Next"

Uncheck "Show extracted files" and click on "Finish"

Launch the "Internet Information Services (IIS) Manager" from the start menu. You need to install IIS in case this option is not available.

Right-click on "Website" and select "Properties"

Select the "Home Directory" tab and choose "Configuration"

Choose "Add"

Add "C:\Program Files\PHP5\php5isapi.dll" (including quotes) to "Executable" and add .php as extension. Then limit the verbs to GET,HEAD,POST,TRACE and click on OK

Now choose the "Documents" tab and select "Add"

Enter index.php and click on OK

Now, you can change the priority of your index.php with the "Move Up" button. This is only necessary if you run primary a PHP based website

Finally, select Web Service Extensions on the left side and choose "Add a new Web service extension"

Select "Add" and enter as path C:\Program Files\PHP5\php5isapi.dll and click on OK

Then enter php5 as extension name and check "Set extension status to Allowed". Then click on OK to enable this extension

Copy C:\Program Files\PHP5\php.ini-dist to C:\WINDOWS\php.ini and restart IIS

Then create the following php file with Notepad:

Save this file under C:\Inetpub\wwwroot\test.php

Now launch Internet Explorer and go to http://localhost/test.php . You should see the PHP info page if your PHP5 installation was successfully.