Start webrick in port 80 (mysql2 gem issue)
Asked Answered
E

2

11

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

Elwoodelwyn answered 30/4, 2011 at 8:39 Comment(3)
why not post the mysql error?Mariko
thanks for you remind! Just posted the error, big thanks!Elwoodelwyn
Check out : #4547198Chantel
M
23

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
Mariko answered 30/4, 2011 at 9:6 Comment(7)
thanks for your answer! however i didnt use rvm in my machine. i tried to install mysql2 with sudo permission, but still end up with the error message. any ideas?Elwoodelwyn
my answer was a long shot. did you look at the link that lobster1234 posted above? "Library not loaded: libmysqlclient.18.dylib (LoadError)" is most likely whats causing the error.Mariko
grate! may be you could post what worked for you as a answer to this question.Mariko
this also works for rails 2. rvmsudo script/server -p 80. Thanks!Anglophobe
I tried this but I got Address already in use - bind(2) for 0.0.0.0:80 (Errno::EADDRINUSE) error. What should I do?Disfeature
@Disfeature make sure you don't have any other servers running on the same portMariko
actually my Apache was working on 80, after stopping the apache it works.Disfeature
S
0

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

Smail answered 24/2, 2013 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.