Setting up a local server on OS X Leopard

This week I’ve spent quite a few hours trying to set up a local development environment on my new Mac. Although I’ve used the built in version of Apache 2, much of the other software that comes pre-installed with OS X is not ideal and needs to be replaced or tweaked. It is also not a bad idea to have your server software in /usr/local to avoid it being potentially broken by system updates. This is a brief record of the steps necessary to create a solid server setup that suits me, mainly for running WordPress sites (PHP and MySQL) and Ruby on Rails. It’s really more of a record for myself if I ever have to do it again – although no doubt next time it will be on Snow Leopard and everything will be slightly different!

  1. We’ve going to use the built-in version of the Apache web server. To start/stop the web server, go to System Preferences in OS X and select Sharing > Web Sharing.
  2. Move the Apache document root to a more convenient location (my personal ‘Sites’ directory): open /etc/apache2/httpd.conf and change the ‘DocumentRoot’ variable in 2 places (note: the PHP module should be left commented out, as it is by default). Next enable .htaccess by editing /etc/apache2/users/<username>/<username>.conf and specifying Options All and AllowOverride All. Restart Apache.
  3. Download and install a more recent version of PHP with more capability than the standard Apple one (GD library, Mcrypt, etc). This installs PHP into the directory /usr/local/php5.
  4. Download and install a version of MySQL server that correlates with that version of PHP (so the PHP MySQL library matches). MySQL is installed into /usr/local/mysql-5.0.77-osx10.5-x86 with a symbolic link from /usr/local/mysql.
  5. Create or edit ~/.bash_login and add this line to the end: export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH". This makes it more convenient to interact with MySQL from the command line, as well as pointing our system to our custom software installations in /usr/local.
  6. To start MySQL from the command line type sudo mysqld_safe (To stop MySQL type mysqladmin -u root -p shutdown)
  7. Set password for MySQL root user: mysqladmin  -u root -p 'mypassword' (Note that the MySQL user is different from the Unix user that the MySQL is running under – usually _mysql).
  8. To check current users in MySQL, use: SELECT Host, User, Password FROM mysql.user;. Set passwords for all as necessary. Alternatively, to limit access to your personal machine only, create the file /etc/my.cnf as detailed on this page (‘A Note About Security’).
  9. Set passwords for other users/hosts as required – see instructions half way down this page. Create an ‘admin’ user for MySQL so we’re not using root in the various config files etc. Will need to grant privileges.
  10. Download and install PHPMyAdmin. Unzip and rename directory, then place in web document root. Make a file called config.inc.php to put in your blowfish password (any random phrase will do). You can copy libraries/config.default.php if you like.
  11. Make sure you’ve installed Xcode from the OSX install disk.
  12. Add in MySQL C bindings for Ruby, to make Rails faster – instructions near the bottom of this page (you will need to have Xcode Tools installed in OS X to do this – use your OS X installation disk if needed)
  13. Follow the instructions on HiveLogic for installing Ruby and Ruby on Rails into /usr/local.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>