ruby项目搭建

需要的一般软件安装

 

sudo apt-get install ssh
sudo apt-get install vim git-core
sudo apt-get install mysql-server
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev

 启动项目遇到的错误

 

1、Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

解决方法:(进入网站https://github.com/sstephenson/execjs 随便选择一个runtime)

 

vim Gemfile

 在打开的文件里面添加(放在gem 'mysql2'下面)

gem 'therubyracer'

 之后执行

bundle install

 2、再次启动程序,打开页面http://0.0.0.0:3000/,提示错误(因为当前我还没有安装mysql数据库)

运行安装数据库

sudo apt-get install mysql-server

 3、重新启动程序,刷新页面http://0.0.0.0:3000/,提示错误(没有创建该项目的数据库)

运行创建数据库

rake db:create

到这边为止,项目启动一切正常了!

 

为了方便能够同时运行多个项目,并且不要手动设置各自的端口号,将rails项目部署到apache服务器上。下面开始安装apache:

安装apache2

 

sudo apt-get install apache2
 为了在apache上运行rails项目,需要安装一个apache扩长模块:(官方名字:phusion passenger)

 

 

gem install passenger
 安装完成运行
passenger-install-apache2-module
 缺少一些依赖包,根据提示一个个安装

 

 

sudo apt-get install libcurl4-openssl-dev apache2-prefork-dev libapr1-dev libaprutil1-dev
 安装完成,再次执行

 

 

passenger-install-apache2-module
 根据提示在httpd.conf中添加以下内容:

 

 

LoadModule passenger_module /home/heson/.rvm/gems/ruby-1.9.3-p392/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
PassengerRoot /home/heson/.rvm/gems/ruby-1.9.3-p392/gems/passenger-3.0.19
PassengerRuby /home/heson/.rvm/wrappers/ruby-1.9.3-p392/ruby

  <VirtualHost *:80>
      ServerName www.yourhost.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /somewhere/public
      <Directory /somewhere/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
      </Directory>
   </VirtualHost>
 ps:后面添加内容里的somewhere根据自己项目的实际情况填写 eg:
  <VirtualHost *:80>
      ServerName www.yourhost.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /home/heson/depot/public
      <Directory /home/heson/depot/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
      </Directory>
   </VirtualHost>
 重启apache服务器

 

sudo apachectl graceful
 本文参考视频: http://v.youku.com/v_show/id_XMzg0NTQ4NzY0.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值