Tag Archives: deploy

Auto-deploy your Virtualmin website with git

Virtualmin’s non-standard implementation of git can be a little awkward to work with, primarily because git itself assumes too many things about the environment by default. However, there is a very easy way to auto-deploy your website from a virtualmin git repo to your virtualmin website root (public_html) using git hooks.

This assumes you have installed git onto your virtualmin server, and will be accessing the remote (virtualmin) repository over ssh (you can also use any protocol that works with git hooks; http doesn’t!)

  1. Create a new virtual server in virtualmin, and set up a repository for it
  2. On the virtualmin server (ssh into it, or whatever method you prefer), navigate to the git directory (/home/sitename/public_html/git/git.git/), and execute the following commands:
    git config core.bare false
    git config receive.denycurrentbranch ignore
  3. Then go to add the hook; go into the hooks directory, create a file called post-receive, and add the following:
    cd /home/sitename/public_html/
    git –git-dir=/home/sitename/public_html/git/reponame.git –work-tree=/home/sitename/public_html/ checkout -f
  4. Add execute permissions on the hook, and ensure the ownership is correct (www-data:sitename)
  5. And that’s it…get the url for your repo (something like sitename@siteurl:public_html/git/git.git), and set it up on your local copy of git, then create some files and push from local to remote and it should automatically deploy – by the way, you will need to use “git push origin master” the first time you push to the empty repo

I think this will just deploy the master branch, and I don’t think it will delete files that are deleted locally (not sure exactly how the checkout command works).

I’ll be adding another tutorial that incorporates branches and proper sync between the two.