Search code examples
symfonycygwinrsync

Symfony 2.2.1 rsync deploy - not working on remote server


I'm very new to Symfony and I'm trying to automate the deploy process with rsync, while keeping both the local and remote installs of Symfony working.

What I've done so far:

  • installed Cygwin on my local machine (Windows 7+Apache2.2+PHP 5.3+MySQL 5.1)
  • done a basic Symfony install on my local machine from shell with the command php composer.phar create-project symfony/framework-standard-edition [path]/ 2.2.1
  • set up a remote LAMP Ubuntu server with php-fpm (fastcgi)
  • set up two different configuration files for local and remote in the app/config/ dir, parameters.yml and parameters.yml.remote
  • created an app/config/rsync_exclude.txt file containing a list of files not to rsync to the remote server (as suggested in this page)
  • created a deploy shell script that I run from Cygwin (see below)

The deploy script issues the commands:

rsync -avz /cygdrive/c/[path]/ user@server:[remote-path]/ --exclude-from=/cygdrive/c/[path]/app/config/rsync_exclude.txt
ssh user@server 'cd [remote-path]/ && php app/console --env=prod cache:clear && php app/console cache:clear'
ssh user@server 'mv [remote-path]/app/config/parameters.yml.remote ~/[remote-path]/app/config/parameters.yml'

The rsync, ssh and mv commands work, but the deployed site shows always a HTTP 500 error (both app.php and app_dev.php). Looking at server error log the error is:

Fatal error:  Class 'Composer\\Autoload\\ClassLoader' not found in /[remote-path]/vendor/composer/autoload_real.php on line 23

Any clue would be more than welcome.

Edit - here is my vendor/composer/autoload_real.php file (sorry for the making the question longer!):

<?php

// autoload_real.php generated by Composer

class ComposerAutoloaderInit9d50f07556e53717271b583e52c7de25
{
    private static $loader;

    public static function loadClassLoader($class)
    {
        if ('Composer\Autoload\ClassLoader' === $class) {
            require __DIR__ . '/ClassLoader.php';
        }
    }

    public static function getLoader()
    {
        if (null !== self::$loader) {
            return self::$loader;
        }

        spl_autoload_register(array('ComposerAutoloaderInit9d50f07556e53717271b583e52c7de25', 'loadClassLoader'), true, true);
        self::$loader = $loader = new \Composer\Autoload\ClassLoader();
        // ^^^^^^ this is line 23 and gives the error ^^^^^^^^^^^
        spl_autoload_unregister(array('ComposerAutoloaderInit9d50f07556e53717271b583e52c7de25', 'loadClassLoader'));

        $vendorDir = dirname(__DIR__);
        $baseDir = dirname($vendorDir);

        $map = require __DIR__ . '/autoload_namespaces.php';
        foreach ($map as $namespace => $path) {
            $loader->add($namespace, $path);
        }

        $classMap = require __DIR__ . '/autoload_classmap.php';
        if ($classMap) {
            $loader->addClassMap($classMap);
        }

        $loader->register(true);

        require $vendorDir . '/kriswallsmith/assetic/src/functions.php';
        require $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php';

        return $loader;
    }
}

Solution

  • If there is an error with the autoloader generated by composer, performing ...

    composer update
    

    ... will update your dependencies and create a new one.

    You should invoke the command with the -o flag if you are deploying to a production system.

    This way composer generates a classmap autoloader ( which performs way better ) instead of the classic autoloader.

    composer update -o
    

    I guess re-generating the autoloader will solve the issue :)