Set up virtual hosts for MAMP

If you use the free version of MAMP this is the simple way to set up virtual hosts –

in /private/etc/hosts add a line for each virtual host like:

127.0.0.1 vhost.local

Then, as described in Supercharge Your MAMP Environment, create a vhost conf file with an entry for each virtual host like:

<VirtualHost *:80>
    ServerName vhost.local
    DocumentRoot /Applications/MAMP/htdocs/vhost.local/
    <Directory /Applications/MAMP/htdocs/vhost.local/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>
 

The above works fine for a few sites that change infrequently, but quickly becomes a hassle to manage if you have many sites. The method posted on postmodern.com may be an option. It did not work for me.

I’m now using MAMP PRO which I’ll write more about in another post.

Simple MAMP setup

Since I switched back to Mac two years ago, I’ve been using Marc Liyanage’s PHP build for Mac to run my local dev environment. I never got all rewrites to work correctly on my local setup, which meant I could only do limited local testing for one site. A few weeks ago, after reading a series of php framework articles by Bart McLeod in php|architect, April-June 2008, I decided to give Zend Framework a try and set up a new site using it. However with my old dev environment, I could not even get the simple Quickstart app on the ZF site to work. So I went in search of another solution and decided to try MAMP and MAMP PRO. MAMP PRO hung on the MySQL start up, but I got a simple test environment set up with the free version of MAMP. It works with ZF, just need to change the rewrite rule from /index.php to index.php, and I was quickly able to get rewrites to work for the other site I mentioned. (Note: my quick fix of removing the leading slash would cause problems with urls in a subdirectory structure. Setting up virtual hosts should solve that.)

Here are the steps I used:

  1. Download MAMP
  2. Drag MAMP to Applications folder.
  3. Launch MAMP app
  4. Click “Preferences” button
  5. Go to “Ports” tab and click “Set to default Apache MySQL ports”
  6. In “Apache” tab change “Document Root” to /Users/[username]/Sites

Access your sites at http://localhost/[foldername]

There is a lot more you can do to customize MAMP; see the living-e forum and Supercharge Your MAMP Environment for some examples. In the meantime, the above should get you up and running within five minutes of completing the MAMP download.

Need to view hidden files in Leopard?

It’s easy to view hidden files in Windows. A little more difficult on a Mac. Here is a post about how to create a couple scripts to hide/show hidden files using Apple’s Automator. You can just type the commands into the terminal if you rarely need to view hidden files.

Using the terminal you just need the following to show hidden files:

# defaults write com.apple.Finder AppleShowAllFiles YES
# KillAll Finder

To rehide type:

# defaults write com.apple.Finder AppleShowAllFiles YES
# KillAll Finder