Postings

rails + xamp
Browse in : All > subjects > rails
All > subjects > xamp
Any of these categories - All of these categories

Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xd and user-summary-[publicationtype].xd. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles The templates will get the extension .xt there.

Title: Installing Rails on my iMac

Author: linoj

Date: January 31, 2007 12:07:03 PM or Wed, 31 January 2007 12:07:03

Summary: Yet another log of one man's blind trek through unfamiliar territory: MacPorts, Apache 2, Ruby, Rails, MySQL5, and even PhP5. Includes a little demo to test the install.

Body: 

Locomotive?

The first time through I used the no-brainer Locomotive package. I dont mean to say its not great, it really is so simple. Just download and install it. Everything is self contained - including the http server. It got me going enough to run a few tutorials.

Then, as recommended in the Agile book, I decided I should do a more manual install of the separate components. That way I can update individual things as needed, including gems (ruby components).

(Note the Agile book claims Locomotive uses SQLite, but i already had mySQL5 installed and it seemed to find it just fine as long as you edit the config/database.yml as needed).

Goin' For It

It all starts here with James Duncan Davidson's article, http://blog.duncandavidson.com/2006/04/sandboxing_rail.html

It's important to note that I already have Apache 1.33 running, with php5 and mysql5. Apache is what came in the box. Php and Mysql I upgraded manually (not with macports). I'm converting to MacPorts so I can upgrade easier in the future using one mechanism.

MacPorts

The first step is to get the MacPorts package manager, which lets you install (make) and update programs with commands like

sudo port install <portname>
port search <portname> 
port update <portname>

http://trac.macosforge.org/projects/macports

To start they call for Xcode and X11. Fortunately I'd already had those installed (had X11 for Gimp, which I dont use much, it sucks, but that's another story). Pretty sure you dont need X11 for Rails anyway :)

What I did need to do is setup my .profile (and remove the .bash_profile, copied any commands from there into .profile).

export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/apache2/bin:$PATH
export DISPLAY=:0.0

and verify with "env" command. Then just download the .dmg package and run the installer.

Then,

$ sudo port selfupdate 

 

Get All The Stuff, per Our Friend James

$ sudo port install apache2
$ sudo port install mysql5 +server
$ sudo port install subversion +tools
$ sudo port install ruby
$ sudo port install rb-rubygems
$ sudo port install rb-termios
$ sudo port install rb-mysql
$ sudo gem install -y rake
$ sudo gem install -y rails
$ sudo gem install -y capistrano
$ sudo gem install -y mongrel
$ sudo gem install -y mongrel_cluster

OK, that went pretty smoothly. Thanks Jimmy. So far so good. Now what?


Apache2

Blessed nubieness. I already have Apache 1.33 running on my mac, as it came in the box. James has me upgrading to 2. Or will both be running? (the suspense builds...)

First I try to start up apache2 by running httpd directly from the commandline (as root). Oh No, Jimmy forgets to mention we need a httpd.conf file! (and thanks to http://blog.nanorails.com/articles/2006/07/11/installing-rails-on-mac-os-x-tiger for pointing this out)

$ cd /opt/local/apache2/conf
$ cp httpd.conf.sample httpd.conf

Start 'em up (I su'd as root at this point):

$  /opt/local/apache2/bin/httpd 
$ ps aux | grep httpd 
$ netstat -anl |grep LISTEN  

