Search code examples
phpcapistranosymlink

Capistrano Symlinks Being Cached?


I've been setting up PHP deployments with Capistrano on CentOS 6 and have run into an interesting issue. The way capistrano works, it sets up folders like this:

  • /var/www/myapp.com/
    • current (symlink to latest release in /releases)
    • shared
    • releases
      • 20130826172737
      • 20130826172114

When I look at the "current" symlink, it points to the most recent release. At first, when opening my web app, everything worked fine. After deploying a new release, the current folder correctly points to the new release, but the web application tries to load files from the old release (which has been deleted in a Capistrano cleanup process). Also, the virtual host is configured to point at /var/www/myapp.com/current/Public.

Are symlinks cached in any way?

The specific PHP code that fails (which initializes my framework) is this:

require_once dirname(dirname(__FILE__)) . '/App/App.php';
App\App::run();

That is in index.php currently located at /var/www/app.com/current/Public/index.php.

My Apache error logs show:

PHP Fatal error: require_once(): Failed opening required '/var/www/myapp.com/releases/20130826172237/App/App.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/myapp.com/releases/20130826172237/Public/index.php

And the current symlink shows:

current -> /var/www/zverse/releases/20130826172641

Obviously 20130826172641 != 20130826172237 which the latter was the previous version.

Any ideas or areas I can look at?


Solution

  • I can't verify this, but it seems that there is some unpredictable behaviour with Apache following / caching the old location of symlinks:

    The only thing that would absolutely clear up this issue was to cycle Apache, which we would prefer not to do on every deployment. -- Mike Brittain

    He suggests moving the whole directory, instead of updating the symlink.