Git PHP Submission

Source: Internet
Author: User
Tags apache log

Do a small demo, you can view:

Https://github.com/feixiang/webgit.git

These days have been depressing things. Git executes well inside the shell, and Apache runs the user into git, but it can't be submitted while the GIT project is being submitted.

At first I thought it was a file permissions issue because the permissions issue was the biggest problem on Linux.

However, although the directory is set to 777 of the authority (do not learn, test), or can not submit, so the heart is cold ...

When asked a colleague today, accidentally changed Apache user from Git back to Apache, accidentally found! To be able to submit success!

The Apache user was previously set to Git because Git was deployed on the Web server, forming the GIT + FTP + web development environment. Later, I tried to change the git user group, and still did not succeed.

Try to change Apache users to nobody, accidentally found! can also submit success!

Seeing here, I began to wonder if the gitolite (GIT Privilege control system) limited the SSH user connection. So I tried to use a user without SSH authentication as Apache user, but no use ... So, think again, is not Apache users have what special permissions? In fact, this direction should be wrong ... Omitted... It is possible that there is a problem with SSH authentication .... To be continue ...

———————————— November 12, 2012 16 O'Clock Update ————————————————

Finally solved the problem! The reason is still the authority problem! Analyze this issue from the Apache log to analyze.

Analyzing the Error_log log helped me complete the task. On my server redhat, Apache log files are/var/log/httpd/

Next: When the Git user commits the commit, the commit is always unsuccessful and there is no output. Of course, this is only in the environment of PHP no output, in fact!

An internal error occurred, and Apache recorded these errors in the error_log.

At the time, the error I got was probably this: [HTML]

* Please tell me who is. Run git config--global user.email "[email protected]" git config--global user.name "Your name" to set Your account ' s def Ault identity. Omit--global to set the identity of the This repository. Fatal:empty ident not allowed [/html]

When Git commits, git does not recognize the configuration of the currently committed user and is blocked by Gitolite.

But git users have already set the username and email. This also involves the global--global settings of git config and the config settings of the current Git repository.

Since the Apache directory is restricted to my web directory, git users cannot read the global configuration information, of course, not sure to commit the user!

Based on this idea, I re-set the local config for each git repository initialization in PHP.

So, commit again! So! Submit Success! Push succeeded!

Focus on problem solving, in-depth analysis of logs ... In solving this problem, we found that Apache log files are very large, we can set additional, limit the size of log files.

Attached PHP code, non-professional, learning edge with ...

function Commitproject ($project) {$remote = "localhost";        $GIT = "/usr/bin/git";        $COMMITMSG = $_get[' commit '];        $Root = $_server[' document_root ');                    $projectRoot = "$Root/$project";        ChDir ($projectRoot);          First determine if git builds an if (!file_exists (". Git")) {//does not exist first build git repository $cmd = "$GIT init";          EXEC ($cmd, $rs, $status);          Add remote origin $cmd = "$GIT Remote add origin [email protected]". $remote. ": Hometouch. $project";          EXEC ($cmd, $rs, $status);          Remove the file property change $cmd = "$GIT config core.filemode false";        EXEC ($cmd, $rs, $status);                    }//below executes the command if ($COMMITMSG = = "") $COMMITMSG = Date ("Y.M.D");        Confirm Submit Username $cmd = "$GIT config user.name ' gitforftp '";        EXEC ($cmd, $rs, $status);        $cmd = "$GIT config user.email ' [email protected] '";        EXEC ($cmd, $rs, $status); ToThe file property changes $cmd = "$GIT config core.filemode false";                  EXEC ($cmd, $rs, $status);        $cmd = "$GIT add *"; echo "cmd:". $cmd. "        <br/> ";        EXEC ($cmd, $rs, $status);        Unset ($RS);        $cmd = "$GIT commit-a-m \" $COMMITMSG \ ""; echo "cmd:". $cmd. "        <br/> ";        EXEC ($cmd, $rs, $status);        Print_array ($RS);        Unset ($RS); Echo ($status ==0)?                ("Commit succeeds <br/>"): ("Commit failed <br/>");        To prevent IP changes, modify the submitted IP $cmd = "$GIT Remote Set-url origin [email protected]". $remote. ": Hometouch. $project";                EXEC ($cmd, $rs, $status);        $cmd = "$GIT push-f origin master"; echo "cmd:". $cmd. "        <br/> ";        EXEC ($cmd, $rs, $status); Echo ($status ==0)?        ("Push succeeded <br/>"): ("Push failed <br/>");        Print_array ($RS);     Unset ($RS); }

One of the problems here is that

Error:insufficient permission for adding a object to repository database. git/objects

This is because the user who initialized the project is not git, so the owner of the. Git directory is not git, so it cannot be written to the. Git database at the time of submission, resulting in this error. The workaround is simple, change the. Git directory owner to

sudo chown-r git:git repo.git

Git PHP Submission

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.