Website updating from git (over ssh)

bashgitsshwebserver

I have a script that I run over SSH, which updates my website from a Git repo.

cd website-git
git checkout master
git pull

# Update protected directory
rsync -v -a --delete --exclude=db --exclude=vendor ./protected/ /home/protected

# Update public directory
rsync -v -a --delete --exclude=tmp --exclude=data ./public/ /home/public

It works fine, but the git repository has 150 MB and I pay for space used, so this is not a very good solution.

Apart from deleting the working copy (initially obtained with git clone) after taking the files form it, is there some way to save space with this setup?

Best Answer

You should investigate how to use Capistrano to deploy your PHP code instead of reinventing the wheel with a Bash script like this. Capistrano is basically a series of Ruby scripts that in-turn then run a series of Bash commands to deploy code from a code repository to a remote server.

Although Capistrano is mainly used in the Ruby development world, but I have used it on tons of PHP projects and it works great. This is a nice tutorial on how to adapt Capistrano for usage in PHP applications. Ditto with this one.

If space is a concern, once you have your Capistrano scripts setup be sure to set the :keep_releases setting to something low like 2 or 3 like this in the Capistrano script:

set :keep_releases, 3
Related Question