使用WEBrick时,带有sqlite3的简单sinatra应用程序有效,但在使用apache和passenger时无效
当我的应用程序尝试写入sqlite3数据库时,我收到一条“500内部服务器错误”消息 当我使用WEBbrick时,一切都正常,但当我使用Apache和Passenger时,会出现上述错误。我的应用程序加载第一页,但尝试发布时失败 以下是我如何设置所有内容: awesome.rb文件:使用WEBrick时,带有sqlite3的简单sinatra应用程序有效,但在使用apache和passenger时无效,sqlite,apache2,sinatra,passenger,Sqlite,Apache2,Sinatra,Passenger,当我的应用程序尝试写入sqlite3数据库时,我收到一条“500内部服务器错误”消息 当我使用WEBbrick时,一切都正常,但当我使用Apache和Passenger时,会出现上述错误。我的应用程序加载第一页,但尝试发布时失败 以下是我如何设置所有内容: awesome.rb文件: require 'sinatra' require 'data_mapper' require 'dm-core' require 'dm-migrations' require 'slim' APP_ROOT
require 'sinatra'
require 'data_mapper'
require 'dm-core'
require 'dm-migrations'
require 'slim'
APP_ROOT = File.expand_path(File.dirname(__FILE__))
DataMapper::setup(:default, "sqlite3://#{APP_ROOT}/emails.db")
class Email
include DataMapper::Resource
property :id, Serial
property :email, String, :required => true
end
DataMapper.finalize
get '/' do
slim :index
end
post '/add' do
Email.create params[:email]
redirect '/'
end
config.ru文件:
require '/var/www/awesome'
root_dir = File.dirname(__FILE__)
set :environment, ENV['RACK_ENV'].to_sym
set :root, root_dir
set :app_file, File.join(root_dir, 'awesome.rb')
disable :run
run Sinatra::Application
httpd.conf文件:
<VirtualHost *:80>
ServerName foo.com
DocumentRoot /var/www/public
<Directory /var/www/public>
AllowOverride None
Options FollowSymLinks
Options -MultiViews
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.18/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.18
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p327/ruby
我还为该组提供了对/var/www的www数据写入访问权限
--更新--
以下是“ps-axu | grep-Pass”命令的输出:
我以root用户的身份运行所有操作。这只是一个测试服务器,我想先让一切正常工作。我以前在安装ruby系统时遇到过麻烦,所以我从一个干净的服务器开始,没有添加任何其他用户
--更新2--
emails.db已经设置为每个人都可以使用chmod 777阅读,但我只是将其更改为chmod 666。这是我的ls-l输出:
-rw-rw-r-- 1 root www-data 442 Dec 23 13:15 awesome.rb
-rw-rw-r-- 1 root www-data 215 Dec 23 12:41 config.ru
-rw-rw-rw- 1 www-data www-data 12288 Dec 23 12:56 emails.db
-rw-rw-r-- 1 root www-data 54 Dec 23 10:55 hello.rb
drwxrwxr-x 2 root www-data 4096 Dec 22 14:50 log
drwxrwxr-x 2 root www-data 4096 Dec 22 15:34 public
drwxrwxr-x 2 root www-data 4096 Dec 23 12:03 tmp
drwxrwxr-x 2 root www-data 4096 Dec 22 17:16 views
然后我用“/etc/init.d/apache2 restart”重新启动了apache。我知道从chmod 777到chmod 666不能解决我的问题,但它可能更安全一些。我重新运行了我的应用程序,但仍然得到相同的“HTTP错误500(内部服务器错误):当服务器尝试满足请求时遇到意外情况。”我非常确定它仍然与apache和sqlite3有关,因为当我注释掉“Email.create params[:Email]”行时,我没有得到错误
--更新3--
下面是“tail-f/var/log/apache2/error.log”的输出:
这就是它所显示的一切。Chrome显示:
Request Method:POST
Status Code:500 Internal Server Error
运行Passenger的用户是什么?您可以使用命令
ps-axu | grep-Pass
找到,这样用户就应该对sqlite数据库文件具有写入权限。请显示apache错误日志中的消息。@上面发布的taro是ps-axu | grep-Pass命令的输出。您只需向所有人授予对数据库的读/写访问权:chmod 666/path/to/emails.db
@taro所有人都已经拥有读/写访问权,因为就在我在这里发布问题之前,我做了chmod 777 emails.db。但它仍然没有改变任何事情。我确实运行了chmod666,您可以在上面看到我的ls-l命令的输出。
96.18.233.137 - - [24/Dec/2012 20:46:54] "GET / " 200 706 0.0274
96.18.233.137 - - [24/Dec/2012 20:46:54] "GET /favicon.ico " 404 18 0.0013
96.18.233.137 - - [24/Dec/2012 20:47:01] "POST /add " 14 - 0.0046
Request Method:POST
Status Code:500 Internal Server Error