Test projects viewer

I have a couple of test projects in my test directory. This is where I usually put the latest wordpress, phpBB or any other script or web software I would like to test out or develop and play with. Until recently I had to access those by writing the virtual host path (www.test.local) and then append the directory name (in.eg. /drupal). I got tired of it, and coded a nifty little “browser” which displays all of the directories and files. Combined with the DNS wildcards, you can have unlimited virtual domains without having to configure them in vhosts, setting the /etc/hosts and restarting apache server. I have included this in the zip file found at the end of this post.

We are using bind dns server to resolve everything that comes to the “test” domain to your machines IP address. After that, Apache takes care of the rest. And what he does is kinda cool. The .htaccess file has a set of rules to test weather the index.php exists in the requested directory (via subdomain), and if it does, he redirects us to that directory. If the index.php doesn’t exist, our “main” index.php shows the contents of that directory, so you can select any other file and run it. Let’s start.

Setting up your DNS server under Ubuntu is best described here. I will only display contents of my files, so you know what to do. My hostname (/etc/hostname) is “ubuntu” and IP address of my machine is 192.168.253, so when ever you see one of those, change to your settings. To install bind, use synaptic (search for bind9), to start, stop or restart bind, pass those commands to /etc/init.d/bind9, i.e. “/etc/init.d/bind9 stop”. To edit the files I used vi, and I also had to be root, so I ran sudo -i to become one.

/etc/hosts

192.168.1.253 ubuntu
192.168.1.253 www.test.local test.local

/etc/bind/named.conf.local

acl "local" {
192.168.1.0/24;
127.0.0.1;
};
zone "test" {
type master;
file "/etc/bind/zones/db.test";
allow-query { local; };
notify no;
};
// For reverse DNS
zone "1.168.192.in-addr.arpa" {
type master;
file "/etc/bind/zones/rev.1.168.192.in-addr.arpa";
allow-query { local; };
};

/etc/bind/named.conf.options


options {
directory "/var/cache/bind";
forwarders {
192.168.1.254;
};
auth-nxdomain no;    # conform to RFC1035
listen-on-v6 { any; };
};

/etc/bind/zones/db.test

$ORIGIN .
$TTL 86400 ; 1 day
test IN SOA test. (
200904031 ; serial number (todays date appnded with '1')
10800 ; refresh (3 hours)
3600 ; retry (1 hour)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
$ORIGIN test.
@ NS ubuntu
ubuntu A 192.168.1.253 ;This is the hostname & ip of my computer
test CNAME ubuntu
*.test CNAME ubuntu

/etc/bind/zones/rev.1.168.192.in-addr.arpa

$ORIGIN .
$TTL 86400 ; 1 day
1.168.192.in-addr.arpa IN SOA test. (
200904031 ; serial number (today's date appended with '1')
28800 ; refresh (8 hours)
14400 ; retry (4 hours)
3024000 ; expire (5 weeks)
86400 ; minimum (1 day)
)
$ORIGIN 1.168.192.in-addr.arpa.
@ NS ubuntu
253 PTR ubuntu ;The 253 is the last octet of my machines ip address

After the bind has been set up, restart it, and test it. You should make a virtual host that points to www.test.test. Now, if you type anything else as subdomain, you should get the test.test page again. Try with something.test.test, or anythingelse.test.test.  For apache setup i have “NameVirtualHost 192.168.1.253” in the main config and use


ServerName      test.test
ServerAlias     *.test.test
DocumentRoot    "/path/to/test"

for every subdomain i need.

We now have our environment set up, and need the contents of the test directory displayed. For that we use the index.php to list the directories and files. The directories are linked to be the subdomains. Now, if you do get to the directory which does not include index.php, it’s contents will be displayed, and you will be able to click the file you want to run. This is handled by .htaccess. If you type the wrong subdomain, you will get a notice about missing directory. I still didn’t get directories with uppercase letters or dots to display, but this is enough.

I also did a brief search for the theme, and used one to display the content, so it has the feeling of a finished project, not my usual html without the css or even parts of html without the html, head and body parts :). Somehow I couldn’t justify using smarty here :), so i did str_replace to modify the content of the template. Here is the download link so you can put it in the /test dir and see all your projects. Tell me what you think of it.

Test environment viewer