Easy Mac Web Dev Server Setup

Uploading files to design, develop, and test Web pages on a remote server takes up valuable time and it interrupts the creative flow. Wouldn’t it be great if we could do all of that on our own machine and then upload a completed project?

What we need is our own Web development server, preferably something like we’re used to working with in the real world. Apache sounds nice and MySQL and PHP would be icing on the cake. Also, while we’re making outrageous demands, we’d like to do it the Mac wayâ??with minimal muss and fuss. Ooh, and we’ll get bonus points if we can do it all for free!

The three applications we mentioned (Apache, MySQL, and PHP) are all industrial-strength, open source software that happen to be free, so we’ve already addressed two of our three requirements. Installation on our Mac OS X system (10.3+) is where the solutions differ and there are several approaches we can take (from hardest to easiest):

  • Compile source code. This is the way your great grandparents did it. They’d search through mail-order catalogs for all the dependent files they’d need, load the punch cards, flick a switch, and go out to the stream to wash their clothes while waiting for the concoction to compile. It was time-consuming, back-breaking work and was fraught with peril. One wrong configuration choice or a UNIX command out of order resulted in one goober of a mess. Not much has changed since then. The upside of compiling is that you have more control over the way the application is built (i.e., you decide whether you are building a Yugo or a BMW).
  • Compile with Fink or DarwinPorts. With ports, links to the dependent files have already been made so all you have to do is choose a package to install and then wait out the lengthy compilation process. Of course, you’re depending on the people that made the links to know what they were doing so your Mac’s internals didn’t get all goobered up.
  • Install pre-compiled binaries. Some applications have come a long way in making their installations fairly painless. There’s still a bit of command-line work required for tweaking configurations and the slight risk of goobering up things as a result.
  • Start up Personal Web Sharing (PWS). Much of PWS is already installed in Mac OS X. Adding MySQL and PHP, however, does require some courage.
  • Install pre-packaged binaries. MAMP and XAMPP provide amazingly easy drag and drop solutions. They’re self-contained and just as easy to dispose of. The goober factor is almost nil.

We’re going to take a look at the last two approaches to installing our Web development server. (As a final note before we begin, we’re setting up a development server not a production server. The distinction is necessary because setting up a production server would require exposing our Mac to the entire World and all the scary security risks that exist out there. With our development server set up, we’ll have less to worry aboutâ??see Security below.)

Personal Web Sharing

There is no easier way to set up a basic Web server on the Mac than with PWS:

  1. Open System Preferences â?? Sharing.
  2. Check the Personal Web Sharing box (under the Services tab).

Poof! You are now running the Apache 1.3 version that came loaded with OS X. Open a browser to http://localhost/~[username]/ (replace [username] with your username–in case you forgot it, it appears next to the home icon in Finder) and you’ll be greeted by a welcome page and some instructions on what to do next. Cool, huh?

PWS+MySQL+PHP

So let’s say you’ve outgrown the plain-old HTML pages and you want to graduate to something a bit more dynamic. It’s time to break out the MySQL and PHP. Some of the following steps require administrator privileges and involve poking around the UNIX command line with Terminal (located under Applications/Utilities), so if you’re a bit squeamish there’s no shame in jumping to the MAMP section.

MySQL Installation

OS X also comes with PHP preloaded, but we’re going to need to wake it up. Before that, however, we’re going to install the MySQL database. MySQL really used to be a challenge to install, requiring a lot of cryptic command line work. Fortunately for us, there are now some very nice binaries (ready-made programs) that make life a whole lot easier (you can still use the command line if you wish):

  1. Download the latest Mac OS X binary of MySQL (standard) (and MySQL Administrator and MySQL Query-Browser while you’re at it).
  2. Install the MySQL standard package file (e.g., mysql-standard-5.0.18-osx10.4-powerpc.pkg).
  3. Drag the MySQL.prefPane file to the /Library/PreferencePanes folder in your local hard drive (e.g., Macintosh HD).
  4. Open System Preferences â?? MySQL.
  5. Click on Start MySQL Server to start the database (make sure PWS is already started).
  6. Install MySQL Administrator.
  7. Start the MySQL Administrator application with Server Hostname=’localhost‘ and Username=’root‘ (leave Password empty).
  8. Go to Accounts, select root from the accounts, create a password, and then save changes.

