[教學] Lighttpd+RoR+php5+mysql 建置快速RoR環境

原本是用OSX上得apache的, 但是聽說lighttpd小又快, 所以有了以下的實驗.... 有同好的話可以一起討論討論....

要準備的有三個大項:
1. DB: MySQL
2. Ruby on Rail
3. Web daemon: Lighttpd + php5 + FastCGI + Zend + eaccelerator

以下安裝步驟都在終端機中執行, 當然為了方便, 你可以先切換到root使用者, 要enable root帳號十分簡單, 下sudo passwd然後變更密碼後 su - 進去就行了, 不知我說什麼的人請先k一下Unix.

另外就是, 在Intel以及G5/G4上頭是都可以執行的, 但是記得要先裝好xcode.



=========================================================================
MySQL沒有跟其他程式有牽連所以先裝:

1. Installation

CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared

make

make install

cd /usr/local/mysql

./bin/mysql_install_db --user=mysql

chown -R mysql ./var

2. 建立 /etc/my.cnf 內容如下:

[mysqld]
bind-address = 127.0.0.1
character-set-server = utf8
init-connect='SET NAMES utf8'


3. 因為你使用mac, 建立 /Library/LaunchDaemons/com.mysql.mysqld.plist 內容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.mysql.mysqld</string>
<key>Program</key>
<string>/usr/local/mysql/bin/mysqld_safe</string>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>mysql</string>
<key>WorkingDirectory</key>
<string>/usr/local/mysql</string>
</dict>
</plist>

4. 更改 /Library/LaunchDaemons/com.mysql.mysqld.plist 的所有權

chown root /Library/LaunchDaemons/com.mysql.mysqld.plist

5. Start/Stop MySQL

launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist (執行一次後, 以後mac重開機就會自己執行MySQL)
launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist (解除重開機後自動執行MySQL)


MySQL在OSX上的client可以用CocoaMySQL或是NavicatNavicat, 我比較偏好使用Navicat, 利用Navicat去改root的密碼很直覺也快速, 使用者可以完全不需要下命令列指令.



=========================================================================
再來是 Ruby on Rails(RoR)

1. 到 Ruby官網 Download Ruby & RubyGems.

2. 依照說明compile & nstall

3. 執行下列指令:

gem update rails

gem install rails --include-dependencies

env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

如果你用的是PPC, 上面這行改成:
env ARCHFLAGS="-arch ppc" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config



=========================================================================
不麻煩但是冗長的是這個部份:Lighttpd server pcre/fastcgi/gem-fcgi/php5/zend/eaccelerator

首先要下載下列套件
_ php 5
_ Zend optimizer
_ eaccelerator
_ FastCGI
_ ruby-fcgi
_ PCRE
_ lighttpd
_ automake
_ autoconf

1. compile PCRE and install it

2. Lighttpd:

./configure --prefix=/usr/local --with-pcre=/usr/local

make

make install

3. FastCGI:
./configure --prefix=/usr/local
make
make install

4. ruby-fcgi:

ruby install.rb config --prefix=/usr/local

ruby install.rb setup

ruby install.rb install

gem install fcgi

5. 然後是php...要注意, 不可以enable cli, 還有, 如果你想要php支援其他的功能, 你可能必須預裝一些軟體, 如:GD, Imagemagick

./configure --enable-bcmath --enable-calendar --enable-exif --enable-fastcgi --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-magic-quotes --enable-mbstring --enable-soap --enable-sockets --enable-zip --enable-fastcgi --enable-force-cgi-redirect --with-config-file-path=/usr/local/php/etc --disable-cli --enable-safe-mode --with-mysql=/usr/local/mysql --disable-debug -prefix=/usr/local/php --with-bz2 --with-curl=/usr/include/curl/ --with-freetype-dir=/usr/X11 --with-gd --with-zlib --with-ttf --with-xmlrpc --with-mime-magic --with-kerberos --with-png-dir=/usr/X11

make

make install

6. Compile and Install Automake/Autoconf

7. Zend
Zend的安裝方式有導引, 在此不多介紹.

8. eaccelerator

/usr/loacl/php/bin/phpize (這個檔案在你剛剛安裝php的路徑下)

./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php/bin/php-config

make

cp modules/eaccelerator.so /usr/local/php/lib/php/extensions

mkdir /tmp/eaccelerator

chmod 0777 /tmp/eaccelerator

9. 修改 /usr/local/php/etc/php.ini

......
extension_dir = "/usr/local/php/lib/php/extensions"
......
extension=eaccelerator.so
......
......
......
[Zend]
zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.0
zend_optimizer.version=3.3.0a
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_optimizer.optimization_level=1023
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"


10. 修改 /etc/lighttpd/lighttpd.conf

server.modules = (
    "mod_rewrite",
    "mod_redirect",
    "mod_alias",
    "mod_access",
    "mod_fastcgi",
    "mod_accesslog" )
.......
server.document-root = "/var/www/htdocs/"
.......
server.errorlog = "/var/log/lighttpd/error.log" (/var/log/lighttpd這個目錄你要自己建)
.......
index-file.names = ( "index.php", "index.html",
    "index.htm", "default.htm", "dispatch.fcgi" )
.......
server.port = 2048 (或是你要改成80)
.......
## change uid to <uid> (default: don't care)
server.username = "www"

## change uid to <uid> (default: don't care)
server.groupname = "www"
......
#### fastcgi module
## read fastcgi.txt for more info
## for PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini
fastcgi.server = ( ".php" =>
    ( "localhost" =>
        (
        "socket" => "/tmp/php-fastcgi.socket",
        "bin-path" => "/usr/local/php/bin/php-cgi" (should check php-cgi file)
        )
    )
)

11. 啟動....發射升空.....

/usr/local/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf

2008-07-09 12:58 發佈
無論是用osx內建的apache或是自行編譯的apache或是lighttpd都會有一個問題, 如果你有利用gd函式庫製作captcha (就是防止機器人留言的那種有數字的圖形), 就會在終端機中出現下面這種訊息:

The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.

就算自行編譯gd library也是無法順利執行........後來試用xampp的mac版本, 不錯耶, 居然是可以執行的, 可以順利使用GD的函數了, 不想麻煩的人, 推薦使用XAMPP來作為開發環境也是不賴的.
Jingle All the Way 新解:空桶響叮噹.....
內文搜尋
X
評分
評分
複製連結
Mobile01提醒您
您目前瀏覽的是行動版網頁
是否切換到電腦版網頁呢?