Saturday, 25 February 2012

Using Host Headers on a Virtual Server and creating a new site before buying a domain name

How to create and test a website before buying the domain name

Sometimes you may want to create a new website but don't have a domain name to point it at but still want to test everything is working.

Today I wanted to do this and there were a number of issues I had to work through so I thought I would list them for all the Windows developers who are new to LINUX and APACHE.

The site was a basic Wordpress site which was going to run on a Rackspace Virtual Server which already hosted a number of sites.

If you have installed VirtualMin and WebMin it's very easy to manage your server with a graphical interface otherwise you will need to do everything through a SSH client like PUTTY terminal serviced into your server.

1. Create a new virtual site
  • Login into your webserver which will be your hostname on port 1000 e.g:
  • If you login as root you won't need to create Webmin logins for each virtual host.
  • Choose the "Create Virtual Server" option on the left menu.
  • Complete the form entering the name of the domain you want to use e.g  robstestdomain  I tend to use the domain name as the description field as well.
  • Enter a password - this will be used for your FTP and Database password unless you change it later - make it secure by using a mixture of letters and numbers both lower and uppercase. If you cannot remember a complex string use a combination of words or a sentence and add numbers or symbols between each word and at the beginning and end e.g 77Strictly2012Software1984
  • Under the Enabled features I ticked the following options:

Setup website for domain?
Accept mail for domain?
Setup Webalizer for web logs?
Create MySQL database?
Enable AWstats reporting?

  • Click the "Create Server" button and the system will generate everything it needs with an output like so

Setting Up Virtual Server

In domain
Creating administration group robstestdomain ..
.. done
Creating administration user robstestdomain ..
.. done
Creating aliases for administration user ..
.. done
Adding administration user to groups ..
.. done
Creating home directory ..
.. done
Creating mailbox for administration user ..
.. done
Adding to email domains list ..
.. done
Adding default mail aliases ..
.. done
Adding new virtual website ..
.. done
Adding webserver user www-data to server's group ..
.. done
Performing other Apache configuration ..
.. done
Setting up scheduled Webalizer reporting ..
.. done
Setting up log file rotation ..
.. done
Creating MySQL login ..
.. done
Creating MySQL database robstestdomain ..
.. done
Setting up AWstats reporting ..
.. done
Setting up password protection for AWstats ..
.. done
Applying web server configuration ..
.. done
Saving server details ..
.. done

Once you have done this open up your favourite FTP client like FileZilla and add the new domains details to the Site Manager. For example if you were creating a secure FTP site you would use these settings.

  1. Click "New Site" give it the name of your domain > "robstestdomain"
  2. On the right fill out the form with
  3. Host:
  4. Protocol: SFTP - SSH File Transfer Protocol (secure FTP) you can choose FTP if your hosts firewall is setup to allow traffic through ports 20 and 21.
  5. Logon type: Normal
  6. User: robstestdomain
  7. Password: [the same password you entered when creating the Virtual Server] e,g 77Strictly2012Software1984
  8. Click "Connect" your FTP client should now connect to the new folder on your server which will be empty apart from some default folders like cgi-bin, homes, logs, public_html etc.

Download the latest version of Wordpress from their site:

Extract the files and copy them up to the public_html folder on your server e.g: /home/robstestdomain/public_html

You will now have extra folders like wp-content, wp-includes and wp-admin under /public_html as well as a number of files including wp-config-sample.php.

You need to edit this file and replace the main database connection settings at the top of the file. These will be the same settings you used when creating the site unless you have manually gone in and changed them.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'robstestdomain');

/** MySQL database username */
define('DB_USER', 'robstestdomain');

/** MySQL database password */
define('DB_PASSWORD', '77Strictly2012Software1984');

/** MySQL hostname */
define('DB_HOST', 'localhost');

One thing I found earlier is that if you created a domain with a hyphen in it like "My-Domain" then when you create the username you should replace the hyphen with an underscore otherwise it won't be able to connect to the database.

You should also add in sentences for all the security keys to make your site more secure. The longer the words the better.

define('AUTH_KEY',         'some phrase or two');
define('SECURE_AUTH_KEY',  'another unique phrase 100003433');


define('NONCE_SALT',       'something else 23423423');

Once complete save the file as wp-config.php and upload to the root folder e.g /public-html/wp-config.php

Now that you have a virtual server setup you need to make sure that you can access it from your own computer as it currently isn't visible online as there is no DNS record setup pointing a domain to your site.

To do this you can edit your hosts file which is located om your computer (windows 7) under

You need to add the following line to the host file that points the IP address of your webserver to the domain you have just created.

If you don't know the IP address of your host just open a command prompt and type "PING [hostname]" e.g PING

Reply from bytes=32 time=105ms TTL=49

In your host file at the bottom of any exiting list put the IP address of your host and the domain you want it to point to e.g

If you have problems editing the file such as it saying that the file is "Read Only" even when it's not set as Read Only, or you don't have sufficient administrator privileges to edit the file then do the following:

1. Right click on Notepad and choose "Run as administrator"
2. Use the File > Open option to open the hosts file
3. Add the line in and then choose File > Save.

Make sure you shut down your browser after editing the host file before re-opening it and then typing in the domain name in the address bar e.g

If everything has gone okay you should be taken to the Wordpress configuration page e.g /wp-admin/install.php where you can complete the setup by entering details of your sitename, email and password.

Once the form is completed click on the "Install Wordpress" button it will build all the tables in your database and activate your site. You can check the database has been build from within VirtualMin or by using a MySQL database management system like Navicat.

Remember if you have other sites on the same server that have DNS records setup they should still work by entering their domain names into the address bar but because you have told your computer to always take the domain and point it at your server in the host file you should be able to see your new site even if no-one else can.

You could enter your IP address alone instead of the domain name but either should bring you to the new site.

If you don't want people to access your new site during development by hitting your IP address (not that many real users would do) you should setup some htaccess or deny hosts rules so that only traffic from your own PC can directly use the IP address or your new test domain name and return a 403 status code to everybody else.

Once you have set your site up, installed your themes and plugins and read my Wordpress Survival Guides, one and two on the best plugins to use for performance and the best Apache config for your site you will be ready to rumble. Go and buy a domain from and point it to your new virtual server.

If you have any problems you should also check your new sites Apache config file e.g /etc/apache2/sites-available/ and make sure its setup like you want. Open an existing config file for one of your other working sites and copy and paste the data changing the names to your new site.

Always restart your server after changing your conflig files but only after running a test for any syntax errors in any of your config files. You can do this in your console with the following lines.

myhost:~:# apache2ctl configtest
Syntax OK
myhost:~:# /etc/init.d/apache2 restart

You can also restart Apache through WebMin which is located under the System > Bootup and Shutdown menu option.

And that my friends is how you do it.

Update: 27-FEB-2012

If you change your mind about the domain name you want to use for your site you will need to delete the existing virtual server and set-up a new one. This might cause problems if you are behind a proxy at work that doesn't allow your hosts file to work. Therefore you should read this article on deleting a site in VirtualMin and accessing a Wordpress site by IP address alone.

No comments: