PHPackages                             jordillonch/deploy-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. jordillonch/deploy-bundle

ActiveSymfony-bundle[DevOps &amp; Deployment](/categories/devops)

jordillonch/deploy-bundle
=========================

A Symfony2 deploy bundle

71914[1 issues](https://github.com/jordillonch/DeployBundle/issues)PHP

Since May 27Pushed 11y ago2 watchersCompare

[ Source](https://github.com/jordillonch/DeployBundle)[ Packagist](https://packagist.org/packages/jordillonch/deploy-bundle)[ RSS](/packages/jordillonch-deploy-bundle/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Symfony2 Deploy Bundle
======================

[](#symfony2-deploy-bundle)

**WIP**

[![Build Status](https://camo.githubusercontent.com/c1a53297973e6f375845faa048df14fe6e0f31756776afaaa1d441e219b2458b/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6a6f7264696c6c6f6e63682f4a6f7264694c6c6f6e63684465706c6f7942756e646c652e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/jordillonch/JordiLlonchDeployBundle)

What it is?
-----------

[](#what-it-is)

This bundle aims to be a deploy system for your projects.

It is a Symfony2 Bundle but it can be used to deploy several kind of projects.

The bundle provides some commands to automatize deploy process. Here are main commands:

- **Initialize**: Prepare deployer and remote servers creating a directories structure to host new code.
- **Download**: Download code from repository, adapt, warn up… and ship it to remote servers in order to put new code to production.
- **Code to production**. Deploy new code to production atomically and reload web server, app…
- **Rollback**. Return back to previous deployed version.

Deployer have zones configured to deploy new code.

Zones are a project and environment (e.g. prod\_api, our project Api for the production environment).

Deployer uses GitHub repository, a configured branch, and HEAD as a target to deploy.

You can use this bundle adding it to your projects via composer (see installation section) but my recommendation is that you create a new project to deploy because you may be want to not have your production configurations in your repository project. So it is a good idea to delegate add productions configuration to the deploy system.

Furthermore this bundle offers **helpers** to automatize common operations like install *composer* dependencies, do a *cache warm up* for *Symfony2* projects, refresh *php-fpm* after put code to production, get url to *GitHub* with diffs of new deployed code...

How it works?
-------------

[](#how-it-works)

There are two basic ideas that allows to deploy several code versions and put one of them to production and rollback between them.

When you want to deploy new code you have to do a "*download*" operation. That operation clones code from your git repository to a new directory (e.g. 20130704\_180131\_a618a56b08549794ec4c9d5db29058a01a58977f) then do adaptations to the code. Adaptations are the step where configurations are added, app cache is warned up, dependencies are downloaded and installed, symlinks are created to shared directories…

Shared directories are directories where there are data that you want to keep between deploys. (e.g. logs, reports, generated images...)

After that, code is copied to configured servers. Ssh authorized keys are used to allow copy and execute commands to remote servers.

Then, when you want to use last downloaded code to production you have to execute "*code to production*" operation. This operation modify a symlink to the directory where last version are downloaded.

Usually, after that you should restart webserver or php-fpm.

*Note*: These ideas are taken from Capistrano.

Quick start
-----------

[](#quick-start)

### Create a new Symfony 2.3 project

[](#create-a-new-symfony-23-project)

```
php composer.phar create-project symfony/framework-standard-edition path/ 2.3.0

```

### Install the bundle

[](#install-the-bundle)

Add following lines to your `composer.json` file:

```
"require": {
  "jordillonch/deploy-bundle": "dev-master"
},
"minimum-stability": "dev",

```

Execute:

```
php composer.phar update

```

Add it to the `AppKernel.php` class:

```
new JordiLlonch\Bundle\DeployBundle\JordiLlonchDeployBundle(),

```

### Configure general settings and a zone

[](#configure-general-settings-and-a-zone)

`app/config/parameters.yml`

```
jordi_llonch_deploy:
    config:
        project: MyProject
        vcs: git
        servers_parameter_file: app/config/parameters_deployer_servers.yml
        local_repository_dir: /home/deploy/local_repository
        clean_max_deploys: 7
        ssh:
            user: myuser
            public_key_file: '/home/myuser/.ssh/id_rsa.pub'
            private_key_file: '/home/myuser/.ssh/id_rsa'
            private_key_file_pwd: 'mypassword'
    zones:
        prod_myproj:
            deployer: myproj
            environment: prod
            checkout_url: 'git@github.com:myrepo/myproj.git'
            checkout_branch: master
            repository_dir: /var/www/production/myproj/deploy
            production_dir: /var/www/production/myproj/code

```

`app/config/parameters_deployer_servers.yml`

```
prod_myproj:
    urls:
        - deploy@testserver1:8822
        - deploy@testserver2:8822

```

- Note: Servers urls are in other file (`parameters_deployers_servers.yml`) because this file contains a dynamic configuration that would be changed in a scalable environment like AWS.

### Create a deploy class to myproj

[](#create-a-deploy-class-to-myproj)

- First create your own bundle:

```
php app/console generate:bundle --namespace=MyProj/DeployBundle --dir=src --no-interaction

```

- Create your own class to deploy:

`src/MyProj/DeployBundle/Service/Test.php:`

```
