My child,
I watch with pride, as you grew into a weapon of righteousness.
Remember, Our line has always ruled with wisdom, and strength.
And i know,
You would show restraint, when you exercising your great power.
But the truest victory my son,
Is stiring hearts of your people.
For when my days have come to an end,
You, Shall be king.

- King Terenas Menethil IIWorld of Warcraft

在Leopard里配置rails+php+apache+mysql

November 14, 2007

leopard_box200.jpg上上周在lex的怂恿下升级到了Leopard,最后花了3天时间,备份数据用了一台macbook pro加一只80g移动硬盘,重装4遍,到现在总算稳定下来了,不过还有一个bug未解决(期待10.5.1补丁)……

在Leopard里,很多开源代码都升级到了最新版,比如Python 2.5.1,PHP 5.2.4,Ruby 1.8.6,Apache 2.2,更棒的是,这次系统里直接集成了ruby on rails,包括Mongrel和Capistrano,据说还做过优化……

以前在mac里配置ROR,我是按照Dan Benjamin的《Building Ruby, Rails, Subversion, Mongrel, and MySQL on Mac OS X》来做的,安装ruby,gem之类的东西都是依靠MacPorts(osx里的包管理系统),而MacPorts安装的程序都在/opt/local里,独立于系统环境……

作为一个完美主义者,一定不能容忍自己心爱的系统里有任何兀余的代码,所以,这一次我希望能在leopard已经集成的代码基础上,搭建rails+php+apache+mysql的开发环境……

————————————————完美主义者的分割线——————————————————-

首先搞定apache,在配置面板里的“共享”中,选中”web共享”,就可以启动apache。默认的http://localhost指向/Library/WebServer/Documents,如果想修改成自己的目录,比如/Users/dexteryy/Sites/www,最简单的方法是直接改掉httpd.conf里的DocumentRoot

httpd.conf是放在/etc/apache2/里的,除了DocumentRoot,还要记得把下面两行代码前的注释删掉:

LoadModule php5_module libexec/apache2/libphp5.so
LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so

————————————————完美主义者的分割线——————————————————-

然后是php.ini,系统默认在/etc里放了一个php.ini.default,把它copy一份,改名为php.ini

php.ini里有一个关于mysql的地方要注意,leopard好像修改过mysql.sock的位置,所以要修改以下两行:

mysql.default_socket = /private/tmp/mysql.sock

mysqli.default_socket = /private/tmp/mysql.sock

————————————————完美主义者的分割线——————————————————-

然后安装最新的mysql,我下载的是mysql-5.0.45-osx10.4-i686.dmg。其中的MySQLStartupItem.pkg和mysql.prefpane都不用安装了,因为这两个东西目前都不起作用-___-b

以前启动mysql都是用这个命令:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

但是在leopard里,这个东西好像失效了,只好用这个命令来启动

sudo /usr/local/mysql/bin/safe_mysqld

如果要自动启动mysql,可以用以下方法:

在/Library/LaunchDaemons/里新建一个叫com.mysql.mysqld.plist的文件:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3. <plist version="1.0">
  4. <dict>
  5.     <key>KeepAlive</key>
  6.     <true/>
  7.     <key>Label</key>
  8.     <string>com.mysql.mysqld</string>
  9.     <key>Program</key>
  10.     <string>/usr/local/mysql/bin/mysqld_safe</string>
  11.     <key>RunAtLoad</key>
  12.     <true/>
  13. </dict>
  14. </plist>

修改权限:
sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plist

ok了……注意,如果安装过MySQLStartupItem.pkg,最好把MYSQLCOM直接删掉:

sudo rm -R /Library/StartupItems/MYSQLCOM

————————————————完美主义者的分割线——————————————————-

ruby on rails已经完美的集成了,不需要做任何设置,除了跟mysql的绑定……

sudo gem install mysql — –with-mysql-dir=/usr/local/mysql

选择3……

————————————————完美主义者的分割线——————————————————-

现在可以新建rails的项目了,在终端里进入刚才设置的DocumentRoot目录,输入/rails rails_test

然后启动服务器:
rails_test/script/server

命令执行后不要关闭终端窗口(会关闭服务器),leopard的终端现在支持标签了,苹果键+T,继续做别的事情……

现在访问http://localhost:3000/ ,就可以看到rails项目的页面了……

这里启动的服务器是Mongrel,实际上可以把它跟apache整合到一起,用apache接受浏览器的请求,利用反向代理功能转发给Mongrel,这样就不需要用3000端口,直接用这样的地址就可以访问rails的页面:http://localhost/rails_test

方法很简单,找到刚才的httpd.conf,在最下面加入:

ProxyPass /rails_test http://localhost:3000

————————————————完美主义者的分割线——————————————————-

以上是我目前搭建的一个简单的rails+php+apache+mysql开发环境,可能还有其他问题,在具体使用中慢慢改……

posted in Apple, PHP, Ruby on Rails, 代码 by Dexter.Yy

Follow comments via the RSS Feed | Leave a comment | Trackback URL

5 Comments to "在Leopard里配置rails+php+apache+mysql"

  1. Nomad wrote:

    按照上述方法,我不需要php和mysql,出现如下症状
    Nomad:Documents Nomad$ rails_test/script/server
    => Booting Mongrel (use ’script/server webrick’ to force WEBrick)
    => Rails application starting on http://0.0.0.0:3000
    => Call with -d to detach
    => Ctrl-C to shutdown server
    ** Ruby version is up-to-date; cgi_multipart_eof_fix was not loaded
    !!! Path to log file not valid: log/mongrel.log
    mongrel::start reported an error. Use mongrel_rails mongrel::start -h to get help.
    Exiting
    Nomad:Documents Nomad$ rails_test/script/server
    => Booting Mongrel (use ’script/server webrick’ to force WEBrick)
    => Rails application starting on http://0.0.0.0:3000
    => Call with -d to detach
    => Ctrl-C to shutdown server
    ** Ruby version is up-to-date; cgi_multipart_eof_fix was not loaded
    !!! Path to log file not valid: log/mongrel.log
    mongrel::start reported an error. Use mongrel_rails mongrel::start -h to get help.

  2. DAKKON wrote:

    竟然能访问了,奇迹啊

    还缺个mysql….有点担心搞不定..

  3. Nomad wrote:

    遇到些错误,有没有朋友遇到啊!!
    => Booting Mongrel (use ’script/server webrick’ to force WEBrick)
    => Rails application starting on http://0.0.0.0:3000
    => Call with -d to detach
    => Ctrl-C to shutdown server
    !!! Path to log file not valid: log/mongrel.log
    mongrel::start reported an error. Use mongrel_rails mongrel::start -h to get help.
    Exiting

  4. Nomad wrote:

    原先错误出现了
    => Booting Mongrel (use ’script/server webrick’ to force WEBrick)
    => Rails application starting on http://0.0.0.0:3000
    => Call with -d to detach
    => Ctrl-C to shutdown server
    ** Ruby version is up-to-date; cgi_multipart_eof_fix was not loaded
    !!! Path to log file not valid: log/mongrel.log
    mongrel::start reported an error. Use mongrel_rails mongrel::start -h to get help.

  5. Apache + PHP + Mysql on Mac Leopard 10.5 « Ben Inside - i.am.Ben’s Blog wrote:

    [...] 以上内容纯粹是这个post的小benben版 [...]

Leave Your Comment

YY in Limbo (混沌海狂想) © Dexter.Yy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution - NonCommercial - ShareAlike 3.0(署名-非商业性使用-相同方式共享).
Creative Commons License