Deploying Ruby on Rails App using Passenger & Apache - ruby-on-rails

I am trying to deploy my Ruby on Rails application using Phusion Passenger and the Apache2 module on MacOS. I believe I have installed all dependencies and gems correctly and think a problem lies in my configuration files. I do not have a domain so I am trying to use localhost to deploy.
this first file is the configuration for the apache2 web server and is located in /private/etc/apache2/httpd.conf I think my issue is with the ServerName. I do not have a domain to publicly host this web application from yet. I am trying to locally deploy it first. I have been using localhost:3000 for my development and want to deploy it using that as well. Maybe I am not understanding something vital here with deploying and ServerName.
httpd.conf
<VirtualHost *:80>
ServerName localhost.depot
DocumentRoot /Users/rubythree/Documents/agile-web-development-with-rails-5.1/production/depot/public
SetEnv SECRET_KEY_BASE "secret_key_here"
<Directory /Users/rubythree/Documents/agile-web-development-with-rails-5.1/production/depot/public>
AllowOverride all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
the next file where an issue might be is the hosts file located in /private/etc/hosts where I added the following line...
hosts
127.1.1.1 localhost.depot
I am new to Phusion Passenger and Apache and am pretty sure I am missing something in my configuration files here. When i try to access the ip 127.1.1.1 after a while of loading the browser will not be able to reach the server. running curl 127.1.1.1 will not return anything either, it will timeout. Any help or direction is appreciated :)

Even if ServerName does not match - apache will serve the first virtualhost as default.
"This machine" address is 127.0.0.1, also make sure apache is actually running and has no errors in logs

Related

Passenger (Apache) on EC2 not loading Rails application when arrive via DNS

