I just started out learning Ruby on Rails this week. I'm using Michael
Hartl's book, but I'm working on a remote server rather than my local
computer. As such, I'm using Apache + Passenger to deploy the example
programs rather than Mongrel. Also, I'm using MySQL for my database
instead of SQLite.
My issue is that I don't understand how to deploy a program on a
remote server using Apache + Passenger in a way that makes the
contents of the views directory accessible. For instance, if I create
a sample program 'demo_app' and create a 'users' resource with the
command:
$ script/generate scaffold User name:string email:string
and then migrate with the command:
$ rake db:migrate
I can't see the 'users' folder or anything in it when I point my
browser to the remote server. I can see the standard 'Welcome aboard!'
page at http://<server_addr>/demo_app, but http://<server_addr>/demo_app/users
gives me a 404 Not Found. In my apache2.conf file, I have the
following VirtualHost specification:
In my web root directory, 'demo_app' is a symbolic link to the
application's public directory. I realize that there's nothing in my
web root directory or the above VirtualHost specification that points
to the 'users' resource, but when I build this app locally and view it
with Mongrel, I can see http://0.0.0.0:3000/users just fine. All of
the documentation I've read indicates that the above specification and
symbolic link are all I need to create to deploy an app on a remote
server with Apache + Passenger. Do I need to do something else to
access http://<server_addr>/demo_app/users? Have I missed an obvious
or elementary step? Am I misunderstanding something? Am I on another
planet?
In my web root directory, 'demo_app' is a symbolic link to the
application's public directory. I realize that there's nothing in my
web root directory or the above VirtualHost specification that points
to the 'users' resource, but when I build this app locally and view it
with Mongrel, I can seehttp://0.0.0.0:3000/usersjust fine. All of
the documentation I've read indicates that the above specification and
symbolic link are all I need to create to deploy an app on a remote
server with Apache + Passenger. Do I need to do something else to
access http://<server_addr>/demo_app/users? Have I missed an obvious
or elementary step? Am I misunderstanding something? Am I on another
planet?
For instance, if I create a sample program 'demo_app' and create a 'users'
resource with the command:
$ script/generate scaffold User name:string email:string
and then migrate with the command:
$ rake db:migrate
I can see the standard 'Welcome aboard!' page at
http://<server_addr>/demo_app,
That's a good sign.
but http://<server_addr>/demo_app/users gives me a 404 Not Found.
Did you generate the new scaffold after your app was already running under
Passenger? If so, and it's environment is set to production, did you modify
the tmp/restart.txt file in your app to signal Passenger to restart the
application?
but when I build this app locally and view it with Mongrel, I can see
http://0.0.0.0:3000/users just fine.
That's probably also a good sign. I bet you just need to have Passenger
reload the app as mentioned above. Details can be found at:
Okay, so this is interesting. When I try deploying the app to the
domain root, I can't see the "Welcome aboard!" page; instead, I see
the index.html page that's in Apache's web root directory. Also, when
I try http://<server_addr>/users, I see a directory listing of the
(.erb) files that are in the demo_app/app/views/users. Does this mean
that Passenger is not set up correctly?
I don't know if it matters, but the server I'm using doesn't have a
domain name; I'm accessing it using its IP address.
Okay, so this is interesting. When I try deploying the app to the
domain root, I can't see the "Welcome aboard!" page; instead, I see
the index.html page that's in Apache's web root directory. Also, when
I try http://<server_addr>/users, I see a directory listing of the
(.erb) files that are in the demo_app/app/views/users. Does this mean
that Passenger is not set up correctly?
Yes.
For your own sanity, set up Rails on your local box and don't worry
about the remote server yet.
I don't know if it matters, but the server I'm using doesn't have a
domain name; I'm accessing it using its IP address.
Shouldn't matter.
On May 21, 7:47�pm, Frederick Cheung <frederick.che...@gmail.com>
Okay, I got it to work on the domain root by editing /etc/apache2/
sites-available/default to point to the app's public directory. Is
that the right way to go about it, or is that just a hack? If that's
what I'm supposed to do, it seems odd that this step isn't mentioned
in the mod_rails user guide. I still can't get it to work on a sub-uri
using an analogous technique (i.e., creating a virtual host file for
the URI in /etc/apache2/sites-available)...
If the server actually has a unique ip address for the app, then you
might look at setting up an ip address based virtual host after
reading the caveats in the first section of the first url I cited.
But the simpler thing would probably be to use a name based vhost and
configure the client's dns to resolve the name to the ip address so
you can use it in the browser urls.
Just putting a line in /etc/hosts (or the equivalent if the client is
a doze machine) should be enough.