Deploy a PHP project from Git to a server that does not have Git installed

7k views Asked by At

I need to find a method of deploying a PHP project stored in a git repo to a staging and production server that do not have git installed. Scripts I've found so far (ie Capistrano) require Git on the target server.

Unfortunately, my host does not allow this, and the only way so far is via standard FTP, with which I keep missing files. This makes for an unprofessional look.

I would like to be able to deploy from my local git repo, which will check the .git folder on the target to see which version is on there, then cause the target server to backup the current version and then overwrite it with only the changed files being pushed.

Preferably something in PHP with a web interface.

Not asking much am I ;)

Anyone out there got/seen anything like this?

5

There are 5 answers

4
Boris Guéry On BEST ANSWER

There are three git-ftp scripts which allow you to "push" a git repository to a FTP server.

1
Tyler Eaves On

You might be able to use something like Fuse to "mount" the production server as a local drive, and then as far as your copy of git is concerned it's a local operation. Alternatively, rsync.

2
J-Rou On

I have done something like that using ssh2 and php.

first you need to clone the repo on the server. Once cloned, you can do git pull, checkout, etc from php using ssh2. the most practical way I found was doing.

git fetch;
git reset --hard commit_hash;

in order to get set the commit to the one expected.

To execute a php - ssh2 command (supposing you have ssh2 installed), you can use this method.

public static function SSHCommmand($command,$user,$ip) {
        $port = 22;

        if (!function_exists("ssh2_connect"))
            die("function ssh2_connect doesn't exist.");
        $result['debug'] .= " -Connect- 1";
        if (!($con = ssh2_connect($ip, $port, array('hostkey' => 'ssh-rsa')) )) {
            die("unable to establish connection.");
        } else {
            // try to authenticate with username root, password secretpassword
            if (!(ssh2_auth_pubkey_file($con, $user, '/home/' . $user . '/.ssh/deploy_rsa.pub', '/home/' . $user . '/.ssh/deploy_rsa'/* , 'secret' */))) {
                dir("fail: unable to authenticate.");
            } else {
                // allright, we're in!
                // execute a command
                if (!($stream = ssh2_exec($con, $command))) {
                    die("fail: unable to execute command.");
                } else {
                    // collect returning data from command
                    stream_set_blocking($stream, true);
                    $data = '';
                    while ($buf = fread($stream, 4096)) {
                        $data .= $buf;
                    }
                    fclose($stream);
                    return $data;
                }
            }
        }
    }

I'm using ssh-rsa key, the auth method might change. I'm aslo supposing that the keys are in '/home/' . $user . '/.ssh/deploy_rsa.pub' and '/home/' . $user . '/.ssh/deploy_rsa.

The other thing you might take into account is that to execute remote a remote git command, the command should be like:

_GIT_PATH.' --git-dir='.$path.'/.git --work-tree='.$path.' '.$command;

where $path is the toplevel of the working tree.

By using this and the Amazon Api, I've been able to deploy new code to several servers automatically and simultaneously.

0
eldh On

There's a tool call Dandelion that also does this. From what I can see, it's quite similar to git-ftp, BUT it also supports sftp and Amazon S3, which is handy if you don't want to change deploy tool just because you change server. It comes as a ruby gem, so really easy to install and get going.

0
dallen On

I use Beanstalkapp.com, which is great. You can deploy via FTP or SFTP.