PHP Configuration

Now we can go back and wake up PHP with a little couple of configuration file changes.

  1. Open the /etc/httpd/httpd.conf (Apache configuration) file with your favorite text editor (the free TextWrangler is an excellent choice since it easily opens hidden folders like /etc). (note: you may wish to save a copy in case you need to undo something later.)
  2. To enable PHP, remove the ‘#‘ characters from the beginning of the following two lines and then save.
    1. LoadModule php4_module libexec/httpd/libphp4.so
    2. AddModule mod_php4.c
  3. Open Terminal (here comes the UNIX).
  4. At the prompt, type (or copy this line) sudo cp /etc/php.ini.default /etc/php.ini and hit return. Enter your username password and that’s it. We just made a copy of the PHP configuration file. There’s no more UNIX.
  5. Open /etc/php.ini in your text editor, find the mysql.default_socket = line, add /tmp/mysql.sock to the end (i.e., mysql.default_socket = /tmp/mysql.sock), and save. This will tell PHP where to find MySQL.
  6. Restart Apache by returning to System Preferences â?? Sharing to turn off, then on, Personal Web Sharing.

That’s it. You’re now running a pretty cool little Web application server. To check out the PHP configuration, create a new text file with the line <?php phpinfo(); ?> and save it as info.php in your sites folder. Open your browser to http://localhost/~[username]/info.php and take a look at your handiwork.

To view/edit/create databases in MySQL, try out the MySQL Query-Browser downloaded earlier or download YourSQLâ??another fine database interface for the Mac. phpMyAdmin is a browser-based MySQL interface that provides a third possibility.

MAMP

MAMP is an abbreviation for Macintosh, Apache, MySQL, and PHP. It’s also surprisingly a full-featured and ridiculously easy to setup Web development server package.

MAMP comes pre-packaged with Apache 2, MySQL 4, and PHP 4 and 5 (the OS X PWS solution comes with Apache 1.3 and PHP 4). The setup is child’s play. Just download the package, open it, and drag it to your Applications folder. Clicking on the MAMP icon fires up a self-contained Apache server and MySQL database. A browser window opens with some useful configuration information, a PHPinfo page, a phpMyAdmin MySQL interface, and more. You create your pages in MAMP’s Application folder and run them from http://localhost:8888/.

Best of all, if and when you decide to get rid of your MAMP pages and servers, just drag the MAMP folder to the Trash. It’s that easy.

XAMPP

Setting up XAMPP is very similar to MAMP except that, in addition to installing to the Application directory, XAMPP adds some additional files to the /opt/lampp folder. At this time, XAMPP also runs Perl 5.8 and the newer MySQL 5.

Security

Even though these are development servers, they are real Web servers and do expose our little Mac friends to some of the same monsters that haunt the big-time systems administrators. The Apache Friends have a nice little run-down of the security risks involved in running XAMPP. Some of these risks may also apply to our MAMP and PWS solutions as well (we’ll leave you to do the Google search on the topic). That said, MAMP seems to be the most isolated and therefore the most secure set up.

Conclusion

So that’s it. With these easy solutions, you can set up a Web development server on your humble little Mac that’ll run with the big dogs. Now go forth and be more productive.

Note: In the beTech presentation, we also downloaded and installed WordPress which is not only a great blog application but a great way to test out your brand-spankin’ new development platform.

Leave a Response

About Us

  • Building the University of Virginia web development community one passionate geek at a time.

Mailing List Sign-up

  • What's going on behind the scenes? Join the beTech mailing list and find out.
  • (listserv)

If you would like to write, present, or otherwise get more involved with beTech, please contact .


RSS feed icon