Articles from Thursday, 08/23/2007
Local Web Development on your Mac, Part 2
By David Rogers in Tutorials and Development
So in the last article , we addressed getting started in the simplest of ways: download and install MAMP, an all-in-one standalone Apache + mySQL solution. MAMP, in fact, stands for: Mac, Apache, MySQL, and PHP. Like LAMP , although the ‘P’ in both technically stands for any of the “P-type Languages”: PHP (official site), Perl (semi-official site), or Python (official site). See, Ruby (official site), stick around long enough and you’ll get an acronym with all the other guys! Of course, we’ve lost all hope for Java getting in on this crazy acronym action.
So we’ve got a default, boring install of MAMP running on our local machine. How exciting. But wait, there’s more. Last time, I hinted that there was an Apache config file running around that we could mess with, and mess with it, we will!
First locate your favorite text editor, preferably one that handle plain text well, not RTF. TextEdit will do, if properly set, but I prefer something with a little more power (TextMate by MacroMates is a favorite or TextWrangler by BareBones SW for the real cheapskates). Get that running and go looking for a file, specifically: /Applications/MAMP/conf/apache/httpd.conf – the MAMP Apache config file.
It’s strongly recommended at this point that you make a backup of this file (let’s call it httpd.conf.bak), since we’re making some pretty destructive edits. If you’ve never seen the inside of an Apache config before, don’t sweat it. It’s essentially a big plain-text file that tells Apache exactly what it needs to know to do it’s job. Screwing it up just means that Apache won’t run. No pressure, right?
Follow my directions and we’ll get through this; resist the temptation to mess with other things. It can be bad. We’re going to modify a couple distinct sections, which you can search for with a “Find…” action. They shouldn’t appear more than once.
First, find the line that starts with “Listen”. Each of the lines in an Apache config has one command that Apache recognizes, called a Directive; the “Listen” directive tells Apache which ethernet ports to listen to for incoming web page requests (HTTP traffic, technically). If you scanned the Preferences for MAMP and have a good memory for numbers, you’ll recognize 8888.
Your default Apache (called “Web Sharing” in OS X) is setup to listen to port 80, the default HTTP port, and we don’t really want to override that (could be useful for something else, after all). I don’t really care for the default MAMP setting, so I use port 8080 instead. Therefore, we change the Directive from Listen 8888 to Listen 8080; what could be easier?
Next, jump to the end of the file. There should be a Directive “NameVirtualHost” that’s disabled with pound/number signs (#). In config files like this one, pound symbols indicate comments, and you should have already seen a lot of them. We’re going to un-comment that line and edit it to read NameVirtualHost *:8080. Wait, what does that do?
Short story: it allows us to add Virtual Hosts (via the “VirtualHost” Directive) hereafter that act as full-fledged websites of their own (see the official Apache Web Server documentation for the long explanation). These can be served from anywhere your Apache process can see (as in “has read and index/execute access”) and can be named practically anything you want; great for project development.
I typically use analogs of the project’s actual URL but replace the TLD (”.com”, “.net”, “.org”, etc) with “.local”. Once these are setup, you’ll have a different local domain for each project, which is immensely helpful for development. You can modify the behavior of Apache for each VirtualHost definition via Directives in a local .htaccess file, mimicking a particular production server very closely.
In the next part, I’ll show you how to setup these Virtual Hosts via the VirtualHost directives in external configuration files. Ready? On to Part 3…
Comment
Commenting is closed for this article.
←Local Web Development on your Mac, Part 1
Search Articles
Categories
News & Bulletins
08/21/07
Hermes is on its way...
Built on Zend Framework for PHP5, Hermes is a RAD Platform that handles some of the basic application logic using components and conventions established in ZF, like basic authentication, model instantiation, and external configurations. More to come as we get closer to launch!
New Site Desgin!
So we finally gave the site a much needed face-lift, and there’s more than just a make-over going on. You’ll note that the site is now published with Textpattern as well! Easier updates mean more frequent updates!