Need Advice? CALL: +61 417949565

Riksi - web design and development

  • Home
  • ABOUT US
  • OUR WORK
  • BLOG
  • CONTACT US
  • Home
  • BLOG
  • Web developing
  • command line
  • Deployer – PHP deployment tool – Get started

Deployer – PHP deployment tool – Get started

Deployer – PHP deployment tool – Get started

What is Deployer?

It is CLI deployment tool written in PHP with support for popular frameworks such as WordPress, Magento and Laravel and CakePHP out of the box.

In short , Deployer is a PHP file (called Recipe) containing tasks definitions. Recipe can require other recipes and extend/ override functionality.

Some PHP Deployer of the advantage are:

  • Fast: Contains loads of time-saving features
  • Modular: Can customize the deployment script
  • Clean Code: Clean and easy to use code.
  • Rollbacks: Easy to rollback to the previous version is something that breaks the code.
  • Atomic Deploy: Can do lots of other tasks before doing the symlink and update the live site
  • Parallel tasks: Can run the parallel tasks with no other extension
  • Consistency: It’s consistent between servers
  • Easy to use

Install Deployer:

Using composer to install Deployer with the following command:

1
2
3
4
5
 
 
composer require deployer/deployer --dev
 
 

Or install it globally:

1
2
3
4
5
 
 
composer global require deployer/deployer
 
 

Set Config

To create the deployer settings, we need to use the set function.
set function get 2 arguments.

1
2
3
4
5
6
7
8
 
 
set("neme_of_setting","value");
 
// Project repository
set('repository', 'link_to_repository');
 
 

Hosts

Defining a host in Deployer is necessary to deploy your application. It can be remote server or local host or EC2. Each host should conyain stage, one or more roles and configuration document.

1
2
3
4
5
6
7
8
 
 
host('your_domain.com or IP')
->stage('production')
->roles('app')
->set('deploy_path', '~/app');
 
 

Add ssh login details to the host:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
 
host('domain.com')
->user('name')
     ->('branch', 'master') //Overriding global config per host(eg switch to master branch.
->become('deployer')</code> //switch user
     ->port(22)
->configFile('~/.ssh/config')
->identityFile('~/.ssh/id_rsa')
->forwardAgent(true) ->multiplexing(true)
->addSshOption('UserKnownHostsFile', '/dev/null')
->addSshOption('StrictHostKeyChecking', 'no');
 
 

Tasks

Tasks are the functions which will be run as soon as server contacted.

Task function, receive 2 arguments, the name and a function or callback

Below is the function that print the text on screen after deploy finished.

1
2
3
4
5
6
7
 
 
task("deploy:done",function(){
     write('Deploy Finished");
})->desc("some description for other programmer");
 
 

Another example to restart the server by using the run function.:

1
2
3
4
5
6
7
 
 
task("reload:service":function(){
     run("sudo /usr/sbin/service nginx:reload");
})->desc("Restart the nginx Service");
 
 

Please Note: run() function will execute the command on server

Pre-defined Task

To use the pre-written tasks in default Deployer recipe, we need to use the array and add the default task names:

1
2
3
4
5
6
7
8
9
10
11
12
 
 
task('deploy' , [
    'deploy:prepare', //prepare server for release
     'deploy:release', //Create release and shared directory
     'deploy:update_code', //get the code from git
     'deploy:vendors', //runs composer install and bring in external dependencies
     'deploy:symlink', //create current symlink point to latest version of release
     'cleanup'  //remove old releases
])->desc("Main deploy tasks");
 
 

Please note: its possible to override the pre-defined tasks, by using the same name on the custom task.

Hooks

Deployer provides 2 hooks called before and after. they can run the function before or after deploy.

1
2
3
4
5
 
 
after("deploy" , "name_of_the_task");
 
 

CLI Usage

After installation of Deployer you will have the ability to run the dep command from your terminal.

1
2
3
4
5
 
 
vendor/bin/dep deploy $env
 
 

Sample WordPress deploy.php

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
 
 
namespace Deployer;
 
require_once __DIR__ . '/common.php';
 
set('shared_files', ['wp-config.php']);
set('shared_dirs', ['wp-content/uploads']);
set('writable_dirs', ['wp-content/uploads']);
 
 
task('deploy', [
 
'deploy:info',
'deploy:setup',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:writable',
'deploy:symlink',
'deploy:unlock',
'deploy:cleanup',
])->desc('Deploy your project');
 
after('deploy', 'success');
 
 

More information: https://deployer.org/docs/getting-started.html

Tagged under: deployer, get started
Nick
Saturday, 21 March 2020 / Published in command line, PHP

What you can read next

Redirect Not Logged-in User in PHP
PHP – Create a customised log function
Complete Guide to setup remote Git on your site

Leave a Reply Cancel reply

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

Archive

  • General
    • Smart Home
  • Web developing
    • command line
    • CSS
    • General
    • git
    • Javascript
    • Laravel
    • Magento
    • MySQL
    • PHP
    • Security
    • Shopify
    • Wordpress

Recent Posts

  • Install HomeAssistant on Raspberry pi

  • Shopify ERR_INVALID_ARG_TYPE Error

Riksi

Riksi is a creative, professional & cutting-edge custom web design and development company.

HERE TO HELP

  • BLOG
  • Contact Us
  • Our Work
  • About Us

New on Blog

  • Install HomeAssistant on Raspberry pi

    To install it, We need to connect the SD card t...
  • Shopify ERR_INVALID_ARG_TYPE Error

    fix the Internal Server Error occurred while in...

GET IN TOUCH

T: (+61) 417 949 565
Email: [email protected]

Contact Us
Fill out the form and our team will be in touch with you promptly. Thank you for your interest!

AU & NZ
T: (+613) 9014 9495
T: (+61) 417 949 565
Email: [email protected]


US & Canada
Email: [email protected]

NAME

EMAIL

PROJECT TYPE
PROJECT BUDGET

MESSAGE

Could not authenticate you.

Whats on Instagram

Loading...

Tags

.htaccess calculation cherry pick composer content css deployer documentation error flex general knowledge get started git git stash hack javascript log mysql package password php PHP Trick replace scss shopify sidebar ssh symlink sync trick ubuntu windows 10 wordpress trick wp
  • GET SOCIAL
Riksi - web design and development

© 2020 All rights reserved. Riksi.com.

TOP