Start Services Using a Batch File

If you use your person computer as a testing server you probably have several services running in the background (a web server, database, caching service, etc). Individually these services tend to have a small footprint. If you’re running enough of them however, they can start to impact your machine’s performance. If you have them set to auto start they can also increase your startup time. Ideally you would want to start them when you need them and stop them when you’re done with them, but that can be a hassle for multiple services. A simple solution is to create a batch file to start all of your services, and another one to stop them.

Follow these steps to create your batch file:
Continue reading

Creating Local Domains

This guide will show you how to create a domain on your local machine and configure apache to route traffic to that domain to a particular directory. I’ll describe how to do this using Windows, but the process should be very similar in a linux environment.

The first step is to choose a domain name. When choosing a domain you should remember two things: It will only exist on your local machine and it will override an already existing domain. The latter is probably the most important; choosing google.com as the domain will prevent you from accessing google.com. The simplest way to avoid overriding a domain is to leave off the TLD. Personally I use subdomains of localhost. For example, if I had a project Foo that I wanted to create a domain for I’d choose foo.localhost.

The next step is to associate the domain with your loopback address (almost always 127.0.0.1 the IPv6 version is ::1). To do this you need to locate and edit your hosts file. In Windows it should be located in the directory C:\Windows\System32\drivers\etc If you are using Vista or 7 you won’t be able to edit it with Administrative Privileges. You’ll need to run whatever application you are using to edit it (notepad will do) as an administrator. To do so in notepad follow these steps:

  • In your Start menu navigate to All Programs > Accessories
  • Locate and right-click Notepad
  • Click Run as administrator
  • Once in Notepad select File > Open...
  • Navigate to C:\Windows\System32\drivers\etc and select the file hosts

Your hosts file should look something like this:

127.0.0.1 localhost
::1 localhost

If the domain you chose if foo.localhost then just add the entry:

127.0.0.1 foo.localhost

After you save the file the domain foo.localhost should route to 127.0.01. For now it is effectively identical to just using localhost.

It is up to apache to route traffic to foo.localhost to the right location. This process may vary depending on your configuration, but at this point it is identical to configuring a virtual domain on your server. The first step is to create a virtual host. Locate your httpd.conf file, it should be in the conf directory wherever apache is installed. If you haven’t already set up a virtual host you’ll need to add the line:

NameVirtualHost *

You’ll then need to setup a virtual host for each domain, here is an example:

NameVirtualHost *
<VirtualHost *>
    ServerAdmin webmaster@foo.localhost
    DocumentRoot "C:\srv\foo\public-html"
    ServerName foo.localhost
</VirtualHost>
<VirtualHost *>
    ServerAdmin webmaster@localhost
    DocumentRoot "C:\srv\public-html"
    ServerName localhost
</VirtualHost>

If you entered your new domain into your browser now you may get a 503 error (forbidden). To fix this problem you’ll need to tell apache to allow access to directory you specified in the DocumentRoot entry in your virtual host:

<Directory "C:/srv">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Thats it! Your domain should be setup and ready to use.

Words from our friends at WHS: Finding a good virtual private server will provide you with the performance and flexibility you need to create a great site.

Circumventing DNS Caching

During my recent host switch I ran into a bit of a problem. After I had moved my database and content to the new server and changed the name servers, requests were still be directed toward my old server. The reason for this is that my ISP had not yet updated their DNS record cache thereby causing requests to be directed to the old server. It typically takes several days for a domain to fully propagate; the amount of time it takes for changes to take effect for an individual depends on how often their ISP updates the DNS records. There is, however, a simple way to avoid having to wait for DNS propagation.

(Note that it may be sufficient just to clear your local DNS cache using the command ipconfig /flushdns)

When resolving a domain a host will usually check for an IP address in its local DNS record first. If it cannot find an address it will pass the request on to the DNS server. The problem occurs when neither the local dns record nor the DNS servers’ records are up-to-date. In most cases the DNS servers’ records are out of our hands so the solution is to manually tell the local machine the IP address for a given domain. You can do this by editing the hosts file located in C:\Windows\System32\drivers\etc (the location should be the same for Windows XP/Vista/7). You should edit the file using notepad with administrative privileges. You can do so by selecting your Start Menu -> Accessories and then right clicking Notepad and selecting Run as administrator (This is how I did it using Windows 7).

You can now add the entries for your domain. Each entry should be on its own line and specify an IP address followed by a domain name:

123.45.67.89 mydomain.com
123.45.67.89 www.mydomain.com

You domain should now resolve to the correct host. Note that this does not in any way effect DNS propagation; users who’s DNS servers have not updated their records will still be directed to the old server. You should also note that this method assumes a static IP address; if at some point the IP address of your web server changes the domain will not resolve correctly and the entries will have to be updated or changed. This shouldn’t be much of a problem considering that the entries can (and probably should) be removed once your ISP has updated their DNS records.

Follow Up: MS Vs. EU

Prior to my absence (which was related to me being deathly ill for a week and then having midterms + projects for the subsequent weeks) I wrote about Microsoft’s latest EU troubles, this time relating to Internet Explorer.

In short the EU doesn’t like the fact that IE is the defualt browser on every installation of Windows. The complaint was initially submitted by Opera Software.

It seems now that the EU has decided that Microsoft must offer some other browsers along side IE as well as offer users a choice of which is to be the default. The decision isn’t final, as MS still has a chance for an appeal.

Personally I’m interested to see how Microsoft reacts to this. Ultimately the decision of which alternative browsers(s) to include may fall to the vendors, which may or may not be a good thing. All of the viable alternatives to IE are open source browsers so this decision as very strong implications or the open source community and the companies backing this software, at least for now. My only fear is that, in the case that the decision of which to incorporate falls to the vendors, is that in a few years time there will be a dozen new proprietary browsers generated by the vendors. There’s something unsettling to me about a Dell browsers pre-installed on thousands of computers.

Of course I’m in the US so I won’t be able to witness the effects of this first-hand.