Automated git pull with php on bitnami

Hi,

Well I can certainly try. It was a bit tricky.

The big problem for us I believe was to give the Apache User permissions. In our case the Apache user was daemon and we had to generate a ssh key for that user and then add that key as deployment key in our Gitlab project.

If you don’t know your Apache User create a .php and paste in this code and then go to that .php file from the web browser:
<?php echo exec('whoami');

After that you can run these commands in the console to generate a ssh key.
sudo -u your_apache_user ssh-keygen -t rsa
Make sure that you just give an empty password for the key and then paste the SSH key into deployment key.
After that we had to run a git pull from the console in order to add it to known_hosted
sudo -u your_apache_user git pull

Then create a .php script and all we have for now in our webhook script is
<?php echo shell_exec("git pull origin master 2>&1");
The 2>& 1 gives you output that will help you to debug what is going wrong. This will make sure it only gets whats new on our master branch.

Add a Web hook in your Gitlab project for push events and add your url to your .php script. Also make sure the files your are updating and accessing that the Apache User has permissions to change them.

Hopefully that can help you get a step forward :).

1 Like