Deployer based deployment for WordPress with media and database synchronisation.

Overview

deployer-extended-wordpress

What does it do?

This package provides deploy task for deploying WordPress with deployer (deployer.org) 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 https://roots.io/ and sourcebroker/deployer-extended-wordpress-composer.

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/plugins/muplugins. 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).

Dependencies

This package depends on following packages:

Installation

  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:

    <?php
    
    namespace Deployer;
    
    require __DIR__.'/vendor/autoload.php';
    
    new \SourceBroker\DeployerExtendedWordpress\Loader();
    
    set('repository', 'git@my-git:my-project.git');
    
    host('live')
        ->hostname('example.com')->port(22)
        ->user('deploy')
        ->set('shared_files', array_merge(get('shared_files'), ['config/.env.live.local']))
        ->set('public_urls', ['https://www.example.com/'])
        ->set('deploy_path', '/var/www/example.com/live');
    
    host('beta', '111.111.111.111')
        ->hostname('example.com')->port(22)
        ->user('deploy')
        ->set('shared_files', array_merge(get('shared_files'), ['config/.env.beta.local']))
        ->set('public_urls', ['https://beta.example.com/'])
        ->set('deploy_path', '/var/www/example.com/beta');
    
    host('local')
        ->set('public_urls', ['https://example-com.dev/'])
        ->set('deploy_path', getcwd());
    

Mind the declaration of host('local'); Its needed for database tasks to declare 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. wp-content/plugins should be most out of GIT to in order to have ability to easily upgrade them from admin panel. You can have however some plugins in GIT if you like.

  3. wp-content/mu-plugins can be partially out of GIT but you can also have plugins there which are in GIT.

  4. config/environments and use of wp-config and .env idea is back ported from bedrock and extended with idea of symfony/dotenv

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

    /config/environments/development.php
    /config/environments/staging.php
    /config/application.php
    /config/.env
    /config/.env.beta
    /config/.env.dev
    /config/.env.live
    /config/.env.dev.local.dist
    /config/.htaccess
    /wp-content/plugins/my-plugin-in-git
    /wp-content/mu-plugins/my-mu-plugin.php
    /wp-content/themes/my-theme/
    .gitignore
    deploy.php
    composer.lock
    composer.json
    wp-config.php
    

Mind .env.beta, .env.dev, .env.live - those files stores data which is specific per instance but can be stored in git. For example database name, database user, database host, SMTP settings (without password). The passwords should be stored in file which is out of git on each of the instance host .env.beta.local, .env.dev.local, .env.live.local or if you do not mind so much about security you can store them also in git.

You need also to add shared local env file per instance. You can do it like this. Look at line 4:
host('live')
 ->hostname('example.com')->port(22)
 ->user('deploy')
 ->set('shared_files', array_merge(get('shared_files'), ['config/.env.live.local']))
 ->set('public_urls', ['https://www.example.com/'])
 ->set('deploy_path', '/var/www/example.com/live');

The only required, out of git file on instance is /config/.env.local where you set info what instance it is. The content of /config/.env.local should be only WP_INSTANCE='live' etc depending on which instance it is.

Look at sourcebroker/wordpress-starter for example how you can use in your WordPress.

The shared dirs defined in deployer/set.php are:
set('shared_dirs', [
        'wp-content/uploads',
        'wp-content/languages',
        'wp-content/upgrade',
    ]
);
The shared files defined in ``deployer/set.php``are:
set('shared_files', [
    '.htaccess',
    'config/.env.local',
]);

Composer

