在端口80启动webrick(mysql2 gem问题)

发布于 2024-11-04 09:02:21 字数 1915 浏览 11 评论 0原文

我试图让我的 webrick 在端口 80 上提供服务。我尝试过:

rails server -p 80

但访问被拒绝。后来我明白使用端口1-1024需要root权限,所以我尝试了这个但是

sudo rails server -p 80

,现在我这次得到了mysql2错误。不知道这里发生了什么。我尝试运行:

rails server -p 1025

并且运行良好,我认为这是有关 root 和 mysql2 的问题。有人可以帮忙吗?

以下是控制台中的错误消息:

/Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2 /mysql2.bundle, 9): 库未加载: libmysqlclient.18.dylib (LoadError) 引用自:/Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle 原因:找不到图像 - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle 来自/Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2.rb:8 来自 /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in require' 来自 /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:inrequire' 来自 /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in each' 来自 /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:inrequire' 来自 /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in each' 来自 /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:inrequire' 来自 /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler.rb:120:in require' 来自/Users/ccool2486/Sites/fs2_test/config/application.rb:7 来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.6/lib/rails/commands.rb:28:inrequire' 来自/Library/Ruby/Gems/1.8/gems/railties-3.0.6/lib/rails/commands.rb:28 来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.6/lib/rails/commands.rb:27:in tap' 来自/Library/Ruby/Gems/1.8/gems/railties-3.0.6/lib/rails/commands.rb:27 来自 script/rails:6:inrequire' 来自脚本/rails:6

I am trying to get my webrick serve in port 80. I tried:

rails server -p 80

but get a access denied. I later understood that using port 1-1024 needs a root permission, so I tried this instead

sudo rails server -p 80

However, now i get a mysql2 error this time. Don't know what happened here. I tried to run:

rails server -p 1025

and it's working fine, I think it's something about root and mysql2. Can anyone help?

below is the error message in console:

/Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2.rb:8
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in
require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in
require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in
require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler.rb:120:in require'
from /Users/ccool2486/Sites/fs2_test/config/application.rb:7
from /Library/Ruby/Gems/1.8/gems/railties-3.0.6/lib/rails/commands.rb:28:in
require'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.6/lib/rails/commands.rb:28
from /Library/Ruby/Gems/1.8/gems/railties-3.0.6/lib/rails/commands.rb:27:in tap'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.6/lib/rails/commands.rb:27
from script/rails:6:in
require'
from script/rails:6

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘羡 2024-11-11 09:02:21

看来 mysql2 gem 没有安装在使用的 ruby​​ 运行时中。然而,由于这在没有 sudo 的情况下适用于你,我怀疑你已经安装了 rvm,并且在没有 sudo 的情况下午餐时默认使用 rvm ruby​​(安装了 mysql)。但是当你执行 sudo 时,你很可能使用的是没有安装 mysql2 的系统 ruby​​。

简而言之,如果您安装了 RVM 并且正在使用它。只需使用:

rvmsudo rails server -p 80

It seems that the mysql2 gem is not installed in the ruby run time that is used. however as this works for you without sudo, i suspect that you have rvm installed and you are using the rvm ruby (which has mysql installed) by default when lunching rails without sudo. but when you do sudo you are most probably using the system ruby which doesn't have mysql2 installed.

so in short if you have rvm installed and is using that. just use:

rvmsudo rails server -p 80
迟月 2024-11-11 09:02:21

我使用rails server -p 8080,它对我有用

I use rails server -p 8080, it works for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文