How to Turn your Desktop PC or Laptop into a Test Web Server

If you do any kind of web programming, it can become tedious to continuously upload and test your code on a remote server. One solution is to set-up a test server on your laptop or desktop computer, thus skipping the uploading part. Here’s how you can do it on either a Windows or Linux platform…

Photo by Whrelf Siemens

First thing you want to do is create fake hostnames that resolve to the localhost address, 127.0.0.1. You can create totally fictitious  hostnames or override real ones. On a Linux machine, edit the file /etc/hosts, while on Windows, it’s located at C:\Windows\System32\drivers\etc\hosts – make sure it’s writable/modifiable by users. For each hostname you need, add a line similar to the following to the hosts file:

127.0.0.1   www.fakedomain.com

Next, install the latest version of the Apache  web server (yes, on Windows too). Note that if you have Skype installed on a Windows computer, you’ll have to disable it by opening the task manager and killing all the Skype processes running. You’ll have to do that every time you boot your computer unless you uninstall Skype, as it intentionally listens on port 80. You could alternatively modify the Apache config (httpd.conf) and make it Listen to a different port, but this will force you to use ugly urls with the port number in your tests. Find and edit the file conf/httpd.conf in the Apache install directory, changing the Listen instruction to:

Listen 127.0.0.1:80

This will insure against Apache being open to the outside world. If you’re using a different port than 80, than the line above should be changed to the correct port. If you want to use several fake hostnames in your test web server add this line to httpd.conf:

NameVirtualHost 127.0.0.1

And create a virtual host. For example:

<Directory C:\htdocs>
Options All
Order allow,deny
Allow from all
DirectoryIndex index.php index.html
</Directory>
<VirtualHost 127.0.0.1>
ServerName www.dingdong.com
DocumentRoot C:\htdocs
</VirtualHost>

Next, install the latest version of php, or re-launch its installer if you already have it (choose “change” in the first screen), and make sure you select “Apache  2.*  module” in the Web Server Set-up screen. If you’re working with a Linux computer, follow the same installation instructions from the php web site, exactly as if you were setting-up on a real server.

If you did everything right, you now have the perfect testing environment!

VN:F [1.9.8_1114]
Rating: 4.0/5 (5 votes cast)
How to Turn your Desktop PC or Laptop into a Test Web Server, 4.0 out of 5 based on 5 ratings

Related Articles:

  • No related article

Tags: , ,

0 responses. Leave a Reply

  1. Tom Germain

    Today

    Be the first to leave a comment!

Leave a reply

(Required)
(Required, but never shared)