需要的一般软件安装
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