This is driving me nuts. Hopefully someone can help
I've deployed a Rails app on an EC2 instance (Ubuntu) using Apache and Passenger. Here's my Apache configuration on the EC2 instance
/etc/apache2/apache2.conf
<VirtualHost *:80>
ServerName ec2-52-16-160-160.eu-west-1.compute.amazonaws.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /home/ubuntu/workspace/intellitute/public
ErrorLog /home/ubuntu/workspace/intellitute/log/error.log
RailsEnv development
<Directory /home/ubuntu/workspace/intellitute/public>
# This relaxes Apache security settings.
AllowOverride all
Require all granted
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
This works and I'm able to access the application by putting ec2-52-16-160-160.eu-west-1.compute.amazonaws.com into a browser.
I've registered a domain name with a provider (not AWS) and set up two 'A' DNS records there (appname.com & *.appname.com) to point at the public ip of my server - 52.16.160.160.
I've then changed the ServerName in the conf file above to the domain name I registered and restarted the Apache server.
<VirtualHost *:80>
ServerName www.appname.com (also tried 'ServerName appname.com')
.....
But when I type www.appname.com into a browser I'm just getting the Apache2 Ubuntu Default Page. I'm assuming the fact I'm getting the default page means the DNS is working but for some reason Passenger is not loading the application? Is this assumption correct?
Does it make a difference that I'm still working in the development environment?
I'm stuck and can't find any solution.
Thanks for looking
Edit 1
I'm not at my development machine at the moment but does it make a difference that I haven't set up an elastic IP address on my EC2 instance? I'm just using the public IP address provided by the instance. I'll try set one up later to see what happens.
Finally figured this out. Might help someone in the future.
My EC2 instance was a clone of another and I reckon there was some issues with the apache2 and passenger configurations. I uninstalled and re-installed them on the EC2 instance and it is now working (for appname.com, not www.appname.com - I'll have to figure that out)

How do I deploy to Google Compute Engine using the Ruby stack?

I'm totally lost trying to deploy a demo Rails app to my-app-name.appspot.com. I set up a project in the Developers Console and deployed the Ruby stack on my VM. I would have thought I just need to configure the web server's default site such that the DocumentRoot is the public folder of my Rails app (from /etc/apache2/sites-available/default):
<VirtualHost *:80>
ServerName my-app-name.appspot.com
DocumentRoot /apps/my-app-name/public
<Directory /apps/my-app-name/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Since I'm aiming for the my-app-name.appspot.com space and not using a separate domain, I'm guessing the ServerName and ServerAlias settings are not needed in this case. Now when I visit my target appspot.com address I get a 404 error:
Not Found - The requested URL / was not found on this server.
The logs show that Phusion Passenger is in fact listening to requests. And when I visit the numbered IP address for my project I still get Apache's default index page. Obviously there's a crucial part of the picture I'm not seeing, so any help is greatly appreciated.
Thanks to the posters who commented, I now understand that I was barking up the wrong tree. The appspot.com domain is not compatible with compute engine; I will have to access my project via the IP address.
Also, since I was only trying to put up a test app as proof of concept, I needed to set the Rails environment to development. I was frustrated until I found these instructions (Step 6): https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-apache-on-ubuntu-14-04
Detailed instructions how to deploy Ruby on Rails on Google Compute Engine:
http://startup-with-gae.blogspot.com/2015/08/how-to-deploy-ruby-on-rails-application.html

Middleman server and apache on cloud

I have a ruby on rails application which runs on Middleman Server. I installed that application in windows azure ubuntu virtual machine. After completing installation once i started my server by giving this command "middleman server" my application is running well. After that i have installed apache web server for that application by following this procedure
http://nathanhoad.net/how-to-ruby-on-rails-ubuntu-apache-with-passenger
but im getting this error after completing the above procedure
"it works! this is the default web page for this server. the web server software is running but no content has been added, yet."
Please help me how to install a webserver for a ruby on rails application which normally runs on middleman server.
You said you have Apache installed, there's your web server. And if you installed Passenger you have an application server for your Rails or Middleman. Check out the Phusion Passenger users guide, Apache version. I followed that to set up. Are you trying to view the src as you work or the build after you run middleman build? What are you building, a Rails or Middleman app/site?
I have been messing around with different approaches for Middleman Development setups. I ended trying a few different configurations and documented them in a Gist. Scroll down and there is some info on my Passenger version, I'm very new to MM and that was the first time I tried Passenger, so please take that into consideration. I think the trickiest part was that Passenger requires a public folder, but Middleman doesn't use a public folder at all. I think the Passenger with Middleman has a few more 'gotchas' over the other approaches. Check out the 3.0 in my Gist.
My vhosts file looks like this:
# Testing Middleman Development Approaches #3 with Passenger,
# note the public folder is used to serve the src directory
<VirtualHost *:80>
ServerName mm_passenger.loc
DocumentRoot /Users/davekaplan/mm_passenger/public
ServerAlias mm_passenger.loc.*.xip.io
<Directory /Users/davekaplan/mm_passenger/public>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName mm_passenger.build
DocumentRoot /Users/davekaplan/mm_passenger/build
<Directory /Users/davekaplan/mm_passenger/build>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I'm on Mac running Apache and Passenger. I did a virtual host (path to site files) to the Apache /etc/apache/extra/httpd-vhosts.conf file and the domain to my /etc/hosts file.
Don't give up!
Dave

How to run\handle multiple Ruby on Rails applications on the same domain?

I am using Ruby on Rails 3.1 and I have an application running at the www.mywebsitename.com domain. For improvement reasons I would like to run my application at the www.uk.mywebsitename.com subdomain (BTW: at the www.mywebsitename.com domain I will run a RoR application to redirect users to the proper subdomain).
I do not need geocoding or similar. Simply, I would like to know how to run my application on the www.uk.mywebsitename.com Web address (I am planning to add as subdomain other/similar RoR applications like www.de.mywebsitename.com and www.it.mywebsitename.com, each working with a separate database): what I have to care/do? what do you advice about?
P.S.: My server is running Linux Ubuntu and Apache. I deploy with the Capistrano gem.
It seems like you're looking for how to make apache vhosts, since that's basically what they do.
I assume you're using phusion passenger, and in that case you should already have one vhost (or at least a default site in /etc/apache/sites-available (or something similar, it might be apache2, I'm not entirely sure).
What you basically need to do to get multiple rails applications working is to set up one vhost for each rails application and set the proper ServerName and DocumentRoot for each vhost.
It might look something like this for you uk site:
<VirtualHost *:80>
ServerName www.uk.mywebsitename.com
DocumentRoot /path/to/where/your/uk/site/is/deployed/current/public
<Directory /path/to/where/your/uk/site/is/deployed/current/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
How to setup vhosts for passenger is documented in the passenger documentation.

How do I setup my Rails Apps to Run through Phusion Passenger?

I have the following doubt:
I have an application in Rails+MySQL and I want to run this with Apache + Passenger, I have both installed, but when I run ./script/server my app starts running with WebRick, how do I change it for work with Passenger and Apache?
P.S: I'm on Ubuntu 9.04 Jaunty Jackalope, please consider the fact I'm a newbie =)
If passenger is installed (and the module is in apache), all you need to do is point an Apache VHost's DocumentRoot at your public directory. Passenger should take care of the rest.
There is no separate server to start, the app runs direct from Apache (just like mod_php, but without the cooties).
A more detailed explanation is available here.
You need to put it wherever you told Apache to serve it from. script/server will no longer be involved.
Passenger is more of an always-on type of setup. You don't use script/server to start it, because it automatically shuts down if you're not actively using it, and reactivates when you start using it again. I personally have an /etc/hosts entry that maps myapp.local to 127.0.0.1, and then I use Apache's virtual hosts to identify which Rails app to start.
<VirtualHost *:80>
ServerName myapp.local
DocumentRoot /apps/myapp/public
RailsEnv development
</VirtualHost>
If you're running multiple apps on your own box (i.e. a development box) a friend of mine has got a gem that will help with the /etc/hosts writing called Ghost.
You can use it like:
sudo ghost add domain.local
And now in your browser typing domain.local will point to 127.0.0.1.

Resources