Turn Your Box into a Dev Web Server

To turn your box into a dev web server is pretty simple, yet I’ve seen people struggling with this over and over again, so here’s a simple TODO list.

I won’t go over the likes of Apache installation, VirtualHost setup, .htaccess settings, etc. as you can find these online very easily, and might be specific to the needs of your project.

Most of the time I see people using localhost:8080 and a myriad of other ports to work on several sites locally; but you might as well work on http://www.myproject.com locally in just 2 simple steps:

  • Create a VirtualHost in Apache which goes by “the name” http://www.myproject.com, by including the following within the definition:
    <VirtualHost *:80>
        ServerName www.myproject.com
        DocumentRoot /var/www/myproject/
        # all the other options and definitions ...
  • “Register” the domain name locally – simply add the following line to your /etc/hosts file (on Windows, this file is typically located under [Windows]/System32/Drivers/etc):    www.myproject.com

Now enable the VHost in Apache, restart Apache, and open http://www.myproject.com in the browser, and you’re ready to code off!

Note: The VHost name need not be a valid domain name – feel free to use myproject as ServerName and in /etc/hosts; just beware that some browsers will try to search for “myproject” instead of opening the local site. In such case, type in the whole http://myproject.

2 responses to “Turn Your Box into a Dev Web Server

  1. Thanks for posting this nice concise example of how to set up a development Apache server. I have to say though that this only reinforces my impression of Apache as difficult to configure – changes to /etc/hosts, just to deploy a web server process! In contrast I routinely start thttpd processes ( http://www.acme.com/software/thttpd/ ) as development servers using just a one-line bash command.

  2. Hi, thanks for the comment!

    Yes, Apache might get “difficult” to configure, just like any other generic system (web server, search engine, DB engine). On the other hand, there are simple patterns you may follow, and then the miss-ratio is very small.

    Side note – the change to /etc/hosts is only so that your browser sees the “dummy” domain as a localhost-domain, it’s not part of the Apache configuration per se.
    Except for the case where web server is run as part of the IDE (e.g. Zend Studio that translates URL’s on the fly within itself), you’d have to alter either /etc/hosts or your DNS service with any web server you use.

    If you don’t need to use “domain” addressing for development, or you have just one site to serve, vanilla installation of Apache is all you need, and is as simple to run as any other web server.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s