Note the following applies to Windows Vista, but is probably easier on MacOS/Linux.
Is your hosts
file becoming monstrous? Do you have an alias or shortcut to your hosts
file because you edit it so often? Tired of manually adding every subdomain and domain you work on?
I was too when I thought there must be a better way. And there was.
The general idea is this: by installing a local DNS nameserver in BIND, we can set up local development domains that look like regular domains on the internet. For real domains, we’ll just forward the requests on to a real nameserver. This gives us a couple more benefits: 1) we can use the local nameserver as a caching nameserver to speed up DNS queries (in theory, I have not actually done this), and 2) we can choose to use any DNS service we wish, i.e. OpenDNS, or Google DNS.
Here are the steps.
C:\Windows\system32\dns
.named.conf
in its entirety.
options {
directory ";c:\windows\system32\dns\zones";
allow-transfer { none; };
forward only;
forwarders {
//208.67.222.222; // OpenDNS
//208.67.220.220;
8.8.8.8; // Google DNS
8.8.4.4;
};
query-source address * port 53;
};
/*
logging {
channel queries_log {
file "c:\windows\system32\dns\var\queries.log";
print-severity yes;
print-time yes;
};
category queries { queries_log ; };
};
*/
zone "work.local" IN {
type master;
file "work.local.txt";
};
key "rndc-key" {
algorithm hmac-md5;
secret "xxxxxxxxxxxxxxxxxxxxxxxx";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
CNAME
wildcard record.
$TTL 86400
@ IN SOA ns1.work.local. admin.work.local. (
2008102403
10800
3600
604800
86400 )
@ NS ns1.work.local.
IN A 127.0.0.1
ns1 IN A 127.0.0.1
www IN A 127.0.0.1
* IN CNAME www
C:\> ipconfig /flushdns
www.work.local
. If you have errors, you can uncomment the logging block in named.conf
.VirtualHost
in Apache for your development domain. Thanks to VirtualDocumentRoot
, we can map any number of subdomains to project roots. Here is my VirtualHost
block.
ServerName www.work.local
ServerAlias *.work.local
VirtualDocumentRoot "C:/_work/%1"
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
C:\_work
, for example, C:\_work\awesomeapp
. Create a test index.html file in that directory.Now, you should be able to repeat step 8 for any new website you create! No editing of hosts
files, no bouncing the webserver! Just create the project directory and it’s immediately available.
One other important note: Firefox has its own DNS cache independent of the OS. For sanity, restarting Firefox resets its DNS cache. You can also permanently disable DNS caching in Firefox.
Well, it only took me 18 months, but I finally got around to cleaning up and publishing the Phing filters we use to automatically transform a static site into one that implements many of Yahoo’s Exceptional Performance Rules. These filters, together with the Apache configurations in the README, implement the process outlined in this talk from php|works 2008:
To see it in action, first create an VirtualHost
pointing to the mysite
directory in the project as the web root. Then run:
% phing optimize
which creates a parallel site in a build
directory. Point your VirtualHost
to the new build
directory to see the same site with the performance transformations.
You could run this Phing task in a continuous integration process as part of deployment. You could run it at production deployment time, but it’s probably a good idea to run it at staging time in case it flubs on some CSS or HTML syntax that it is not expecting.
Note that there are other miscellaneous Phing tasks in that github project. I threw these in there in case they could be of use to other Phing users.