Posted by & filed under Lessons Learned.

After setting up all our Mac’s, we thought our one windows machine deserved a bit of love too. Here’s what we did. If you have a setup you love, we’d like to hear about it! See this for setting up on Mac OS X.

Goals of our setup

  • Create a local development environment for Apache, mySql, PHP and Perl
  • Set a wildcard local development domain (e.g. *.42u.local)
  • Integrate with our SVN Repositories

Our tools of choice

  • Windows (flavor of your choice)
  • Dreamweaver
  • TortoiseSVN (SVN client)
  • WAMP (this is a nicely bundled apache, mysql, php bundle)
  • Allway Sync

Let’s get started.

Portions of this tutorial were adapted from the very nice instructions by Axertion here and Don Don’s Garage here.

Set up our local webserver

Install WAMP

Get it here: http://www.wampserver.com/en/
It installs the PRO version along with the free version. Set the general server settings. We generally set these to the defaults. Make sure you set a good root password for MySQL too!

Download and install the PHP add-on for PHP 5.2.9-2
We need this because the default that comes with WAMP is php 5.3.X; our production server is 5.2.9

Set up virtual hosts

Create the folder which will hold your subdomains

For example. Create the following folder:
C:\wamp\www\subdomains

Each folder contained within the subdomains folder will essentially become a subdomain.
For example: example.localhost.com will point to C:\wamp\www\subdomains\example\

Make sure httpd-vhosts.conf file is included.

Open C:\wamp\bin\apache\Apache2.2.21\conf\httpd.conf (or choose Wampserver > Apache > httpd.conf)
Find the lines:
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf

Change to:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Configuring Apache VirtualHosts

Enable the alias_module and vhost_alias_module for apache.

Doing this will enable virtualhost aliasing in apache for your subdomains.

Open C:\wamp\bin\apache\Apache2.2.21\conf\extra\httpd-vhosts.conf

In the httpd-vhosts.conf file, you’ll most likely see some example data.  Replace everything with the following:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName 42u.local
    ServerAlias www.42u.local
    DocumentRoot "C:\wamp\www"
    ErrorLog "logs\errors.log"
    <directory "C:\wamp\www">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName 42u.local
    ServerAlias *.42u.local
    VirtualDocumentRoot C:\wamp\www\subdomains\%1
    ErrorLog "logs\errors.log"
    <directory "C:\wamp\www\subdomains\%1">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

So what’s going on with the code above?

Each <VirtualHost> tag contains a host definition.   The asterisk in <VirtualHost *:80> tells apache that any IP address can be used to access this host definition.  If you wanted to restrict it to just your computer, you could do <VirtualHost 127.0.0.1:80>

ServerName
ServerName 42u.local

ServerAlias
ServerAlias *.42u.local
An alternate domain alias (usually www.localhost.com)

DocumentRoot
DocumentRoot "C:\wamp\www"
The absolute directory to your domain’s root (accessed by going to localhost.com)

ErrorLog Path to your error log.  This is optional.
ErrorLog "logs\errors.log"

VirtualDocumentRoot
VirtualDocumentRoot C:\wamp\www\subdomains\%1
The absolute directory for your subdomain, with a wildcard to define the subdomain’s name.  I use a wildcard %1 to get the name of the subdomain. example.localhost.com will point to C:\wamp\www\subdomains\example

<directory ________>
<directory "C:\wamp\www">
<directory "C:\wamp\www\subdomains\%1">
The directory permission definitions. Defined twice for both localhost.com and it’s virtual subdomains.

After making the changes to your httpd-vhosts.conf file, you must restart apache for the changes to take effect.
Just click the WAMPSERVER icon in your Notification Area and choose “Restart All Services”.

Install BIND DNS Services

  1. Download latest BIND zip for windows: https://www.isc.org/software/bind
  2. Unpack and run: BINDInstall.exe
  3. View: C:\windows\system32\dns\bin\readme1st.txt
  4. Start->Run: C:\windows\system32\dns\bin\rndc-confgen -a
  5. Update named.conf with the key from your rndc key file, and make sure that teh directory option is set to the actual location of your dns install (either \system32 or \syswow64).
  6. Use Explorer, navigate to c:\windows\system32\dns, right click “etc”, properties, security, add, “named”, click “full control”, OK, OK
  7. Download ftp://ftp.internic.net./domain/named.root and save it to C:\windows\system32\dns\etc\named.root to seed BINDs root hints.
  8. Use Windows Services to start/stop the Named Service
  9. Start -> Right-Click “My Computer”, manage , click “Services”, Look for “ISC BIND”, Right-Click start,stop, or restart.
  10. Start -> Right-Click “My Network Places”, properties, Right-Click your active “Local area connection”, properties, click “Internet Protocol (TCP/IP)”, properties, Use following dns server: 127.0.0.1

Download all the DNS config files detailed below here.

C:\windows\system32\dns\etc\named.conf is as follows:

