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.
- Download and install MacPorts (used to be DarwinPorts)
- Open up a terminal and type:
sudo port selfupdate
making sure everything is the way it should be.
If you’re like me, you getport: command not found
in return. - 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
- 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. - 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'
- Next load up the Apache2 package
sudo port install apache2
(this takes a while) 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.- Create an initial http.conf file
cd /opt/local/apache2/conf
sudo cp httpd.conf.sample httpd.conf - Start up Apache2
sudo /opt/local/apache2/bin/apachectl -k start
- Load up http://localhost. It should say “It works!”
sudo port install fcgi
sudo port install lighttpd +ssl
sudo port install mod_fastcgi
- Next load up Subversion package with the mod_dav_svn for Apache2
sudo port install subversion +mod_dav_svn +tools
- 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
- 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) - Create a rails app
rails testapp
- 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
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.
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?
I had the same problem. You’ll need to install the XCode package from http://developer.apple.com/tools/download/
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?
Did you run the “sudo port selfupdate” command? If not, try that.
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?
I am definitely going to be following this when I get my new iMac on wednesday evening.
Pingback: Vivisecting Media » Blog Archive » Installing Erlang on OS X
Pingback: Conscious Bits… - » Ruby on Rails Development Setup on an OS X 10.5 MacBook Pro
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).
Oops, the angle brackets were not escaped in my post. View source to get a better reflection of the command outputs above