You can set proper version of composer with composer_channel (values: 1, 2, stable, prelive, snapshot) or with composer_version which takes exact tags as arguments (https://github.com/composer/composer/tags). For stability and security its advised that you set composer_channel with value 1 or 2 so it will be automatically updated but will not install any new major version in future so your deploy will remain fairly stable.

set('composer_channel', 2);

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:

host('live', '111.111.111.111')
    ->hostname('example.com')->port(22)
    ->user('deploy')
    ->set('shared_files', array_merge(get('shared_files'), ['config/.env.live.local']))
    ->set('public_urls', ['https://www.example.com', 'https://sub.example.com'])
    ->set('deploy_path', '/var/www/example.com.live');

host('beta', '111.111.111.111')
    ->hostname('example.com')->port(22)
    ->user('deploy')
    ->set('shared_files', array_merge(get('shared_files'), ['config/.env.live.local']))
    ->set('public_urls', ['https://beta.example.com', 'https://beta-sub.example.com'])
    ->set('deploy_path', '/var/www/example.com.beta');

host('local')
    ->set('public_urls', ['https://example-com.dev', 'https://sub-example-com.dev'])
    ->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 https://www.example.com https://example-com.dev
wp search-replace https://sub.example.com https://sub-example-com.dev

Configuration

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:

set('media',
    [
        'filter' => [
            '+ /wp-content/',
            '- /wp-content/mu-plugins/*',
            '- /wp-content/themes/*',
            '+ /wp-content/**',
            '+ /wp-admin/',
            '+ /wp-admin/**',
            '+ /wp-includes/',
            '+ /wp-includes/**',
            '+ .htaccess',
            '+ 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',
            '- *'
        ]
    ]);
Comments
  • Your requirements could not be resolved to an installable set of packages

    Your requirements could not be resolved to an installable set of packages

    Hi, when I issue composer require deployer-extended-wordpress I get this error:

    Problem 1 - Installation request for sourcebroker/deployer-extended-wordpress ^0.5.0 -> satisfiable by sourcebroker/deployer-extended-wordpress[0.5.0]. - sourcebroker/deployer-extended-wordpress 0.5.0 requires sourcebroker/deployer-extended ^7.0.0 -> satisfiable by sourcebroker/deployer-extended[7.0.0, 7.1.0, 7.1.1, 7.1.2, 7.1.3] but these conflict with your requirements or minimum-stability.

    opened by qurtopianodesign 14
  • wpdep db:pull live not working fine

    wpdep db:pull live not working fine

    ➤ Executing task db:pull

    In functions.php line 365:

    The command "/usr/bin/wpdep db:export live --dumpcode=80321170f7000218563f6861f727b59e " failed.

    Exit Code: 1(General error)

    Working directory: /var/www/wpstructure-extended

    Output:

    ➤ Executing task db:export

    Error Output:

    In NativeSsh.php line 102:

    [RuntimeException]
    
    opened by MalikZohaib 13
  • Not working with current version of deployer

    Not working with current version of deployer

    Hello,

    Love this package but currently having some issues getting it to work with the current version of deployer (6.4.3).

    One example being the examples use server() and the current spec uses host(). After changing this I get other errors in the composer update command, can provide more logs info if needed.

    Is this to de with versions or is it my local config? If you need help updating I am happy to fix the errors I am seeing and make a pull request but thought I would check first to see if work has been started.

    All the best

    Thanks Chris

    opened by chrisvasey 4
  • How we can keep track of the installed plugins?

    How we can keep track of the installed plugins?

    Hi, your approach to gitignore all the plugins and wp core is impressive. But how we can keep track of the plugins? like which plugins are installed on which project in git?

    regards; Usman Ahmad

    opened by dextar47 1
  • Support for Deployer 7 yml files

    Support for Deployer 7 yml files

    Would it be possible to use https://github.com/deployphp/deployer/releases/tag/v7.0.0-beta.24 with this?

    Looks like from the composer.json file that 6.8 is the latest version possible. Yaml config files would be nice to use.

    opened by danshumaker 0
  • I am trying to create an excutable of deployer-extended-wordpress but getting error

    I am trying to create an excutable of deployer-extended-wordpress but getting error

    could you please check this

    PHP 1. {main}() /usr/bin/godep:0 PHP 2. include() /usr/bin/godep:10 PHP 3. SourceBroker\DeployerExtendedWordpress\Loader->__construct() phar:///usr/bin/godep/index.php:113

    Warning: require_once(recipe/common.php): failed to open stream: No such file or directory in phar:///usr/bin/godep/vendor/sourcebroker/deployer-extended-wordpress/src/Loader.php on line 12

    Call Stack: 0.0006 420608 1. {main}() /usr/bin/godep:0 0.1598 2897344 2. include('phar:///usr/bin/godep/index.php') /usr/bin/godep:10 0.1843 5156728 3. SourceBroker\DeployerExtendedWordpress\Loader->__construct() phar:///usr/bin/godep/index.php:113

    PHP Fatal error: require_once(): Failed opening required 'recipe/common.php' (include_path='phar:///usr/bin/godep/../:phar:///usr/bin/godep:.:/usr/share/php') in phar:///usr/bin/godep/vendor/sourcebroker/deployer-extended-wordpress/src/Loader.php on line 12 PHP Stack trace: PHP 1. {main}() /usr/bin/godep:0 PHP 2. include() /usr/bin/godep:10 PHP 3. SourceBroker\DeployerExtendedWordpress\Loader->__construct() phar:///usr/bin/godep/index.php:113

    Fatal error: require_once(): Failed opening required 'recipe/common.php' (include_path='phar:///usr/bin/godep/../:phar:///usr/bin/godep:.:/usr/share/php') in phar:///usr/bin/godep/vendor/sourcebroker/deployer-extended-wordpress/src/Loader.php on line 12

    if i remove the require_once 'recipe/common.php'; from here https://github.com/sourcebroker/deployer-extended-wordpress/blob/master/src/Loader.php#L12 then it resolves the issue looks like this is unneccessary could you please check this?

    opened by MalikZohaib 0
Owner
SourceBroker
SourceBroker
A deployment tool written in PHP with support for popular frameworks out of the box

Deployer A deployment tool written in PHP with support for popular frameworks out of the box. See deployer.org for more information and documentation.

Deployer 9.7k Jan 1, 2023
The PHP Deployment Tool

Magallanes What's Magallanes? Magallanes is a deployment tool for made with PHP for PHP applications; it's quite simple to use and manage. For more in

Andrés Montañez 685 Dec 25, 2022
PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.

P H I N G Thank you for using PHING! PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant. You can do anything wit

The Phing Project 1.1k Jan 7, 2023
Deploy your PHP with PHP. Inspired by Capistrano and Vlad.

Pomander A light-weight flexible deployment tool for deploying web applications. This project was inspired by Capistrano and Vlad the Deployer, as wel

Mike Kruk 202 Oct 18, 2022
Open software engineering platform and fun adventure game

Phabricator is a collection of web applications which help software companies build better software. Phabricator includes applications for: reviewing

Phacility 12.3k Dec 27, 2022
PHP transpiler - Write and deploy modern PHP 8 code, today.

Phabel Write and deploy modern PHP 8 code, today. This is a transpiler that allows native usage of PHP 8+ features and especially syntax in projects a

Phabel 219 Dec 31, 2022
Deployer is a free and open source deployment tool.

Deployer Deployer is a PHP Application deployment system powered by Laravel 6.0, written & maintained by Stephen Ball. Check out the releases, license

Stephen Ball 886 Dec 15, 2022
Magento2 Deployment with Deployer (Skeleton)

MageDeploy2 Base Magento2 Deployment Setup using Robo and Deployer. This is the base project you should base your deployments on. It provides an confi

Matthias Walter 44 Jul 18, 2022
Deployer is a PHP Application deployment system powered by Laravel

Deployer is a PHP Application deployment system powered by Laravel 5.5, written & maintained by Stephen Ball.

Stephen Ball 886 Dec 15, 2022
This Laravel Nova package allows you to manage media and media fields

Nova Media Hub This Laravel Nova package allows you to manage media and media fields. Requirements php: >=8.0 laravel/nova: ^4.0 Features Media Hub UI

outl1ne 25 Dec 22, 2022
Tool based on deployer.org to perform zero downtime deployments of Magento 2 projects

Magento 2 Deployer Plus Reliable fully-automated deployments tool for Magento 2. Zero downtime deployments on Magento versions >= 2.2 Automating your

Juan Alonso 194 Dec 27, 2022
🚀WordPress Plugin Boilerplate using modern web techs like TypeScript, SASS, and so on... on top of a local development environment with Docker and predefined GitLab CI for continous integration and deployment!

WP React Starter: WordPress React Boilerplate DEPRECATED: WP React Starter was a "research project" of devowl.io for the development of our WordPress

devowl.io GmbH 344 Jan 1, 2023
A deployer library for PHP 5.3

Plum An object oriented deployer library Installation and configuration Plum does not provide and autoloader but follow the PSR-0 convention. $plum =

Julien Brochet 87 Feb 5, 2022
Webloyer is a web UI for managing Deployer deployments

Webloyer Webloyer is a Web UI for managing Deployer deployments. Features Webloyer has the following features: Project management Managing deployment

Yuta Nagamiya 219 Nov 16, 2022
LaraNx Seo enables your Laravel app to store SEO and social media meta tag data in database instead of your code

LaraNx Seo enables your Laravel app to store SEO and social media meta tag data in database instead of your code. Moving marketing data out of your code base and into your database where it is easily modified.

srg 13 Dec 29, 2022
Pico disk, Not need any database, support html5, support mp3, mp4, support streaming media, support AriaNg

Nano netdisk, Now changed to pico disk. Pico disk,does not need any database, support html5, support mp3, mp4, support streaming media, support AriaNg.

null 53 Dec 26, 2022
A truly single-file, no-database, drop-in PHP media gallery.

Media Hut When I went looking, in early 2022, the options for a truly single-file, no-database drop-in PHP media gallery were shockingly small. Well,

Toby D 14 Dec 28, 2022
Admin Columns allows you to manage and organize columns in the posts, users, comments, and media lists tables in the WordPress admin panel.

Admin Columns allows you to manage and organize columns in the posts, users, comments, and media lists tables in the WordPress admin panel. Transform the WordPress admin screens into beautiful, clear overviews.

Codepress 67 Dec 14, 2022