In preparation for this presentation, I've done a fresh install of Mac OS X Tiger on an external drive and patched it up to the latest version. I've also installed a few programs that I use in web development and server configuration, including (but not limited to):
- BBEdit (also alternative text editors like SubEthaEdit and TextWrangler, the latter being free);
- Macromedia Studio MX 8 - for this exercise, only Dreamweaver MX 8 will be used;
Can it get easier than this?
The quickest way to enable the web server on your Mac is by going to System Preferences>Sharing, and then ticking the Personal Web Sharing tick box, as shown below:
Note that this will allow you to access your server via these urls:
|Main Server||User's Sub-sites|
other bon jour
|via IP address||http://xxx.xxx.xxx.xxx||http://xxx.xxx.xxx.xxx/~username|
Your static web site files
At this stage, you can decide where you want to work - either using the main directory at
Personally, I tend to work in the
Sites directory on my machine. When I get a new web project, I create a new folder with the project name and can then go to
http://localhost/~ricardo/project_name/ to view the work.
Another useful tip - drag your
Sites directory and/or the
/Library/WebServer/Documents/ to the Sidebar in the Finder for easy access to your web page directories.
But I want a dynamic site!
After creating a few html files and linking them to each other, eventually you might get bored and want to create pages on the fly or have information displayed due to the time of day, season, whether the user is logged in, whether the user has a specific role on a site, or any innumerable sets of criteria you put your mind to. Think Amazon, Apple Store, forums, guestbooks, newsletter subscriptions, etc.
Once again, the process for setting up this ability on your Mac is very straight forward.
As seen from the static pages, the web server shipped with OS X is Apache, which is the most popular web server dishing out pages on the Internet. Unlike your standard desktop applications, to adjust the preferences for the Apache server, we will have to dig around under the hood and adjust a specific text file here:
There are many ways to get to this file, but I'd like to show you the simplest way on the Mac. Go to the Finder's Go menu and choose
Go to Folder... as seen on the left.
You can then enter the path to the
/private/etc/httpd/ here. You will then be able to double click on the file to open it. I've noted on this installation I've done, that the default editor for
.conf files is SubEthaEdit, of which I'm not extremely familiar with. I'm certain it will do the job, as will TextWrangler, but I'm going to use BBEdit to make my changes.
I've been a user of BBEdit for years (read - yearly upgrades for features I'm fairly certain I never use). It has built-in tools to allow you to edit files owned by root. There are four lines of which we will uncomment (remove the # at the beginning of each line):
LoadModule perl_module libexec/httpd/libperl.so
LoadModule php4_module libexec/httpd/libphp4.so
After saving the file, we will need to restart Apache, and we can do this by turning web sharing on and off in System Preferences>Sharing:
Is it dynamic then?
To see if we've got PHP running, create a new text file in our
Sites folder with just this in it:
<?php phpinfo(); ?>
saving it as phpinfo.php and then navigating to http://localhost/~username/phpinfo.php, we should see a full listing of the features that this PHP installation provides, as well as other environmental variables Apache supplies.
Where do we go from here
Subscribe to this how-to at http://www.siliconmeadow.net/mac-as-web-server , as I will be adding the mySQL portion shortly.