Start webrick in port 80 (mysql2 gem issue)

為{幸葍}努か 提交于 2019-12-04 18:48:44

问题


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:inrequire' 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:inrequire' 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:inrequire' 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:inrequire' 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:inrequire' from script/rails:6


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/5840633/start-webrick-in-port-80-mysql2-gem-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!