Yii failing on re-deployment of application

I am using a “build pipeline” in Jenkins to subject a Yii application I’m working on to a battery of unit tests and regression/integration/UAT tests.

The last job in the build pipeline releases the application to the production environment.

Unfortunately (for me), sometimes the release to production does not work (very annoying as it’s intermittent).

The release job uses rsync to release the application:

export SSHKEY=/var/lib/jenkins/.ssh/id_rsa

export DESTDIR=/var/www/myapp.com/public_html

export DEPLOY_SERVER=myserver.com

rsync -arvz --exclude '/yii' --delete -W --ignore-errors --force $BUILD_LOC/. root@$DEPLOY_SERVER:$DESTDIR

ssh -i $SSHKEY root@$DEPLOY_SERVER '

chown -R www-data:sysuser' ${DESTDIR} '

cd ' ${DESTDIR} '

if test ! -d ./assets; then mkdir '$DESTDIR'/assets; fi

if test ! -d ./protected/runtime; then mkdir '$DESTDIR'/protected/runtime; fi

chown -R www-data:sysuser ./*

chown -R www-data:sysuser ./.ht*

chmod -R 770 ./*

chmod 770 ./.ht*


I’m not copying over the contents of the protected/runtime directory, and the assets directory is empty.

My .htaccess file is as follows:

RewriteEngine on

# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php

The (intermittent) error I get is:

Cannot redeclare class Controller in /var/www/myapp.com/public_html/protected/components/Controller.php on line 7

If I first remove everything (except the Yii directory), then everything seems to work, but this defeats the purpose of rsync (I only want to deploy files that have changed to keep deployment as quick as possible). So, performing the following:

rm -rf assets/ css/ favicon.ico .htaccess images/ index* protected/ themes/ 

as the first step in my deployment job will ensure everything works.

Does Yii use some kind of persistent state data from somewhere else? What is causing this?

Thanks in advance.

I would guess that the include path is different on your production environment. Maybe it refers to a location where a PHP Class "Controller" already exists. It could also be a PEAR package that contains such a class.