Rails application permission on apache - ruby-on-rails

What should be the permission on rails app directory on apache server???

What is your deployment design?
Normally you'd use mongrels and apache as a load balancer for them.
So you'd run the mongrels as a user for your site, and all the rails directory should have permissions for that user.

You probably have a 'www' or 'apache' user that owns your static content and apache root document directory.
It's common convention to make this user own your rails app as well to preserve the same permissions.
If you use something like capistrano, I think it has builtin recipes for permission structure on top of your release directory after deploying.

As Angelus said, it depends on your server setup and deployment design. You can use mongrels (or thins, or unicorns, or...) with Apache as a reverse-proxy, but your question leads me to believe you're using Phusion Passenger (aka mod_rails).
If that's the case, the mod_rails site has several very helpful screencasts which you should watch. Generally, though, mod_rails will run as whichever user owns your app's environment.rb file. See the Passenger user switching docs for details on your permission setup.

While installing apache it creates www-data group and owner so you have to give the ownership of this user for your application.
Then restart the apache service.
rails application works fine.

Related

Setting up Rails on Hostmonster

I'm able to run rails s through ssh successfully and see the app start up just as it does on my own machine but I'm unable to access the app from the web. The app is directly under the home folder and I have a symbolic link pointing from public_html to the public folder of my rails app, just as this tutorial explains. I even tried setting up a subdomain and every other step in the tutorial to no avail. Any help would be highly appreciated.
You need an application server like Phusion Passenger, Unicorn or puma to run a Ruby app in a production environment. Typically, you'll integrate the application server into a web server's (Apache, nginx) environment.
I don't know about your hoster, but if you have root access, then you can probably use any of these application servers.
The built-in server you start by running rails server is only meant for testing purposes on your local machine. It has not been made with security, performance, stability or any other production-environment criteria in mind.

Two Rails apps deployed - How do I change the default App?

I've followed Ryan Bate's guide to deploy two completely different rails apps one one VPS (cost saving, using it for development of small home projects). Link to railscast: http://railscasts.com/episodes/335-deploying-to-a-vps
My issue is: the default application is the one I deployed first, so when I visit the IP address, that is the app which is displayed. How do I configure the server to
Use a subdomain (not sure this is possible using just an IP address)
Change the default app
Had a play around in nginx.conf and read this stack q: NGinx Default public www location?
I can't seem to work it out! Thanks in advance.
I think I understand what you want to do. Your default app term confuses me. Let's throw that out and just say you want to deploy two different rails apps to different domains-- sub or TLD, it doesn't matter. Also, I think you are wanting to deploy them to the same VPS server. Ryan's screencast doesn't include how to do this.
What you are probably looking for is how to host multiple sites (and rails apps) with nginx. Like Ryan's screencast, there are many steps involved to get everything working. I recommend you first focus on domain setup (DNS), then nginx setup. Leaving serving your rails app with unicorn for last.
First
Setup your domain and subdomain to point to the VPS. One way is to create DNS A records point to your VPS IP.
Second
Configure nginx to serve both sites. To get you started in the right direction I recommend you read this: multiple websites on nginx & sites-available. It sounds like you already have nginx serving your app on your domain. So steps might be like:
$ cd /etc/nginx/sites-available/
$ cp default subdomain.example.com
Edit subdomain.example.com accordingly. See nginx docs for details. Also, make sure /sites-available/default and /sites-available/subdomain.example.com are not using _ as server_name directive. Set them to their respective domain names. Also, for now point the root to somewhere that will serve an index.html file (ie. leave rails out of it for now)
$ cd /etc/nginx/sites-enabled/
$ ln -s ../sites-available/eden.jrutherford.com .
$ service nginx restart
If all is well by this point you should be able to visit both domains in a browser and have nginx serve content.
Third
Configure a new unicorn for your subdomain. I'm sorry I don't have specific tips for this step . Follow Ryan's tutorial, search google, unicorn website.
Good Luck.

Nginx & Passenger user permissions. Best practice?

I'm new to nginx, what's best practice for user/group permissions, when deploying (Ruby) application, using nginx and passenger?
Is better deploy as root or "deployer" user in some group? And how should I set folder/file permissions.
On Apache server I have /public /log and some other folders writible by www-data and user is root. This configuration doesn't work on nginx (for me).
Thanks
You should use separate user per application and Passenger/Nginx should automatically use the directory owner to run the process, never use root user.

Running multiple rails applications using Passenger

I'm using Passenger as the application server for rails applications in nginx.Is it possible to run multiple rails applications using a single Passenger instance ?
Thank You
Yes you can definitely run multiple applications on Phusion Passenger. Remember that according to the Phusion Passenger documentation you're supposed to setup a virtual host with a certain domain name, and then pointing that virtual host's document root the application's "public" directory? Well... if you want to deploy more applications, you do the exact same thing. You add more virtual hosts, and in the other virtual hosts you point to other applications' "public" directories.

Setting up Apache for Rails production

I am developing a Rails 3 application and I have installed Capistrano on the client side and Passenger with Apache 2 on the server side.
I make a deployment and the files are sent to a folder called u/apps/.
But when I visit the IP address I am currently using I only get to an empty folder, how do I configure Apache to look for my app in the current folder? So that I only need to visit my IP/domain to see my app?
I have done this using Rails 2.x but I think for Rails 3 also pretty much the same thing. For this you need to use Passenger and then configure Apache.
Following are some useful resources
http://www.modrails.com/install.html
http://railscasts.com/episodes/122-passenger-in-development
If you browse to your URL and you see an apache files/folders list that means that passenger is not triggered for that location...
Test your server environment by running a mongrel/thin in your application folder and see that your application runs correctly. After that, look at your Apache configuration (see Passenger docs).

Resources