Ubuntu下 apache2+Phusion Passenger

Ubuntu下 apache2+Phusion Passenger (此内容转载+个人修改 原链接:http://binku.iteye.com/blog/483687

 

Phusion Passenger  Users guide :http://www.modrails.com/documentation/Users%20guide%20Apache.html#_deploying_to_a_virtual_host_8217_s_root

 

 

Apache configuration files on Ubuntu :
http://articles.slicehost.com/2010/5/19/apache-configuration-files-on-ubuntu

 

---------------------------------------------------------------------------------------------------

 

(1)安装apache: sudo apt-get install apache2
(2)安装passenger

    $ gem install passenger
    $ passenger-install-apache2-module   #注意过程中提示可能会出现缺失gem
    安装到最後时,会出现如下的3条语句:

 

   默认情况下:加载的是本地系统中的gem,但如果你使用rvm进行buby的版本控制的话需要把gem指定成rvm中的gem路径,配置文件中C-V的内容注意

 

   LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-3.0.9/ext/apache2/mod_passenger.so

   PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.9

   PassengerRuby /usr/bin/ruby1.8


 


   LoadModule passenger_module /home/administrator/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/ext/apache2/mod_passenger.so

  PassengerRoot /home/administrator/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9

  PassengerRuby /home/administrator/.rvm/wrappers/ruby-1.8.7-p352/ruby

 

    把三条语句复制到/etc/apache2/apache2.conf的最后

 


(3)在/etc/apache2/sites-available下面创建available的应用配置
    $ sudo touch /etc/apache2/sites-available/rails-app #project.com
    打开rails-app,加入以下语句:
        <VirtualHost *:80> 
           # RailsEnv development 加上这句的话,以development的模式部署
            ServerName binku.com
            DocumentRoot /home/binku/programme/rails-app/public
        </VirtualHost>

 

 

<VirtualHost *:80>

  ServerName elischina.local  #映射的虚拟地址

  DocumentRoot /home/administrator/11111111111/elischina/public #目录一定要指向public

  <Directory /home/administrator/11111111111/elischina/public>

     Allow from all

     Options -MultiViews

     RailsEnv  development  #默认的是加载production的环境 ,如果用production环境,后面启动服务器的时候会出现css,js...加载的错误,文档中有说明:在config/environments/production.rb中 config.assets.compile = true (默认为false)改为true  ( http://stackoverflow.com/questions/7275636/rails-3-1-0-actionviewtemplateerrror-application-css-isnt-precompiled )

  </Directory>

</VirtualHost>


 


(4)创建软链接,把available的应用程序配置链接到/etc/apache2/sites-enabled下面,apache将读取该文件夹下的配置.
   $ sudo ln -s /etc/apache2/sites-available/rails-app /etc/apache2/sites-enabled/rails-app

实际上在你reload project.com文件时候会自动创建软链接

sudo a2dissite project.com 是删除软链接,即取消相应的项目映射

sudo a2ensite project.com  是创建软链接,即应用相应的项目映射


(5)如果要设置虚拟主机的ip可以修改/etc/hosts,加上
   127.0.0.1     localhost
   172.17.21.119 binku.com

     127.0.0.1    elischina.local


(6)如果以production模式部署的话,要记得创建production的数据库   (默认的是development 不需要了,直接rake db:migrate)
   $ rake db:create RAILS_ENV=production
   $ rake db:migration RAILS_ENV=production
(7)重启apache:sudo /etc/init.d/apache2 restart,现在就可以在浏览器访问rails应用了.
   重启apache前可以打开error日志看看启动有没有出错:tail -f /var/log/apache2/error.log
(8)修改完程序后,如果要重新部署可以输入:
   touch rails-app/tmp/restart.txt

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Phusion Passenger是一种基于Nginx或Apache的应用服务器,它可以帮助我们快速、稳定地部署Rails应用。下面以Redmine为例,介绍在CentOS下如何使用Phusion Passenger方式部署Rails应用。 1. 安装必要的软件 首先需要安装RubyRails、Nginx、Passenger等软件,可以使用以下命令: ``` sudo yum install epel-release sudo yum install ruby ruby-devel rubygems gcc gcc-c++ make sqlite-devel sudo gem install rails sudo gem install passenger ``` 2. 安装Nginx和Passenger 使用以下命令安装Nginx和Passenger: ``` sudo yum install nginx sudo passenger-install-nginx-module ``` 在安装过程中,需要选择“1. Yes: download, compile and install Nginx for me”选项,让Passenger自动编译和安装Nginx。 3. 配置Nginx和Passenger 默认情况下,Passenger会自动添加Nginx的配置文件并启动Nginx服务,但是我们需要手动修改Nginx配置文件。 找到Nginx的配置文件,一般是/etc/nginx/nginx.conf,添加以下内容: ``` http { # ... server { listen 80; server_name yourserver.com; root /path/to/your/redmine/public; passenger_enabled on; passenger_ruby /usr/bin/ruby; passenger_app_env production; } } ``` 其中,yourserver.com是你的服务器域名或IP地址,/path/to/your/redmine是你的Redmine应用所在路径。 4. 启动Nginx服务 启动Nginx服务: ``` sudo systemctl start nginx ``` 5. 配置数据库 修改/config/database.yml文件,配置Redmine连接数据库的相关信息。 6. 初始化Redmine 在Redmine目录下运行以下命令初始化数据库: ``` RAILS_ENV=production bundle exec rake db:create RAILS_ENV=production bundle exec rake db:migrate RAILS_ENV=production bundle exec rake redmine:load_default_data ``` 7. 启动Redmine 在Redmine目录下运行以下命令启动Redmine: ``` RAILS_ENV=production bundle exec rails server -e production ``` 现在你就可以在浏览器中输入yourserver.com访问Redmine了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值