Yep its running. And duh so is Apache 1. Both on port 80. Stop Apache 1 (using System Preferences > Sharing > Personal Web Sharing > Stop is how I'd been doing it up till now).

OK, browsing to http://localhost now uses Apache2. But the webroot is empty. Ooops, need to edit the conf file some more (/opt/local/apache2/conf/httpd.conf). Comparing the new one with the old one (/private/etc/httpd.conf) helps explain what else needs setting, including ServerAdmin, DocumentRoot, ErrorLog such as

ServerAdmin admin@parkerhill.com
DocumentRoot "/Library/WebServer/Documents"
ErrorLog "/private/var/log/httpd/error_log"

This article by Tavi helped here, http://forums.macnn.com/88/web-developer/322362/tutorial-installing-apache-2-php-5-a/

Tavi also suggests uncommenting the lines

Include conf/extra/httpd-autoindex.conf (Fancy directory listing)
Include conf/extra/httpd-default.conf (Some default settings)

I also decided to change

DirectoryIndex index.html
to
DirectoryIndex index.html index.php

Restart Apache2, this time with apachectl (and use the right copy):

(might first need to clean out all httpd processes with sudo killall -9 httpd)

$ sudo /opt/local/apache2/bin/apachectl stop
$ sudo /opt/local/apache2/bin/apachectl start

Or, adding this to .profile

alias apache2ctl='sudo /opt/local/apache2/bin/apachectl'
 
$ apache2ctl stop
$ apache2ctl start

Arrange to launch apache2 at startup

$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist 

So how do I change the System Preferences gui to use Apache2 instead of 1.3??? Can't find an answer by Googling. I'll just keep it Off in there for now (and put apache 1 on port 81 in case it does get started somewhere somehow, by changing to Port 81 in httpd.conf).

OK, i can browse to http://localhost, and a couple of static html pages there. Now try http://localhost/phpinfo.php

PhP

Oops, my other php stuff isn't working. I'll just install a fresh copy rather than fiddle with the existing install (and take advantage of port).

Stop apache first, then

$ sudo port install php5 +apache2 +mysql5 +pear
$ cd /opt/local/apache2/modules
$ sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so

Create a php.ini file you can use

$ cp /opt/local/etc/php.ini-dist /opt/local/etc/php.ini 

(actually I copied the ini from the old location /etc/php.ini)

and update the httpd.conf file by adding this line

 	Include conf/extras-conf/*.conf 	

Finally (re)start apache

As usual, create a file phpinfo.php in webroot containing

 	<?php phpinfo(); ?> 	

and test it by linking to http://localhost/phpinfo.php

:)

MySQL 5

Create the database

$ sudo mysql_install_db5 --user=mysql 

Launch when you reboot:

$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist 

Add to .profile:

alias mysqlstart='sudo mysqld_safe5 &'
alias mysqlstop='mysqladmin5 -u root -p shutdown'

(The "-p" assumes that you will be using a password for root, which you of course should be)

Add a password to your root account:

$ mysqladmin5 -u root password [yourpw] 

NOTE: the commands are now mysqladmin5 and mysql5, etc. These are just symlinks in /opt/local/bin to the corresponding programs in /opt/local/lib/mysql5/bin/ (e.g. /opt/local/lib/mysql5/bin/mysqladmin)

Now, in reality, this is not a new install for me, I have other databases. My previous install was in /usr/local/mysql (which is a symlink to /usr/local/mysql-standard-5.0.27-osx10.4-i686 and all the databases are its data/ subdirectory. Ugh-ly. (See post). I could just symlink the new mysql database dir there, but after some thought I decided the new one is a better name and location. So instead I copied the binary files from /usr/local/mysql/data/ to /opt/local/var/db/mysql5 and made a symlink from data to the new location. Important: dont just copy the data directory, instead copy each database subdir separately, using cp -rp.

Also, port has changed where the .sock file lives. Edit php.ini to say

	mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock  	

If some apps still dont find it, try adding a symlink to the (default?) location in /tmp (note the name is mysql.sock , not mysqld.sock) (however, this link seems to get deleted whenever I reboot so watch out for that):

$ sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock 

Clean Up

When I finally decide Apache2 and all this stuff is working, I'll probably retire Apache 1 altogether on this system. At that point I'll probably put symlinks where files had been conveniently located until now, like /etc/php.ini => /opt/local/etc/php.ini and delete /usr/local/bin/php altogether. Similarly for the old copies of mysql (mysqladmin5 vs mysqladmin) ...

One Last Test

Just to make sure, I'll reboot and make sure all is still running...

 


Verify Ruby and Rails are Up

Do a quick demo. No explanation here, just typing (see Agile book Chapter 4). Note, "mate" is my editor, choose your own.

$ mkdir ~/rails
$ cd ~/rails
$ rails demo
$ cd demo
$ ruby script/server

Link to http://localhost:3000/

Yep, we're in!

$ ruby script/generate controller Say
$ mate app/controllers/say_controller.rb

add these 2 lines inside the class definition:

	def hello
end

Link to http://localhost:3000/say/hello
Get error "Template is missing". That's ok, lets make it.

$ mate app/views/say/hello.rhtml
<html> 
<head>
<title>Hello, Rails!</title>
</head>
<body>
<h1>Hello from Rails!</h1>
</body>
</html>

Refresh. Yippee!

Now some database action

$ mysqladmin5 -u root -p create demo_development
$ mate config/database.yml

Add password to development: section , and test the connection

$ rake db:migrate 

No errors, Is good.

Make a database table (i'm diverging from the book's tutorial at this point):

$ ruby script/generate model quote
$ mate db/migrate/001_create_quotes.rb

inside the do block, add

t.column :saying,     :string
t.column :who,        :string
$ rake db:migrate 

Make an admin controller

$ ruby script/generate controller admin
$ mate app/controllers/admin_controller.rb

add this line inside the class:

scaffold  :quote 	

Link to http://localhost:3000/admin

That should bring up an admin page, add a couple quotes like

If its working it's creating and retrieving data to/from the database.

Good to go!!

 

Notes: 

More fields may be available via dynamicdata ..

Last modified on Feb 19, 2007 3:50:00 PM by linoj

Note: Comments are owned by the poster. We are not responsible for their content.

Installing Rails on my iMac

Posted by: Anonymous on September 24, 2007 08:45 AM
The issue with the symbolic link for tmp/mysql.sock

The way I understand this is that the mysql.sock gets created when mysql starts up. The link gets lost because the file gets deleted somehow, and therefore also the link.

I found a possible solution that seems to work.

In the launchdeamons there is a wrapper file for mysql.

I included the mysql.sock symbolic link in that file in the start section. On reboot it seems the link works.

Here is the code from the wrapper:

#!/bin/sh
#
# MacPorts generated daemondo support script
#

#
# Init
#
prefix=/opt/local

#
# Start
#
Start()
{
	/opt/local/share/mysql5/mysql/mysql.server start
	sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock
}

#
# Stop
#
Stop()
{
	/opt/local/share/mysql5/mysql/mysql.server stop
}

#
# Restart
#
Restart()
{
	Stop
	Start
}

#
# Run
#
Run()
{
case $1 in
  start  ) Start   ;;
  stop   ) Stop    ;;
  restart) Restart ;;
  *      ) echo "$0: unknown argument: $1";;
esac
}

#
# Run a phase based on the selector
#
Run $1

#

Post a new comment

BBCode Actions : Close Tags

Name : Anonymous


Keywords :

  • apache
  • install
  • mysql
  • php
  • port