PHP Subversion Setup FTP

I work in a small php store, and recently I suggested abandoning our nas as a common code base and starting using a disruptive function for version control.

I figured out how to make sure that our development server is updated with every commit in our development branch ... and I know how to merge into trunk and update our intermediate server, because we have direct access to both of them, but mine the biggest question is how to write a script that will update the production server, to which we only have access to ftp many times. I don’t want to download the whole site every time ... is there a way to write a script that is smart enough to only upload what was changed to the web server when it was executed (I don’t want it to automatically load into the production environment, we want execute it manually)?

Does my question make sense?

+3
source share
7 answers

, , subversion . , ( ) . , .

, rsync, . FTP, - rsync FTP. , - ; . , , .

EDIT: , , , . - rsync ftp, weex http://weex.sourceforge.net/. ftp, , , , . .

+4

SVN FTP, http, svnsync. , severs - svnsync, .

+1

. SVN - URL-:

 <?php

    // make sure you have a robot account that can't commit ;) 
    $username = Settings::Load()->Get('svn', 'username');
    $password = Settings::Load()->Get('svn', 'password');
    $repos = Settings::Load()->Get('svn', 'repository');

    echo '<h1>updating from svn</h1><pre>';
    // for secutity, define an array of folders that you do want to be synced from svn. The rest should be skipped.
    $svnfolders = array(    'includes/' ,'plugins/' ,'images/' ,'templates/', 'index.php' => 'index.php');

    if(!empty($_GET['justthisone']) && array_search($_GET['justthisone'], $svnfolders) !== false){ // you can also just update one of above by passing it to $_GET
        $svnfiles = array($_GET['justthisone']);
    }

    foreach($svnfiles as $targetlocation)
    {   
        echo system("svn export --username={$username} --password {$password} {$repos}{$targetlocation} ".dirname(__FILE__)."/../{$targetlocation} --force");
    }

    die("</pre><h1>Done!</h1>");
+1

LFTP ftp.

0

:

, , ​​. . PHP script, svn, , rep. .

script :

$path = realpath( '/path/to/production/mirror' );
chdir( $path );

$start = time();
shell_exec( 'svn co' );

$list = array();
$i = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ), RecursiveIteratorIterator::SELF_FIRST );

foreach( $i as $node )
{

    if ( $node->isFile() && $node->getCTime() > $start )
    {

        $list[] = $node->getPathname();

    } 

    // directories should also be handled

}

$conn = ftp_connect( ... );

// and so on

, .

0

Source: https://habr.com/ru/post/1708927/


All Articles