Deployment for WordPress with

0.6.0 2019-05-09 11:31 UTC


What does it do?

NOTE! Its tested only with Deployer 4.3!

This package provides deploy task for deploying WordPress with deployer ( and additionally a tasks to synchronize database and media files.

The deployment is simplified in order to have ability to auto-upgrade WordPress and upgrade plugins manually by admin panel (or automatically with tools like InfiniteWP). This is a half way between no deployment at all and deployment fully driven by composer. If you want to manage WordPress and plugins fully with composer then check

Should I use "deployer-extended-wordpress" or "deployer-extended-wordpress-composer"?

In sourcebroker/deployer-extended-wordpress the WordPress and third party plugins are installed manually. What you have in git is basically only your theme. The good thing is that in such case you can update WordPress and plugins automatically. This can be considered as preferable for low budget WordPress websites.

In sourcebroker/deployer-extended-wordpress-composer the WordPress and third party plugins are installed using composer. This way you gain more control over what is installed but at the same time to install new WordPress or new plugin version you need first to modify composer.json or do composer update (depending how big upgrade you do). Then you need to commit composer.json / composer.lock and do deploy which will install new version of WordPress and plugins. This is additional work that can not be easily automated. One of additional advantages of this solution is that you can easily cleanup infected WordPress/plugins files as with each deployment all php files are fresh (part from your git and part from composer repositories).


This package depends on following packages:


  1. Install package with composer:

    composer require sourcebroker/deployer-extended-wordpress
  2. If you are using deployer as composer package then just put following line in your deploy.php:

    new \SourceBroker\DeployerExtendedWordpress\Loader();
  3. If you are using deployer as phar then put following lines in your deploy.php:

    require __DIR__ . '/vendor/autoload.php';
    new \SourceBroker\DeployerExtendedWordpress\Loader();
  4. Remove task "deploy" from your deploy.php. Otherwise you will overwrite deploy task defined in deployer/deploy/task/deploy.php

  5. Example deploy.php file:

    namespace Deployer;
    require __DIR__.'/vendor/autoload.php';
    new \SourceBroker\DeployerExtendedWordpress\Loader();
    set('repository', 'git@my-git:my-project.git');
    server('live', '')
        ->set('public_urls', [''])
        ->set('deploy_path', '/var/www/');
    server('beta', '')
        ->set('public_urls', [''])
        ->set('deploy_path', '/var/www/');
    server('local', 'localhost')
        ->set('public_urls', [''])
        ->set('deploy_path', getcwd());

Mind the declaration of server('local', 'localhost'); Its needed for database tasks to decalre domain replacements, and path to store database dumps.

Project's folders structure

This deployment has following assumptions:

  1. WordPress source code is not in GIT in order to have ability to easily upgrade them from admin panel.

  2. Plugins source code is not in GIT in order to have ability to easily upgrade them from admin panel.

  3. Taking the two above points into consideration the only files in GIT will be:



The wp-config-local.php should be excluded from git and have following data.



define( 'DB_NAME', '' );
define( 'DB_USER', '' );
define( 'DB_PASSWORD', '' );
define( 'DB_HOST', '' );
define( 'WP_DEBUG', false );

The INSTANCE should be the same as server name defined in deploy.php.

This file should be included in wp-config.php before require_once(ABSPATH . 'wp-settings.php');

require_once(ABSPATH . 'wp-config-local.php');


The deploy task consist of following tasks:

task('deploy', [
    //

    //

    // Standard deployer deploy:prepare

    // Standard deployer deploy:lock

    // Standard deployer deploy:release

    // Standard deployer deploy:update_code

    // Standard deployer deploy:shared

    // Standard deployer deploy:writable

    // Standard deployer deploy:vendors

    // Detect WP version and get fresh code from WordPress git repo

    // Standard deployer deploy:copy_dirs. Copy plugins from previous release of WordPress

    // Standard deployer deploy:clear_paths

    // Create database backup, compress and copy to database store.
    //

    // Clear php cli cache.
    //

    // Start buffering http requests. No frontend access possible from now.
    //

    // Standard deployer symlink (symlink release/x/ to current/)

    // Clear frontend http cache.
    //

    // Frontend access possible again from now
    //

    // Standard deployer deploy:unlock

    // Standard deployer cleanup.
])->desc('Deploy your WordPress');

Its very advisable that you test deploy on some beta instance first :)

dep deploy beta

The shared dirs are:

set('shared_dirs', [

The shared files are:

set('shared_files', [

Synchronizing database

Database synchronization is done with sourcebroker/deployer-extended-database. Example of command for synchronizing database from live to local instance:

dep db:pull live

Domain replacement

The "post_command" task "db:import:post_command:wp_domains" will change domains declared in "public_urls". Domain replacement is done with cli command "search-replace" from wp-cli/wp-cli.

Please mind to have the same amount of "public_urls" for each of instances because replacement on domains is done for every pair of corresponding urls.

Look at following example to give you idea:

server('live', '')
    ->set('public_urls', ['', ''])
    ->set('deploy_path', '/var/www/');

server('beta', '')
    ->set('public_urls', ['', ''])
    ->set('deploy_path', '/var/www/');

server('local', 'localhost')
    ->set('public_urls', ['', ''])
    ->set('deploy_path', getcwd());

The if you will do:

dep db:pull live

the following commands will be done automatically after database import:

wp search-replace
wp search-replace


Database synchro configuration:

set('db_default', [
    'ignore_tables_out' => [],
    'post_sql_in' => '',
    'post_command' => ['{{local/bin/deployer}} db:import:post_command:wp_domains']

        'database_default' => [
            function () {
                return (new \SourceBroker\DeployerExtendedWordpress\Drivers\WordpressDriver)
                    ->getDatabaseConfig(getcwd() . '/wp-config-local.php');

Mind that "deploy.php" file must be the same on all instance before you can start to do database synchronization.

Synchronizing media & WordPress / plugins code

Media synchronization is done with package sourcebroker/deployer-extended-media. The command for synchronizing media & php files which are out of git is:

dep media:pull live

Because we do not use composer to get WordPress and plugins therefore we will treat here code of WordPress and plugins as kind of media to synchronize. This is a bit o misuse of sourcebroker/deployer-extended-media but if we think of media as part of project which is out of git that needs to be synchronized between instances then our WordPress and plugins php code which is also out of git is bunch of files that needs to be synchronized between instances.

Therefore our config to synchronize files media & WordPress / plugins code looks like this:

        'filter' => [
            '+ /wp-content/',
            '- /wp-content/mu-plugins/*',
            '- /wp-content/themes/*',
            '+ /wp-content/**',
            '+ /wp-admin/',
            '+ /wp-admin/**',
            '+ /wp-includes/',
            '+ /wp-includes/**',
            '+ wp-activate.php',
            '+ wp-blog-header.php',
            '+ wp-comments-post.php',
            '+ wp-config-sample.php',
            '+ wp-config.php',
            '+ wp-cron.php',
            '+ wp-links-opml.php',
            '+ wp-load.php',
            '+ wp-login.php',
            '+ wp-mail.php',
            '+ wp-settings.php',
            '+ wp-signup.php',
            '+ wp-trackback.php',
            '+ xmlrpc.php',
            '+ index.php',
            '- *'