Welcome!


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

Are your smart devices spying on you? Make better purchasing choices and find products that respect your privacy at Unwanted.cloud

RSS Latest posts from my personal blog


Subscribe to RSS feed


Upgrading from Deployer 3 to Deployer 4

Stanislav KhromovStanislav Khromov

If you are upgrading Deployer from version 3 to 4 you will see issues when trying to deploy, for example:

[ERROR] Error: Call to undefined function set() in /Users/stakhr/site/deploy.php:5    
       Stack trace:                                                                                
       #0 phar:///Users/stakhr/site/deployer.phar/bin/dep(114): require()            
       #1 phar:///Users/stakhr/site/deployer.phar/bin/dep(115): {closure}()          
       #2 /Users/stakhr/site/deployer.phar(4): require('phar:///Users/s...')         
       #3 {main}  

To fix these issues, you need to do a few things:

Here is a full example of deploying a WordPress site using Deployer 4

<?php
namespace Deployer;
require 'recipe/common.php';
set('ssh_type', 'native');
set('ssh_multiplexing', true);
// Set configurations
set('repository', 'git@github.com:user/repo.git');
set('shared_files', ['public/wp-config.php']);
set('shared_dirs', ['public/wp-content/uploads']);
set('writable_dirs', []);
set('keep_releases', 3);
set('composer_command', 'composer');
//Defaults for all servers
set('timezone', 'Europe/Stockholm');
set('branch', 'master');
// Configure servers
server('production', 'example.com')
->user('root')
->identityFile()
->forwardAgent()
->set('deploy_path', '/var/www/example.com/deployer')
->set('environment', 'production');
/**
* Chown files to correct user
*/
task('deploy:chown', function () {
run('chown -R www-data:www-data ' . get('deploy_path'));
});
/**
* Restart php-fpm
*/
task('deploy:restart-php', function () {
run('ee stack restart --php7');
});
/**
* Restart Memcached
*/
task('deploy:restart-memcached', function () {
run('service memcached restart');
});
/**
* Write current Git commit hash to version.txt of current release
*/
task('deploy:write_version', function () {
cd(get('deploy_path') . '/current/public/');
run('git rev-parse HEAD > version.txt');
});
/**
* Display current Git commit hash
*/
task('info:version', function() {
cd(get('deploy_path') . '/current');
$version = run('git rev-parse HEAD')->getOutput();
write("Currently deployed commit: <info>$version</info>");
});
/**
* Main task
*/
task('deploy', [
'deploy:prepare',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:writable',
'deploy:vendors',
'deploy:symlink',
'deploy:write_version',
'deploy:chown',
//'deploy:restart-php',
//'deploy:restart-memcached',
'cleanup',
'info:version',
'deploy:warm_cache'
])->desc('Deploy your project');
after('deploy', 'success');

PS. I’ve also noted that running deployer self-update on version 3 does not upgrade to version 4.

Full-stack impostor syndrome sufferer & Software Engineer at Schibsted Media Group

Comments 0
There are currently no comments.