Featured

Symfony 2 deployment with Rsync – Similar to Symfony 1.4 deployment

March 5, 2014 by Sarath DR in Featured, Web Development with 0 Comments

As mentioned in the Symfony 2 website, there are many tools available to deploy the source code to remote server. I made this simple hack to follow the previous Symfony 1.4 deployment process. We have been using rsync to deploy all of our Symfony 1.4 projects and it is automated with some shell scripting. In order to keep the same settings, I have been forced to use the same commands that we use for Symfony 1.4. I would not recommend this solution, it is always better to use Phing or other deployment tools to make things more perfect. However this one is a quick solution and easy to implement.

Mainly you have to follow the below four steps.

Step 1: Configure your remote server details. Create two files “properties.yml” and “rsync_exclude.txt” in the “app/config” folder of your Symfony2 project.

Screen Shot 2014 03 05 at 17.30.48 300x234 Symfony 2 deployment with Rsync   Similar to Symfony 1.4 deployment

Step 2: properties.yml file format. Please follow the below format for server details configuration.

1
2
3
4
5
6
7
8
9
10
11
12
# Development environment
development:
   host: dev.sarathdr.com
   port: 22
   user: devuser
   dir: /srv/www/dev.sarathdr.com/

production:
   host: prod.sarathdr.com
   port: 22
   user: produser
   dir: /srv/www/dev.sarathdr.com/

Step 3: Create a new file “symfony” and save that your project root folder. Copy the below code and paste it in that file. Or Click here to download the file.

Screen Shot 2014 03 05 at 17.36.05 294x300 Symfony 2 deployment with Rsync   Similar to Symfony 1.4 deployment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env php
<?php
use Symfony\Component\ClassLoader\UniversalClassLoader;
require_once dirname(__FILE__).'/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
 
$loader = new UniversalClassLoader();
$loader->register();
 
$loader->registerNamespaces(array(
    'Symfony' => dirname(__FILE__).'/vendor/symfony/symfony/src',
));
 
use Symfony\Component\Yaml\Parser;
 
 
// php symfony project:deploy preprod -t  
$yaml = new Parser();
$array = $yaml->parse(file_get_contents(dirname(__FILE__).'/app/config/properties.yml'));
 
if( isset( $argv[1]) &&  $argv[1] == 'project:deploy' ){
	if( isset($array[$argv[2]]) ){
 
		$settings = $array[$argv[2]]; 	
		$serverString = getServerString($settings); 
 
		$rsync = "rsync -azC --force --delete --progress --exclude-from=app/config/rsync_exclude.txt ";
		if( isset( $argv[3] ) ){
			if( $argv[3] == "-t" ){
				$rsync .= "--dry-run "; 
			}
 
			$cmd = $rsync.$serverString;
 
			echo "\n>> exec ". $cmd ."\n";
 
 
 
		    $descriptorspec = array(
		         1 => array('pipe', 'w'), // stdout
		         2 => array('pipe', 'w'), // stderr
		       );
 
		       $process = proc_open($cmd, $descriptorspec, $pipes);
		       if (!is_resource($process))
		       {
		         throw new RuntimeException('Unable to execute the command.');
		       }
 
			   echo stream_get_contents($pipes[1]);
			   echo stream_get_contents($pipes[2]);
			   fclose($pipes[1]);
			   fclose($pipes[2]);
 
 
 
		}else{
			echo "\n Missing configuration \n";
		}
 
	}else{
		echo "\n Missing configuration \n";
	}
}else{
	echo "\n Missing parameter \n";
}
 
function getServerString( $settings ){
 
	$ssh = 'ssh';
	if( isset($settings["port"])  ) {
		$ssh = '"ssh -p'.$settings["port"].'"';
	}
	if( isset($settings["user"])  && isset($settings["host"]) ){
		return ' -e '.$ssh.' ./ '.$settings["user"].'@'.$settings["host"].':'.$settings["dir"]; 
	}
 
}
?>

Step 4: The set up is now finished and you can try a dry run with the below command from the root folder.

 
php symfony project:deploy development -t 
 
#dry-run

Use the below command to deploy the files

 
php symfony project:deploy development --go
 
#deploy

Share this to

Leave a reply

Your email address will not be published. Required fields are marked *

*

About
View Sarath D R's profile on LinkedIn

I am a technology consultant and an entrepreneur focused on the following technologies Java,Spring, Android, Angular, Asterisk, Symfony, Cake , Code-Igniter, Jquery , XAMPP, XHTML, AJAX, MySql, Seo, Web Design, Wordpress, iPhone development.

Today’s Tips
  • Generate Codova.jar file from Phonegap project using ant
  • Google map javascript client  to find the geographic co-ordinates  from  Address or post code
  • Update Android main UI from Webview – Phonegap Plugin
  • Jplayer is not working  with HTC One Android 4.3 version browser
  • Regular expression to validate mobile phone numbers starting with + ( plus ) – php
  • Simple pagination script for PHP
  • Useful adb ( Android Debug Bridge ) commands
  • Change the javascript files url to absolute url – Symfony 1.4
  • Set Http authentication header from Client – PHP / CURL

This site uses cookies from Google to deliver its services, to personalise ads and to analyse traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.This site also uses cookies from Google to deliver its services, to personalise ads and to analyse traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies.

Close