Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running git pull from a php script

I was trying the Perfect Workflow, with Git, GitHub, and SSH, and i have everything set up, except running the command git pull from php.

When i run exec('git pull') i get:

Could not create directory '/.ssh'. Host key verification failed. fatal: The remote end hung up unexpectedly

If i run it in the terminal (as root) it works just fine, but i need this hook to work from the Post-Receive URL (Github).

If i do exec('whoami') i get apache.

It's a (dv) from mediatemple with CentOS.

like image 598
AFRC Avatar asked Feb 21 '12 01:02

AFRC


People also ask

How do I pull a Git repository?

PULL Request Or also called a target repository. The simple command to PULL from a branch is: git pull 'remote_name' 'branch_name' .

Can I deploy PHP project on GitHub?

Upload SSH Key To GitHub RepositoryOn Github, navigate to the repository and find the code which you want to deploy. If you are using another Git service, you will have to find the equivalent way of deploying them. Go to Settings -> Deploy keys and click on the Add Deploy Key button to add the SSH key.


1 Answers

If you want apache (the user) to be able to pull from git, you'll have to create an ssh key for apache, then add that to the read only keys on github.

The flow is something like this (tweak to your needs)

usermod -s /bin/bash apache
su apache
cd ~
ssh-keygen # work through the keygen dance (added a dash)

Upload (tilde here refers to apache's homedir) ~/.ssh/id_rsa.pub to github and give apache access to whichever repos it needs to pull from.

Then you can test on the server by again su'ing to apache and running the git pull

su apache
cd ~/working-copy
git clone my-project

Once that's working you should be able to run a git pull through PHP.

like image 144
quickshiftin Avatar answered Sep 29 '22 23:09

quickshiftin