When I run the script <?php chdir('/var/www/html'); echo shell_exec('git pull origin master 2>&1'); ?>
, I get the error message:
error: cannot open .git/FETCH_HEAD: Permission denied
Here's what I did:
ssh [email protected]
pwd # shows that I'm already at /var/www as my home directory
ls .ssh/ # shows that I have id_rsa and id_rsa.pub, and id_rsa.pub is given to github
cd html
git pull origin master # everything downloads perfectly
echo "<?php chdir('/var/www/html'); echo shell_exec('git pull origin master 2>&1'); " > pull.php
Now when I go to http://example.com/pull.php
I get the error cannot open .git/FETCH_HEAD: Permission denied
.
To confirm my permissions, I logged in as root to do a chown -R apache:apache /var/www
. I also have this in my /etc/passwd
apache:x:48:48:Apache:/var/www:/bin/bash
What am I doing wrong?
php -i
). This looks like thechdir
could be ignored by the forked shell, see the 'Caution' at php.net/manual/en/function.chdir.php. Also worth checking SELinux contexts if running CentOS/RHEL.