1. 編譯安裝apache2
2. 安裝passenger
sudo gem install passenger
sudo passenger-install-apache2-module
根據提示安裝缺少的依賴包(不同機器可能不同,看提示)
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install apache2-mpm-prefork
sudo apt-get install apache2-prefork-dev
sudo apt-get install libapr1-dev
sudo apt-get install libaprutil1-dev
再次運行 sudo passenger-install-apache2-module
依賴都通過的話 就會開始編譯一些文件了,最後會提示
把以下內容加到配置文件裏去(可以用sudo apache2ctl -V | grep SERVER_CONFIG_FILE命令查看配置文件位置)
如:-D SERVER_CONFIG_FILE="apache2.conf" 在/etc/apache2目錄下
apache2.conf中有這樣一段
# Include all the user configurations:
Include httpd.conf
說明
apache2.conf 會自動加載同目錄下的httpd.conf文件 所以把以下內容加到httpd.conf中即可
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9
PassengerRuby /usr/local/bin/ruby
3.配置發佈在 apache2 配置文件中加入
<VirtualHost *:80>
ServerName www.yourhost.com
DocumentRoot /somewhere/public # <-- be sure to point to 'public'!
<Directory /somewhere/public>
AllowOverride all # <-- relax Apache security settings
Options -MultiViews # <-- MultiViews must be turned off
</Directory>
</VirtualHost>
本機測試的話,修改/etc/hosts文件,加入
127.0.0.1 www.yourhost.com
重啓apache2服務 sudo apache2ctl restart 即可訪問www.yourhost.com
在項目目錄下
$ touch tmp/restart.txt
5. RailsEnv development
如果要在開發環境下使用passenger ,在配置文件中加入 RailsEnv development
每次請求過後,都會reload應用
If you set RailsEnv development in your Apache configuration,then Rails will automatically reload your application code after each request.
7.完整例子 添加的部分 httpd.conf
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9
PassengerRuby /usr/local/bin/ruby
<VirtualHost *:80>
ServerName new.my.com
DocumentRoot /home/rex/ror/projects/newapp/public
RailsEnv development
<Directory /home/rex/ror/projects/newapp/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>