I have a PHP script with a web interface which is used to provide input into a process which is now automated. I am attempting to include committing and pushing to Git in this process by executing git commands through PHP's exec. I am able to pull in the remote repository, add files and get the status of it. However, I am running into an issue when attempting to commit my changes.
When I attempt to commit, I get:
[0] =>
[1] => *** Please tell me who you are.
[2] =>
[3] => Run
[4] =>
[5] => git config --global user.email "[email protected]"
[6] => git config --global user.name "Your Name"
[7] =>
[8] => to set your account's default identity.
[9] => Omit --global to set the identity only in this repository.
[10] =>
[11] => fatal: unable to auto-detect email address (got 'tim@tim.(none)')
It is my understanding that Git is not resolving my global config at ~/.gitconfig, which it can do when executed normally through a Terminal. I have Apache running under my user and group. When I attempt to run the commands suggested above, I get:
[0] => fatal: $HOME not set
How can I resolve this?
You need to check the available environment variables that you have in Apache. You can do this using
http://php.net/manual/en/function.get-defined-vars.php
Apache starts as root and switches to an unprivileged user but the env variables are not set for that user See here..
https://serverfault.com/questions/179833/apache2-user-home-directory-lock-to-root
Note, the home directory on a linux system is set in /etc/passwd. Here's an example
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
But in Apache this just sets the document root because it's not setting up env variables the way a normal login would ie reading profiles etc. You can set env variables in Apache using
SetEnv HOME /home/foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With