0 comments
web
06 Jun 2009

OS X Web Development (Revisited)

Many revisions have passed since we last covered this topic, so with a fresh install on hand it’s time to refactor!

MySQL

For the early versions of Leopard you had to compile from source, not very pretty and can prove troublesome for people not used to that kind of thing. Well not any more! MySQL themselves have released a package for 5.1 which works nicely and has a companion guide to get you set up.

If you are on your local machine and getting fed up of having to type a password to connect, you can also blank the password by running this command:

mysqladmin -p -u username password ''

Where username is the user account you want to blank the password for.

You should take a look at Sequel Pro for a nice native interface to connect and manipulate databases.

PHP

Although there isn’t an official release for OS X, there is however, a link hidden away on the side navigation for all in one package that will take you to a guide with a download link. This download is another package installer so you just click and follow instructions.

You may want to alter your php.ini file a little to have short tags enabled but otherwise it was spot on. The only issue with this package is making the command line version the same as the shared object used by apache. For an experienced user this is no problem, symlinks are your friends.

Make a backup of your current php bin file and then symlink this new one to that location, so now your path should follow the symlink to the correct version of php!

Apache

As we haven’t built anything from source this time we no longer need to tell apache what architecture it’s using, so no need to make any amends. If you are making sites with the same structure all the time I would say put this into your vhosts file:

For ease you can use a vhost declaration like:

<VirtualHost *:80>
    VirtualDocumentRoot /path/to/websites/%1/public
    <Directory "/path/to/websites/%1/public">
      Options FollowSymLinks
          AllowOverride None
    </Directory>
</VirtualHost>

This way you no longer need to make a vhost per site. If only you could this with /etc/hosts file!

If you are getting 403 errors then make sure your directory declaration is correct and looks something like:

<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>

GiT

Version control is an import part of our jobs, so we use a distributed system called git, hopefully you’ve heard of it. There is now a very nice and easy package file for OS X so again you can skip out all the command line stuff and just click to install it.

It comes with an extra script file, if you run this you can then take full advantage of software like GitX and OpenItInGit (a Finder plugin) to do git with a gui!

If you use text mate as an editor you can also get hold of a git bundle for text mate called gitorious, which is installed via git.

Ruby Gems

If you are using gems such as capistrano you will need to do an update as the ones in Leopard are somewhat out of date! It is very straight forward but does require using the command line:

sudo gem update --system

This will get your version of gems updated and sudo gem update will update any gems installed to the latest versions.

ImageMagick

If you need ImageMagick for your php framework this section’s for you. They now have a ImageMagick binary install for OS X Leopard available. Download this and extract it to /usr/local. To allow your php scripts to execute ImageMagick you’ll need to set some environment variables for the apache process. To do this edit the file /System/Library/LaunchDaemons/org.apache.httpd.plist to add something like the following (additions highlighted):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>org.apache.httpd</string>
    <key>OnDemand</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/sbin/httpd</string>
        <string>-D</string>
        <string>FOREGROUND</string>
    </array>
    <key>SHAuthorizationRight</key>
    <string>system.preferences</string>
    <key>EnvironmentVariables</key>
    <dict>
      <key>DYLD_LIBRARY_PATH</key>
      <string>/usr/local/ImageMagick-6.5.3/lib</string>
      <key>MAGICK_HOME</key>
      <string>/usr/local/ImageMagick-6.5.3</string>
      <key>PATH</key>
      <string>
        /usr/local/ImageMagick-6.5.3/bin:/usr/bin:/bin:/usr/sbin:/sbin
      </string>
    </dict>
  </dict>
</plist>

The Big Bonus!

Using this method means that although you’ll have to start off altering your system paths a bit, in the future whenever you do a OS X update your setup will not get wiped (with the exception of the php symlink). Much nicer than having to reinstall every time.

NOTE: I originally wrote this post for the One Black Bear website after formatting and experimenting with new setup on my laptop. It is very handy for reference so I included it on my site as well.

EDIT (Sept 30 2009): Even better! with Snow Leopard you no longer have to install a custom version of PHP; the built in version is up to date and comes with everything.

blog comments powered by Disqus