4

I have recently setup Capistrano on my server and it works great.
I changed my virtual hosts to point to the symbolic link created by Capistrano.
My virtual hosts file:

<VirtualHost *:80>
    DocumentRoot /var/www/html/my_app.com/current
    ServerName my_app.com
    <Directory />
    Options FollowSymLinks
        AllowOverride Indexes
    </Directory>
</VirtualHost>

When I restart my apache server using sudo service httpd restart, I get the error:

Warning: DocumentRoot [/var/www/html/my_app.com/current] does not exist

The current directory definitely exists. When I set the vhost to point to .../my_app.com/, it works and shows the default apache page, the problem is this symbolic link to current (which is updated as I deploy applications using capistrano).

I am using a Amazon ec2 instance, apache 2.2 (LAMP).

so basically, how do I point a virtual host to a symbolic link?


Update The output of ls-l:
lrwxrwxrwx 1 ec2-user ec2-user   57 Aug 28 22:40 current -> /var/www/html/my_app.com/releases/20120828223437
drwxrwxr-x 3 ec2-user ec2-user 4096 Aug 28 22:40 releases
drwxrwxr-x 6 ec2-user ec2-user 4096 Aug 28 16:01 shared

In my httpd.conf(comments stripped out):

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

My Error Logs:

[Wed Aug 29 00:04:39 2012] [error] [client 87.194.51.136] Symbolic link not allowed or link target not accessible: /var/www/html/my_app.com/current
[Wed Aug 29 00:04:40 2012] [error] [client 128.30.52.73] Symbolic link not allowed or link target not accessible: /var/www/html/my_app.com/current
[Wed Aug 29 00:04:40 2012] [error] [client 87.194.51.136] Symbolic link not allowed or link target not accessible: /var/www/html/my_app.com/current, referer: http://mydomain.com/

The ouput of ls -l for /var/www/html/my_app.com/releases/20120828223949.

drwxrwxr-x 6 ec2-user ec2-user 4096 Aug 28 22:39 20120828223949

When I run the command ls -l /var/www/html/my_app.com/current/

ls: cannot access /var/www/html/my_app.com/current/: No such file or directory

Looks like a dead symlink... How do i fix this?

Anil
  • 262
  • 2
  • 4
  • 15
  • 2
    Can you provide us with the output of `ls -l /var/www/html/my_app.com/`? At any rate, you should probably know that using symlinks in this way can [lead to problems](http://www.mikebrittain.com/blog/2009/05/12/case-against-using-symlinks-for-code-promotion/). – brain99 Aug 28 '12 at 23:36
  • This can be permission on one of the sub-folders of the destination of the link, as symlink is always rwxrwxrwx, so you need to grant your apache access to it. – Andrew Smith Aug 28 '12 at 23:36
  • What are your logs showing? You can set an errorlog in the virtual host `ErrorLog /home/httpd/logs/error_log` – JMeterX Aug 28 '12 at 23:54
  • This may or may not work but try disabling SELinux `setenforce 0` This command will temporarily turn it off – JMeterX Aug 29 '12 at 00:46
  • 2
    Does the apache user (I assume apache runs as user ec2-user) have execute permissions on `/var/www/html/my_app.com/releases/20120828223437` and all parent directories? – brain99 Aug 29 '12 at 03:46
  • I've updated the post to include the dir permissions for the releases dir. – Anil Aug 29 '12 at 09:51
  • 1
    Unless you've redeployed between edits, your problem is a dead symlink. `current` is pointing at a directory ending `223437`, and your `releases` directory contains a directory ending `223949`. – nickgrim Aug 29 '12 at 10:01
  • 1
    Does `ls -l /var/www/html/my_app.com/current/` (note trailing slash) return what-you-expect? – nickgrim Aug 29 '12 at 10:05
  • No, I get the error ls: cannot access /var/www/html/my_app.com/current/: No such file or directory. – Anil Aug 29 '12 at 12:23
  • When I try and symlink it again `ln -sf /var/www/html/my_app.com/current /var/www/html/my_app.com/releases/20120828223949/`, Nothing is outputted but the symlink still points to the old dir. – Anil Aug 29 '12 at 12:25
  • You've got the arguments to `ln` in the wrong order, it should be "from" then "to" (like `cp`). – nickgrim Aug 29 '12 at 12:37

1 Answers1

3

As-per-my-comment and your follow-up it looks like your current symlink doesn't point to a valid target; remove it and re-add it:

$ rm -f /var/www/html/my_app.com/current
$ ln -s /var/www/html/my_app.com/{releases/20120828223949,current}
nickgrim
  • 4,466
  • 1
  • 19
  • 28
  • Thanks! I ran `rm -f /var/www/html/my_app.com/current && ln -s /var/www/html/my_app.com/releases/20120828223949 /var/www/html/my_app.com/current` and it worked! – Anil Aug 29 '12 at 12:39