0

I can't believe that it turned out to be so difficult, but I need to be able to run my rails app at localhost/rails_app for development reasons, without breaking other applications I have. (localhost/php_app, for example)

I've followed a lot of tutorials, but I still can't get it working.

I have passenger installed and I think the missing step is to properly configure a VirtualHost.

(Mac OS X, Rails 4, Apache)

Edit: The big problem is that I can't run in localhost:3000 or any other port

Edit2:

With this in the apache configuration file:

<VirtualHost *:80>
     ServerName localhost
     ProxyRequests off
             <Proxy *>
                    Order deny,allow
                    Allow from all
             </Proxy>
           <Location /my_rails_app/ >                                                         
             ProxyPass http://localhost:3000/
             ProxyPassReverse  http://localhost:3000/
         </Location>
</VirtualHost>

The application runs on localhost/my_rails_app/ but it still uses localhost/ as the base url, missing every asset and making all the links wrong.

Pedro Bernardes
  • 706
  • 1
  • 8
  • 20

2 Answers2

1

First off, on a local system you can just use the built-in test server that comes with Rails. Here's a virtual host that I use on a ubuntu server to run Rails:

<VirtualHost *:80>
  ServerName errandlist.com
  ServerAlias www.errandlist.com
  # !!! Be sure to point DocumentRoot to 'public'!
  DocumentRoot /var/www/errandlist/public   
  RailsEnv production  
<Directory /var/www/errandlist/public>
     # This relaxes Apache security settings.
     AllowOverride all
     # MultiViews must be turned off.
     Options -MultiViews
  </Directory>
</VirtualHost>

And you are going to need to enable Passenger in your httpd.conf:

# Ruby Passenger support
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.19/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.19
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-1.9.3-p448/ruby

It will be very similar on OSX, your versions may vary.

Edit: here's a question about running the test server on port 80: How to run rails s -p80 on 80 port?

Community
  • 1
  • 1
Peter Wooster
  • 6,009
  • 2
  • 27
  • 39
  • Thanks for your answer, but I didn't understand the first statement "built in test server that comes with Rails". Also, I did it! See my own answer. – Pedro Bernardes Jul 05 '14 at 16:29
  • The command `rails server` starts the test server, see http://guides.rubyonrails.org/command_line.html – Peter Wooster Jul 05 '14 at 16:43
  • I know that, but it runs at localhost:3000, and I need it to run at localhost/rails – Pedro Bernardes Jul 05 '14 at 16:47
  • Yeah, with that answer I'd be able to run at port 80, but still not able to run at a subdomain and it would break my other applications, since it is replacing apache. (Right?) – Pedro Bernardes Jul 05 '14 at 16:54
  • That is correct, it will block the use of apache on port 80. You need to get Passenger working. What is missing in your virtual host is the DocumentRoot setting, that controls where the files are served from. – Peter Wooster Jul 05 '14 at 16:58
0

I just use this script to run on localhost from the command line for debugging purposes for a project known as "priority_tree":

c:\ruby\bin\ruby C:\web\priority_tree\script\server -e test -p 3000

Then just open up IE or Edge with http:\localhost:3000 to test the program's operation.

You have to have dns setup to access a sql server or other database instance if you use it, but otherwise this should work.

Timothy Dooling
  • 470
  • 1
  • 4
  • 17