Search code examples
phplaravelgitgitlab

how to pull data from gitlab with php script in laravel?


I create new project in gitlab.

I upload my project in host, I need get last update form gitlab with function in laravel.

My function:

function execPrint($command = "git pull user:pass@gitlab.com/myProject.git") {
    $result = array();
    exec($command, $result);
    print("<pre>");
    foreach ($result as $line) {
        print($line . "\n");
    }
    print("</pre>");
}

After run this function:

ssh: Could not resolve hostname shayvard: Temporary failure in name resolution
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

How to issue this code?


Solution

  • The syntax user:pass@gitlab.com/myProject.git for GitLab URL is wrong on all accounts.

    First, it's an scp-like syntax for SSH protocol. But you cannot pass user/password to SSH in URL. The user for SSH at GitLab must always be git and authentication is done using keypairs.

    To fix your URL: either you switch to HTTPS: https://user:pat@gitlab.com/user/shayvard.git; please be advised you need a Personal Access Token instead of your account password.

    Or you setup an SSH keypair and use one of these syntaxes:

    ssh://git@gitlab.com/user/shayvard.git
    git@gitlab.com:user/shayvard.git