Sunday, August 28, 2011

Running many sites in WAMP environment

What I Wanted
  • unique urls for many local sites
  • easy links to each url 
I develop websites and end up swapping back and forth between lots of sites.  When i tried to do it with the built-in WAMP alias settings, it threw off some of my code that dealt with the urls.  When I tried to fix that, it created problems when I moved my local work to the remote linux servers.  However, by specifying a url in  Apache, I can side step these problems.

Setting up a WAMP environment with local urls for multiple sites isn't all that hard.  I gathered up pretty much all my info from three sites (one, two, three).  Here's the steps for doing that:

1) Download & install WAMP2
It's easy: www.wampserver.com/en/

2) Edit your hosts file
It's located at C:\Windows\System32\drivers\etc\hosts. After this line:
127.0.0.1  localhost
add this: 
127.0.0.1  my.url.com  
Your url can be absolutely anything; a single word, a few letters or a full domain.

3) Edit your httpd.conf file 
The easiest way to do it is just to click on the tray icon, click the Apache folder and select the httpd.conf icon.  Alternately, it will be located inside your wamp install: something similar to "C:\wamp\bin\apache\Apache2.2.17\conf".

After this line (which is probably the last line of your httpd.conf file)
Include "c:/wamp/alias/*" 
add this block: 
NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1> 
ServerName localhost
DocumentRoot "C:/wamp/www/"
</VirtualHost>
<Directory "C:/wamp/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
 
 

For all future domains, you only need to add the VirtualHost and Directory blocks.  Note: it is important to use forward slashes ( / ) instead of backslashes ( \ ).  

4) Visit my.url.com 
It should be up and running now.

5) Modify WAMP index page (totally optional)
I have a tendancy to forge the urls of sites after a few weeks/months, so I wanted the index page to just keep a running tally for me.  Since we didn't change the localhost settings, if you type in http://localhost, you will still get the WAMP index page.  Kinda handy.  Adding two code blocks will display all your local urls on this page.

Open the wamp index.php file located at C:\www\wamp\index.php and add this block of code anywhere near the top (for instance, after the '
isset($aliasContents)' test on line 291).    
 
// get virtual hosts from hosts.txt file$vhosts = '';
$winfile = 'C:\Windows\System32\drivers\etc\hosts';
if(is_file($winfile)){

   $file_handle = fopen($winfile, "r");
   while (!feof($file_handle)) {
        $line = fgets($file_handle);
       if(!(preg_match('/^#/',$line))){
           preg_match('/127.0.0.1\s+([\w._-]*)/',$line,$urls);
           if(count($urls)) {
               $vhosts .= "<li><a href='http://$urls[1]'>$urls[1]</a></li>";
           }
       }
   }    fclose($file_handle);
}

 And  towards the bottom after this block (around 472):


<ul class="utility">
<li>Version ${wampserverVersion}</li>
<li><a href="?lang={$langues[$langue]['autreLangueLien']}">{$langues[$langue]['autreLangue']}</a></li>
</ul>


add this block:

<h2>Local Virtual Hosts</h2>
<ul class="aliases">
${vhosts}
</ul>


This change will give you a nice little list of your local hosts so that you don't have to remember what three letter abbreviation you used way back when.  

Hope that helps. 

Sunday, February 6, 2011

Setting up SVN on MediaTemple DV host

What I Wanted
  • SVN repo
My Case
  • Linux server
  • MediaTemple DV acct
  • Tortiose SVN client  
Article Details
  • I will add more detail when I see some comments on this article.
A client has an account with MediaTemple and I want some kind of version control.  I'm most familiar with using SVN, so that's what I went for.  I haven't been too impressed with the knowledge base for their Dedicated Virtual accounts yet and this project was no exception.  There were several promising articles that just lead me down dead-end paths for hours.  This is what ended up working for me:

1. Install MediaTemple Developer Tools (link)
This will install svn on the host, as well as several other things you'll probably use eventually.

2. Create the Repository:
Follow these instructions, Setting up Subversion in 4 minutes. These links were also useful for me, a novice linux user
  • Problem: "Could not use external editor to fetch log message". 
  • Solution 
  • Problem: How do I reload .bash_profile again?
  • Solution 
    Restart svnserve (if necessary, not sure..):
    1. Get svnserve process id (link)
    2. kill it: kill -HUP  
    3. then restart it: /usr/bin/svnserve -d -r /var/www/svn/repos 
     Checkout repository into empty folder:
    • Using Tortiose, right click on folder and select "SVN Checkout"
    • In dialog that pops up, for url use: svn://ipaddress/repo_name
    • In the password dialog that pops up use whatever you set in the file /var/www/svn/repos/repo_name/conf/passwd