I also ran into this issue, there is hardly any documentation for beginners.
Here are the steps I took to get this working with gitlab:
make sure to have an SSH key on the server that you want to auto deploy on, for me this was an Ubuntu server. I had to generate an SSH key for the www-data so the user could connect to the gitlab server.
I had to run this command to generate an ssh key for the www-data user:
sudo -u www-data ssh-keygen -t rsa
After you generate the ssh key you have to add it to the gitlab to your projects deploy keys. (project->settings->deploy keys).
now goto the folder that you want your project to push to (for me it was /var/www/website/) and do the following:
git clone origin-url .
the dot at the end makes it so it only pulls the files, and doesn't include the folder your project is in on gitlab.
then...
chgrp -R www-data .git
chmod -R g+rwxs .git
That gives permission to the git folder to execute php commands and adds the www-data group to the folder.
after that i had to make a script that would run the commands i wanted when the hook was called.
here is the php that i am using, i named the file webhook.php
<?php
if($payload = file_get_contents('php://input')) {
try {
$payload = json_decode($payload);
} catch(Exception $ex) {
echo $ex;
exit(0);
}
// put the branch you want here
if($payload->ref != "refs/heads/master") {
echo "wrong head";
exit(0);
}
//put the branch you want here, as well as the directory your site is in
$result = `cd /var/www/website && git fetch origin && git merge origin/master`;
echo $result;
} else {
echo "failed request";
}
?>
the webhook.php will need execute permissions from www-data as well.
once all that is done you will need to make the webhook in your project (project->settings->webhooks)
add the url to the webhook.php
I put my webhook.php in a subdomain on the server so I could use it to push different sites with the same file.
http://deploy.website.com/webhook.php
I also added used http://requestb.in so that I could make sure of the data that was getting sent to the server.
Not sure if i'm forgetting anything, but I think this was everything i did