Drupal (as well as PHP and MySQL) on an Intel iMac with OS X real quick
I run a dynamic website at work called Science Buzz all about breaking science news featuring a science blog among other things. Well, we wanted to show off the site at an upcoming conference but didn't want to have to pay the extortion level fees for a rather slow internet connection. Creating a static version of this large dynamic site on a kiosk proved to be rather difficult until I realized I didn't need to make it static just run it natively on the iMac as a local service.
So if you want to know how I got Drupal up and running on an Intel Processor based iMac read on: (the process was made much smoother by listening to Paul McCartney's Ram during the ordeal)
Turn on the Web Server
If your reading this you probably already know how to do this but:
- Open 'System Preferences'
- Select 'Sharing'
- Go to the 'Services' tab and turn on 'Personal Web Sharing'
- This will make all the files at '/Library/WebServer/Documents' live. You can see them in your browser by typing to 'localhost' into your browser bar. If you can't see the default Apache message when you do this...well, you've got something gunked up.
Turn on PHP
Well, normally I would just use one of Marc Liyanage's great PHP binaries. Unfortunately these only work on PowerPC(PPC) Macs and my iMac I needed to use was a newer Intel686 based machine. I guess Marc is working on a binary for Intel macs but don't hold your breath.
Luckily the 10.4 OS that comes on the Intel iMacs already has PHP installed just not enabled. So you just need to enable it by:
- Open /etc/httpd/httpd.conf in you favorite text editor
- Remove the # before any lines containing PHP
- Save the file. This will require a root password.
This step stolen from the web-graphics blog
Again using your fav. text editor create a file at /Library/WebServer/Documents/phpinfo.php that looks like this:
<?php phpinfo(); ?>
If you don't see a screen that shows you a ton of info about your PHP install with a big purple bar at the top you've done something wrong.
I wanted to use the newer 4.1 version of MySQL which, thank the stars, has already been compiled and turned into a OS X package by the good folks at MySQL.
- Download the Mac OS X 10.4 (x86) Standard 4.1.18 package from the MySQL 4.1 download page.
- Unpack the archive and run the instal package
- Run the MySQLStartupItem package
- Double-click the MySQL.prefPane to install this.
I don't know if these steps are still nesc. but I did them anyways thanks to advice from Marc Liyanage's pages once again.
sudo chown -R mysql data/
Root password needed here
Now start it all up
sudo ./bin/mysqld_safe &
- test it out by running
Ta-da! PHP and MySQL. Make sure to read up on securing your MySQL system. At bare minimum lock down the root account.
/usr/local/mysql/bin/mysqladmin -u root password new_password_here
Socket problems and the ugly hack
If you try to write a PHP script in this environment that accessed the MySQL DB you would get socket errors. These two packages don't seem to perfectly talk to each other just yet. So I hacked a solution based on some wise comments over at web-graphics (comments 14-16). The fixes here work once but as soon as you restart seem to break. So I just forced this process to happen at the startup of the MySQL service.
- Open '/Library/StartupItems/MySQL/MySQL' in a text editor
- At the end of the file add these lines:
ln /tmp/mysql.sock /var/mysql.sock
This creates a symbolic link to the mysql socket file. I don't know why you need to redo this each time you start the service but that was the only way it would work for me.
The rest pretty much followed a standard Drupal installation. I had to go into the httpd.conf file and allow .htaccess files ful permission to get Drupal's "Clean URLs" to work but this isn't annything specific to the Mac. All in all much simpler than I thought it would be.