A while back, I upgraded my work computer to Lion. Instead of doing a normal install, I installed Lion onto a flash drive and did a clean install. This gave me a chance to make my system exactly how I wanted it. I managed to get an almost perfect development setup. When my laptop’s Ruby install got a little funny, I decided to do a clean install of Lion and follow the same setup, and document it set by set this time.
I am a PHP developer, I’ve also been developing with Ruby. So I’ll need git, Apache, PHP, PEAR, MySQL, Redis (a key-value store), and Ruby.
I wanted to make installing these things as easy as possible, that’s why I decided to go with Homebrew, a Mac package manager. There are other package managers out there, but I’ve found Homebrew to be the easiest to use.
To use Homebrew, you’ll need some build tools installed. You could install Xcode, but there’s an issue compiling using RVM (our Ruby install) with the newest version of Xcode. I had to uninstall Xcode and install osx-gcc-installer, so I would recommend just installing osx-gcc right from the get-go.
Once that’s done, we can install Homebrew. Just open up Terminal enter enter
One of the most valuable tools I use, no matter what language I’m working with is git. You could easily go to http://git-scm.com/ and download git from their, or even easier
Lion ships with Apache and PHP, but require some setup to get them to work how we want. It’s at this point you’ll need to decide where you want to keep your code at. I chose to keep all my code in a folder Code underneath my home directory and separated it by language from there.
We need to create a vhosts file that tells Apache about each of our sites. Let’s create that file now.
While we’re at it, let’s create a directory for log files generated by Apache.
We need to add some basic data to our vhosts file. Make sure you change /Users/name/Code/php to match where you are storing your files.
Note: Some tutorials out there will use domain.local, do not use .local in your domains, this will slow down Apache incredibly!
We need to turn on Apache now. Go to System Preferences > Sharing and turn on Web Sharing. Visit
http://localhost/. If you see “It Works!”, you have successfully installed Apache.
To add a site, you’ll need to copy the template, remove the comments, fill in the data, add an entry to /etc/hosts (127.0.0.1 domain.dev), and reload Apache (toggle Web Sharing off and on).
Let’s make sure Apache is loading the PHP module, and create our php.ini file.
Make changes to /etc/php.ini to fit your needs.
Note: If Apache runs slow, check out this article.
PEAR is PHP’s package manager. You’ll need it to install packages like APC or Memcache(d).
You’ll need to change the include_path in /etc/php.ini from “.:/php/includes” to “.:/usr/lib/php/pear”
Now that PEAR is installed let’s install APC. APC requires the pcre libraries, which we can install with Homebrew
You’ll need to add these lines to the end of /etc/php.ini to active APC.
extension=apc.so apc.enabled = 1 apc.shm_segments = 1 apc.shm_size = 32M apc.cache_by_default = 1 apc.stat = 1 apc.rfc1867 = 1 apc.stat = 3600
Finally, toggle Web Sharing off and on to enable PHP.
Let’s finish our custom MAMP stack (Mac, Apache, MySQL, PHP) by installing MySQL. MySQL is a package in brew, so let’s use that.
Once MySQL is installed, you need to configure it to work.
If you want to autoload MySQL on login
Note: If you are having issues, edit the plist to the correct UserName
If you don’t want to autoload MySQL, you have these commands to start and stop MySQL.
It’s recommended that you do a secure install (set a password and remove the test database and user).
One final step for MySQL, PHP is looking for mysql.sock in /var/mysql, when it’s actually in /tmp, so let’s edit that.
I find myself using Redis for a lot of my projects, so I installed that as well. If you don’t use Redis, skip this step.
To autoload on login.
Lately I’ve been diving into Ruby. OS X comes with Ruby, but it’s an old version. You could install the latest with Homebrew, but there’s a better option, Ruby Version Manager or RVM. RVM allows you to have multiple versions of Ruby and switch between them. To install RVM simply run
You can install different version of Ruby by running rvm install [version]. For example if you wanted to install 1.9.3 (the latest as of writing)
To use that version run
You can also set a default version
Ruby Gems is also installed, so you can install your favorite gems
With Homebrew installed, it’s easy to install other packages. Just search for the package.
For example I needed Nginx for a Ruby project I was working on
I’ve been running this setup on my work computer about a month and I haven’t had any issue with it. I don’t have to open up MAMP’s preferences everytime I want to switch sites, or have seperate computers to test different versions of Ruby. I hope you find this setup as useful as I have. If you have any suggestions or comments, please share them.
Update 2/9/12: These steps also mostly work in Snow Leopard. You’ll have to follow the instructions brew prints out for MySQL, but otherwise should be almost step for step.
Comments? I'm @mloberg on Twitter.