How To Install MacPorts, Apache2, Rails, MySql, Mongrel, and Subversion on an Intel Mac

Now that I’m just about ready to deploy my first rails app, I thought I’d get the deployment environment set up rock solid on both the production and the development machines (one Mac Mini and one MacBookPro).

Like many other tutorials on this same subject, your mileage may vary. In fact I’m writing this now, because mine did. After stalling out in many of the tutorials all different places, this is what worked for me.

  1. Download and install MacPorts (used to be DarwinPorts)
  2. Open up a terminal and type:
    sudo port selfupdate
    making sure everything is the way it should be.
    If you’re like me, you get port: command not found in return.
  3. I fixed this by opening up .bash_profile in a text editor (Textmate: mate ~/.bash_profile) and adding the line
    export PATH=/opt/local/bin:$PATH
  4. Next download and install MySQL5
    I grabbed the binary from the bottom of the MySQL 5 download page. It comes with a System Preference Pane and checkbox for auto-startup. I’m using CocoaSQL for admin.
  5. Change the MySQL5 root password

    /opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
    /opt/local/lib/mysql5/bin/mysqladmin -u root -h [HOSTNAME] password 'new-password'
  6. Next load up the Apache2 package
    sudo port install apache2
    (this takes a while)
  7. sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist to launch Apache2 on startup. I’ve disabled Apple’s default Web Sharing in the System Preferences.
  8. Create an initial http.conf file
    cd /opt/local/apache2/conf
    sudo cp httpd.conf.sample httpd.conf
  9. Start up Apache2
    sudo /opt/local/apache2/bin/apachectl -k start
  10. Load up http://localhost. It should say “It works!”

  11. sudo port install fcgi
    sudo port install lighttpd +ssl
    sudo port install mod_fastcgi
  12. Next load up Subversion package with the mod_dav_svn for Apache2
    sudo port install subversion +mod_dav_svn +tools
  13. Next load up Ruby, RubyGems, Termios, RB-MySQL5 Bridge, and ImageMagick Packages
    sudo port install ruby
    sudo port install rb-rubygems
    sudo port install rb-termios
    sudo port install rb-fcgi
    sudo port install rb-mysql (I had some errors on this one.)
    sudo port install imagemagick
  14. Install a bunch of useful gems, like rails and capistrano.

    sudo gem install --include-dependencies rake
    sudo gem install --include-dependencies rails
    sudo gem install --include-dependencies termios
    sudo gem install --include-dependencies capistrano


    sudo gem install daemons gem_plugin mongrel mongrel_cluster --include-dependencies
    sudo gem install --include-dependencies mongrel
    sudo gem install --include-dependencies mongrel_cluster


    sudo gem install mysql --
    --with-mysql-dir=/usr/local/mysql
    --with-mysql-include=/usr/local/mysql/include/
    --with-mysql-lib=/usr/local/mysql/lib/
    --with-mysql-config=/usr/local/mysql/bin/mysql_config

    (thanks to d. robert adams for the last bit)
  15. Create a rails app
    rails testapp
  16. Connect the rails app to mongrel

    cd /RAILS/ROOT/OF/TESTAPP
    mongrel_rails cluster::configure -e development -p 8000 -a 127.0.0.1 -N3 -c /RAILS/ROOT/OF/TESTAPP

11 Replies to “How To Install MacPorts, Apache2, Rails, MySql, Mongrel, and Subversion on an Intel Mac”

  1. This is nice set of instructions, but if you’re using Apache2 in conjunction with mongrel why did you install the lighttpd web server package? I thought it was more typical to choose one or the other when you’re installing Rails.

  2. Hi , I am having trouble installing apache2

    When I attempt to intstall I get this error:

    Error: Unable to execute port: wrong # args: should be “proc name args body”

    I’ve typed in the unix line multiple times as well, when I put a space between apache and 2 “apache_2” I get:

    —> Cleaning apache
    Error: Port 2 not found

    Could you please help explain my problem?

  3. I downloaded and installed xcode yet I still recieve the same error. any clue as to why? also is there a way to check to see if you have installed mysql5 properly?

  4. considering you’re recommending the stock mysql 5 package, wouldn’t mysqladmin be in /usr/local/mysql/bin/mysqladmin instead of /opt? or are you suggesting we should use the mysql 5 that comes with MacPorts?

  5. Very helpful. Here is a command summary of my apache2 subversion mod_dav_svn install (starting configuration). Basically I did:

    $ sudo port selfupdate
    $ port -v
    MacPorts 1.600

    $ sudo port install apache2
    $ sudo port uninstall subversion # was already installed without mod_dav_svn
    $ sudo port install subversion +mod_dav_svn +tools

    $ cd /opt/local/apache2/conf
    $ sudo cp httpd.conf.sample httpd.conf
    $ sudo vi httpd.conf # added Include
    $ cat httpd.conf | grep svn # no match
    $ cat httpd.conf | grep subversion
    Include conf/extra/httpd-subversion.conf
    $ cat /opt/local/apache2/conf/extra/httpd-subversion.conf
    LoadModule dav_svn_module modules/mod_dav_svn.so

    DAV svn
    SVNPath /Library/Subversion

    $ curl http://localhost/svn/
    svn – Revision 16: /

    svn – Revision 16: /

    pcj/

    Powered by Subversion version 1.5.0 (r31699).

  6. Oops, the angle brackets were not escaped in my post. View source to get a better reflection of the command outputs above

Leave a Reply

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