options {
     // version statement - inhibited for security
     // (avoids hacking any known weaknesses)
     version "get lost";
    // optional - disables all transfers
    // slaves allowed in zone clauses
    allow-transfer {"none";};
    forwarders {8.8.8.8; 8.8.4.4;}; //GOOGLE Public DNS
    directory "C:\WINDOWS\system32\dns\etc";
};
// this key needs to be updated with your actual key from the rndc.key file
key "rndc-key" { algorithm hmac-md5; secret "xxxxxxxxx=="; };

controls {
inet 127.0.0.1 port 953 allow { localhost; } keys { "rndc-key"; };
};
view "trusted" {
    match-clients { 192.168.0.0/16; 127.0.0.1; }; // any private class c and localhost
    recursion yes;
    // required zone for recursive queries
    // retrieve from: ftp://ftp.internic.net./domain/named.root
    zone "." {
       type hint;
       file "named.root";
     };
    // basic localhost support
    zone "localhost" in{
        type master;
        file "master.localhost";
    };
    // basic localhost support
    zone "0.0.127.in-addr.arpa" in{
        type master;
        file "localhost.rev";
    };
    // this is the wildcard zone
    zone "42u.local" {
        // Don't forward queries for this zone.
        forwarders {};
        type master;
        // The final extension of .txt simply is so that Windows doesn't
        // think the file is executable (.com), and will open the file with your
        // systems designated text editor without any fuss.
        file "42u.local.txt";
    };
};

view "badguys" {
    match-clients {"any"; }; // all others hosts
    // recursion not supported
   recursion no;
};

C:\windows\system32\dns\etc\42u.local.txt is as follows:

$TTL 2d    ; 172800 secs default TTL for zone
$ORIGIN 42u.local.
@             IN      SOA   ns1.42u.local. hostmaster.42u.local. (
     2009120500 ; se = serial number
     12h        ; ref = refresh
     15m        ; ret = update retry
     3w         ; ex = expiry
     3h         ; min = minimum
)
     IN      NS      ns1.42u.local.

; Retrieve the IP for the target of the wildcard
; Linux: ifconfig
; Windows: ipconfig
@             IN      A       127.0.0.1

www           IN      A       127.0.0.1

; Retrieve the IP for the DNS server
ns1           IN      A       127.0.0.1

*             IN      CNAME   www

C:\windows\system32\dns\etc\localhost.rev is as follows:

$TTL    86400 ;
; could use $ORIGIN 0.0.127.IN-ADDR.ARPA.
@       IN      SOA     localhost. root.localhost.  (
    1997022700 ; Serial
    3h      ; Refresh
    15      ; Retry
    1w      ; Expire
    3h )    ; Minimum
        IN      NS      localhost.
1       IN      PTR     localhost.

C:\windows\system32\dns\etc\master.localhost is as follows:

$TTL    86400 ; 24 hours could have been written as 24h
$ORIGIN localhost.
; line below = localhost 1D IN SOA localhost root.localhost
@  1D  IN     SOA @    root (
     2002022401 ; serial
     3H ; refresh
     15 ; retry
     1w ; expire
     3h ; minimum
)
@  1D  IN  NS @
1D  IN  A  127.0.0.1

To test your new caching dns server for resolving the local wildcard domain: Start->Run: “cmd”, then type “nslookup whatever.42u.local” at the command prompt.

If it doesn’t work and you can’t browse the web anymore, Look at step 9 and set dns back to “obtain DNS server address automatically”, or to 8.8.8.8 and 8.8.4.4, to go direct to Google’s DNS. You should also look at your Event Viewer to discover any errors, See step 8, except select the “Event Viewer” instead of “Services”, then look at the “Application” log.

Check if your subdomains work.

Start WAMP and test it out. In this example, we should get the default WAMP page when we go to http://example.42u.local
Apache should now be serving files for that subdomain from C:\wamp\www\subdomains\example

Install content into our shiny new document root.

For us, this is generally a clean WordPress Network install.

First do the Famous 5 Minute Install.

Follow that immediately with the Network Setup

Download and install our base network plugins:

  • Jetpack
  • All in One SEO
  • Custom Admin Branding
  • 42u HTML5 Upgrade
  • Edit Flow
  • Backup Buddy

Set up Subversion

The Repository

For our published WordPress plugins, we use the WordPress SVN repository. For our themes, perl modules and unpublished plugins, we use Beanstalk. Beanstalk is cool. We handle all our deployments right out of the Beanstalk cloud. Click. Done.

TortoiseSVN

TortoiseSVN is a really easy to use Revision control / version control / source control software for Windows.
Get it here: http://tortoisesvn.tigris.org/

Sync the trunk to the wordpress root

For themes and plugins we use the Allway Sync app to keep the files in the WordPress root in sync with the trunk.
This frees us from the change/upload/test/revise cycle.

Leave a Reply

  • (will not be published)