Configure a VirtualHost for Rails Apps with Apache+Passenger on subdomain

September 10, 2013 13.5k views
Hi :) I followed some tutos and did a search on my issue on google, but no answer found worked for me. I hope you will be able to help me. Here is my configuration : First, I have installed a LAMP for my PHP projects, so apache2 and mysql are correctly installed. I work in the folder : /home/ME/www (where I put my projects) And then, I linked with a symlink my folder /var/www eg: ln -s /home/pixy/www/project1 /var/www/project1 And I have correctly added a vhost (in sites-available, and a2ensite...) This PHP project correctly works on my subdomain : (don't try, project1 is fake for the example ^^) I also would like to run my Rails (4) applications, so I followed the tuto on Digital Ocean to install passenger with apache2. I think the compilation succeed, I had no problem (I think...) I also put the three lines given at the end of the install at the end of my apache2.conf file Then I put a new project on my workspace : /home/pixy/www/blog I want to access to this application with a vhost, with the subdomain : I tried a lot of configurations, but no one worked =( I tried to : - symlink /home/pixy/www/blog /var/www/blog and then configure my DocumentRoot to this path : /var/www/blog - No symlink, and directly put the DocumentRoot at /home... And others but I don't remember I pastebin you my actual configurations : - My default vhost : - My blog vhost : I linked as symlink : /home/pixy/www/blog /var/www/rails/blog You can try, it doesn't work... What is wrong/missing with this config ? Do I have to a2ensite the config ? (I think I did it) Do I have to put the PassengerAppRoot ? I work with ruby 2 and rails 4 If you have any question on my config I forgot to tell here ask me. Many thanks in advance for your help ! :)
10 Answers
First, let's make sure you're not having permissions problems.

In your /var/www directory, what's the output of ls -la?
root@pixy:/var/www# ls -la
total 16
drwxr-xr-x 3 root root 4096 Sep 10 07:00 .
drwxr-xr-x 12 root root 4096 Sep 8 19:39 ..
-rw-r--r-- 1 root root 177 Sep 8 19:39 index.html
drwxr-xr-x 2 root root 4096 Sep 10 07:11 rails
And in my rails folder :

root@pixy:/var/www/rails# ls -la
total 8
drwxr-xr-x 2 root root 4096 Sep 10 07:11 .
drwxr-xr-x 3 root root 4096 Sep 10 07:00 ..
lrwxrwxrwx 1 root root 19 Sep 10 07:11 blog -> /home/pixy/www/blog
Check apache's error logs for errors:

tail /var/log/apache2/error.log

Do you see anything?
With this configuration :

I have the error :

[Tue Sep 10 19:17:04 2013] [error] [client] Directory index forbidden by Options directive: /home/pixy/www/blog/public/

"You don't have permission to access / on this server."

With this one :

No error, I just see my directory...
You can check here :
I believe apache runs as www-data by default so you will have to allow www-data to read your home dir/website's files.

chgrp -R www-data /home/pixy/www

chmod -R g+r /home/pixy/www

Let me know if that fixes it.
No =(

I don't know why, but with this config :

It works !! The error seemed to be
PassengerAppRoot /home/pixy/www

I removed the line

I'm pretty sure I tried without before...
But it now works :)

Maybe it can help someone one day !

Thank you for you help =)
Ah, sweet! Glad it works now! :]
PS : You were right :

chgrp -R www-data /home/pixy/www
chmod -R g+r /home/pixy/www

Is the right thing to do, thaks again :)
Great! Glad it worked! :]
Have another answer? Share your knowledge.