Cannot run Sinatra application on port 80

May 24, 2014 2.4k views
I am trying to run some blog software I wrote on port 80 like this: ruby tinyblog.rb -o 80 Only problem is that I get this error: [2014-05-24 01:04:34] INFO WEBrick 1.3.1 [2014-05-24 01:04:34] INFO ruby 2.1.2 (2014-05-08) [x86_64-linux] /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:206:in `bind': Permission denied - bind(2) for 127.0.0.1:80 (Errno::EACCES) from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:206:in `listen' from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:461:in `block in tcp_server_sockets' from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:232:in `each' from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:232:in `foreach' from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/socket.rb:459:in `tcp_server_sockets' from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/utils.rb:75:in `create_listeners' from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:132:in `listen' from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:113:in `initialize' from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:45:in `initialize' from /home/user/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/handler/webrick.rb:11:in `new' from /home/user/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/handler/webrick.rb:11:in `run' from /home/user/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1497:in `start_server' from /home/user/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1435:in `run!' from /home/user/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/main.rb:25:in `block in ' How do I fix this? The application can be found at http://github.com/Quojil/TinyBlog if need be.
2 Answers
Ensure that you are not running a web server that is already bound to port 80, and that you are running as a user with root privileges. Root privileges are required for binding to any port below 1024.
We have an article on deploying a Sinatra application on Ubuntu 13: https://www.digitalocean.com/community/articles/how-to-deploy-sinatra-based-ruby-web-applications-on-ubuntu-13.

I hope that helps.
by O.S. Tezer
In this DigitalOcean article, we will learn a couple of different ways to take your Sinatra application out of its hidden box and share it with the world on Ubuntu using different and interesting technologies and methods.
Have another answer? Share your knowledge.