Use Mac as a Web Server (1/5)
Posted by Wesley on
This article serves two purposes: to show what steps are needed to have a functioning website running on a Macintosh computer, and to remind myself not to forget how to do this later. Yes, I must be dumb.
Okay, you need:
- A Macintosh computer (mine is a Mac mini)
- Mac OS X 'Panther' 10.3.9 or higher (mine is running 'Tiger' 10.4.1)
- Internet connection (direct, or through a router that you can configure)
Okay, you need:
- A Macintosh computer (mine is a Mac mini)
- Mac OS X 'Panther' 10.3.9 or higher (mine is running 'Tiger' 10.4.1)
- Internet connection (direct, or through a router that you can configure)
I'm assuming the OS X installation is of a normal edition, not Server edition. OS X Server already integrates much of the tools needed and configured, so you can skip a large portion of this guide already.
1. Apache
OS X already has Apache web server software integrated (1.3 for normal, 2.0 for Server), so we're off to a good start. To enable this, open System Preferences, and locate 'Sharing' under 'Internet & Network'.
You will notice 'Personal Web Sharing' checkbox under 'Services' tab. Click the checkbox and you'll have the server running instantly. The address to access your instant website is shown at the bottom. Go there and make sure the default pages load. Where are the files, though?
http://address/ --> /Library/WebServer/Documents/
http://address/~username/ --> /username/Sites/
A couple of things to note: 'Library' goes to the root of the Macintosh HDD, not under the username folder, and the ~(username) address looks uncool. Unless the Mac is being used by several people I think we can just go for the first address. The original 'Documents' folder contains default Apache server docs and stuff, so I moved it out elsewhere and have an empty Documents folder for a clean start. From now on I'll refer to this folder as the 'root' since it is the root folder of the website.
Make a simple index.html file on the root to check that you can load the page. That's cool and all, and if static HTML pages are your thing (as I was until this year) then you can skip bunch of stuff and go right into getting a working URL. But as I found out, man, static pages are boring.
2. PHP
The first step to a not-so-boring website is putting PHP: Hypertext Preprocessor, or PHP for short, running on this setup. It's a versatile scripting language that can create dynamic web pages. In other words, it saves you a lot of pain from actual work once you have it do your bidding.
You can read about the PHP by going to the official website I linked above. What we need is an actual installation package. This is where Marc Liyange's PHP module created to work with Apache in OS X comes in handy. I scrolled down to 'Installation Instructions' and got the "PHP 5.0.4 for Apache 1.3" package (version number may change).
Once the .dmg file is downloaded, open it and run the 'php-5.0.4.pkg' package installer. Follow the instructions to finish installing, then make the test page as mentioned in Marc Liyange's site to check that it's working.
With the installation this easy, there's almost no reason for putting off installation. A lot of stuff out there uses it to function and you don't even have to know how to program in PHP to use them, so you miss out a lot if you don't install PHP.
Next up is MySQL. This could be slightly tricky.