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

Howard Huang
  • 355
  • 1
  • 4
  • 9

2 Answers2

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
thekindofme
  • 3,846
  • 26
  • 29
  • 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? – Howard Huang Apr 30 '11 at 09:28
  • 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. – thekindofme Apr 30 '11 at 09:32
  • grate! may be you could post what worked for you as a answer to this question. – thekindofme May 01 '11 at 14:55
  • this also works for rails 2. rvmsudo script/server -p 80. Thanks! – Tom Maeckelberghe Feb 29 '12 at 08:02
  • 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? – r15 Mar 20 '14 at 10:22
  • @r15 make sure you don't have any other servers running on the same port – thekindofme Apr 02 '14 at 23:06
  • actually my Apache was working on 80, after stopping the apache it works. – r15 Apr 03 '14 at 11:05
0

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

Fan
  • 9
  • 1