Deploy WordPress websites with ease.

Overview

WordPress Deployer

packagist package version packagist package downloads license

Deploy WordPress websites with ease.

This package is basically a Deployer "recipe" for WordPress websites.

Installation

composer require-dev itsahappymedium/wp-deployer

You will then want to create a deploy.php file at the root of your project with the following contents:

<?php
require_once('./vendor/autoload.php');
new WP_Deployer();
?>

You can optionally pass a file path as a parameter to the WP_Deployer class to use a file other than config.yml.

After that you should have the dep command available to you. Run it to confirm a successful installation and view a list of commands you can use.

Note: Deployer and WP-CLI will be installed as dependencies. Deployer can be used via vendor/bin/dep and WP-CLI can be used via vendor/bin/wp.

One last thing, you'll want to make sure that the following is in your .gitignore file to avoid them being commited to your repo:

/config.yml
/db_backups
/tmp

Configuration

Create a config.yml file at the root of your project. Use config-example.yml as a starting point.

Note: You will want to make sure that you add your config.yml file to your .gitignore file so that it is not committed to your repo as this file will contain sensitive credentials.

Variables

These variables can be set in your config.yml file and/or via the set function in your deploy.php file:

WP-Deployer Variables

These variables are custom to WP-Deployer.

Variable Default Value Description
application The name of the application.
compiled_theme_files (See below) An array of files (or file globs) from your theme's directory that are not included in your repo and should be uploaded during a deployment.
database Database information. An object with database, host, username, and password set.
db_backups_path db_backups The path where database exports are stored. (This path should be added to .gitignore)
public_path /var/www/public The path where your server expects the website to be located and available to the public.
templates_path templates The path where template files are located.
tmp_path tmp The path where temporary files are stored. (This path should be added to .gitignore)
theme_name The name of your active theme.
url http://localhost The URL to your website.
wp_config_constants An array containing keys and values of constants to declare in your wp-config.php file.
wp_content_dir wp-content/content The path to your content directory where themes and plugins are located.
wp_site_url (The value of url) The URL to where your wordpress directory/core files is located.
wp_email The e-mail address to use for the default user when generating a new site database.
wp_user The username to use for the default user when generating a new site database.

* Bold variable names are required to be set.

compiled_theme_files default value
*.css
*.map
js/*.js
js/*.map

Deployer Variabes

These variables are built-in to Deployer. You can read more here: https://deployer.org/docs/6.x/configuration.

Variable Default Value Description
branch Branch to deploy.
cleanup_use_sudo false Whether to use sudo with cleanup task.
clear_paths (See below) List of paths which need to be deleted in release after updating code.
clear_use_sudo false Use or not sudo with clear_paths.
composer_action install Composer action.
composer_options Options for Composer.
copy_dirs List of files to copy between release.
default_stage staging The default stage.
deploy_path /var/www/public_html Where to deploy application on remote host.
env Array of environment variables.
git_recursive true Set the --recursive flag for git clone.
git_tty true Allocate TTY for git clone command. This allow you to enter a passphrase for keys or add host to known_hosts.
hostname The host IP address.
http_user User the web server runs as. If this parameter is not configured, deployer try to detect it from the process list.
keep_releases 5 Number of releases to keep. (-1 for unlimited)
repository Git repository of the application.
shared_dirs (See below) List of shared dirs.
shared_files (See below) List of shared files.
ssh_multiplexing true Use ssh multiplexing to speedup the native ssh client.
stage The stage deploy to.
use_atomic_symlink true Whether to use atomic symlinks. By default deployer will detect if system supports atomic symlinks and use them.
use_relative_symlink true Whether to use relative symlinks. By default deployer will detect if the system supports relative symlinks and use them.
user (Current git user name) User to SSH into the server as.
writable_chmod_mode 0755 Mode for setting writable_mode in chmod.
writable_chmod_recursive true Whether to set chmod on directories recursively or not.
writable_dirs List of directories which must be writable for web server.
writable_mode acl Writable mode. Options are acl, chmod, chown, chqrp.
writable_use_sudo false Whether to use sudo with writable command.

* Bold variable names are required to be set.

* Italic default values are custom to WP-Deployer.

clear_paths default value
.git
templates
.gitignore
.lando.yml
composer.json
composer.lock
config.yml
deploy.php
readme.md
shared_dirs default value
content/uploads
shared_files default value
.htaccess
robots.txt
wp-config.php

Templates

Template files are as follows: .htaccess, robots.txt, and wp-config.php. Default templates for these files are included with WP-Deployer however custom ones can be made by placing them in your templates directory. We use Twig to render the templates. View the templates directory in this package for examples.

A template can be associated with a specific stage by putting that stage name before the .twig file extension (for example: robots.txt.staging.twig).

(Note: The ability to add custom templates here will be coming in the future.)

Usage

Run dep list and/or dep help <command> to get more information on these commands.

dep deploy <stage>

Deploys your website to the stage (which is defined in your config.yml file).

dep db:<push/pull> <stage>

Exports and downloads/uploads the database to/from stage and then imports it.

dep uploads:<push/pull> <stage>

Downloads/uploads the contents of your content/uploads directory to/from stage.

dep db:fix

Extracts the local copy of your database and replaces all occurances of utf8mb4_unicode_520_ci to utf8mb4_unicode_ci and then re-imports it. This solves the issue where the server is using a different version of MySQL than your local.

dep setup:<local/remote> <stage>

Generates the templates files and sets up the database for WordPress if it hasn't been already. If a new database is set up, the username and password (randomly generated) will be shown in the terminal. Keep in mind that a new wp-config.php file will be generated with newly generated secrets.

dep setup:init <stage>

A convience command; Runs the following commands in order: dep setup:local <stage>, dep uploads:pull <stage>, dep db:pull <stage>.

License

MIT. See the license.md file for more info.

Comments
  • autoload.php path in the wp-config.php template is wrong (at least for default WordPress installations)

    autoload.php path in the wp-config.php template is wrong (at least for default WordPress installations)

    At Happy Medium we store our WordPress core files in a wordpress directory, so currently the wp-config.php template is trying to require the autoload.php file via ../vendor/autoload.php but for default WordPress installations it would be located at ./vendor/autoload.php.

    You can get around this by defining your own templates/wp-config.php.twig file in your project.

    bug 
    opened by kodie 1
  • wp-cli doesn't get installed on the remote server since wp-deployer is a require-dev package

    wp-cli doesn't get installed on the remote server since wp-deployer is a require-dev package

    This means that currently any commands that use wp-cli on the remote server are broken (db:pull, db:push setup:remote).

    I'll need to get this fixed asap. 😅

    You can get around this by adding "wp-cli/wp-cli-bundle": "^2.3" in the require field of the composer.json file in your project.

    bug 
    opened by kodie 1
  • Update to Deployer v7

    Update to Deployer v7

    Deployer v7 has been out for a little while (we're currently using v6) so we should probably switch over to that but it will probably require a lot of changes in our code to work.

    enhancement 
    opened by kodie 0
  • Possibly add the ability to avoid regenerating secrets when regenerating wp-config.php

    Possibly add the ability to avoid regenerating secrets when regenerating wp-config.php

    If you run dep setup, it generates your wp-config.php file for you, thus generating new secrets (salts and stuff), but let's say you make a change to config.yml and want to regenerate the wp-config.php file, well, the secrets will get regenerated as well thus making all currently logged in user's sessions invalid as well as making anything else that may use those secrets invalid.

    I'm thinking this would be a functionality specific to the wp-config.php file where you could add comments to preserve data, something like this:

    // START:SAVE
    define('AUTH_KEY',         '@_ZCWi^PKzKlYm5ut6gA0<5D5#9<Mx(P~NM1(.vb{?z4.r0;[QnIif?h*id8H7>F');
    ...
    // END:SAVE
    

    and then maybe we could add a prompt when running dep setup if wp-config.php already exists, "Do you want to preserve wp-config.php data that is marked as 'save'?" with the default being "Yes".

    enhancement 
    opened by kodie 1
  • {{Variables}} get replaced with the default stage (staging) variables during setup:local and setup:init commands

    {{Variables}} get replaced with the default stage (staging) variables during setup:local and setup:init commands

    This is because local isn't considered it's own stage. I'll have to look into this one more.

    You can get around this by avoiding using {{variables}} in things like the wp_site_url config options.

    bug 
    opened by kodie 0
  • Add the ability to define a specific version of composer to use on the server

    Add the ability to define a specific version of composer to use on the server

    Currently, you're required to install Composer, globally, on the server yourself manually. We've run into issues with some older websites that require an older version of Composer. We've also ran into issues where Composer would auto-update itself and cause issues.

    I think it would be nice to be able to define a Composer version in your config.yml file and have WP-Deployer download it on the server and use that local copy.

    enhancement 
    opened by kodie 0
  • Allow for custom template files to be added

    Allow for custom template files to be added

    Currently, template files are limited to .htaccess, robots.txt, and wp-config.php. It would be nice if any other files put in the templates directory are rendered as well.

    enhancement 
    opened by kodie 0
Owner
Happy Medium
Happy Medium is an interactive agency in Des Moines, IA
Happy Medium
A PHP client for Wordpress websites that closely implement the XML-RPC WordPress API

Wordpress XML-RPC PHP Client A PHP client for Wordpress websites that closely implement the XML-RPC WordPress API Created by Hieu Le MIT licensed. Cur

Hieu Le 112 Nov 10, 2022
List of high-ranking websites powered by WordPress (everything but news and blogs)

Powered By WordPress About 25% of the web is powered by WordPress. A big majority of these sites are private blogs but also heavy-weights such as Sony

MB 19 Dec 23, 2022
A custom WordPress nav walker class to fully implement the Twitter Bootstrap 4.0+ navigation style (v3-branch available for Bootstrap 3) in a custom theme using the WordPress built in menu manager.

WP Bootstrap Navwalker This code in the main repo branch is undergoing a big shakeup to bring it in line with recent standards and to merge and test t

WP Bootstrap 3.3k Jan 5, 2023
A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities.

Awesome WordPress A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities. Inspired by bayand

Dropndot Limited 91 Dec 26, 2022
The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone.

Pronamic WordPress Basecone The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone. Table of contents Au

Pronamic 1 Oct 19, 2021
A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings.

Suspend WP A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings. ?? Demo (coming so

Waren Gonzaga 3 Nov 15, 2021
Twenty Twenty-Two, the default WordPress theme that will launch with WordPress 5.9.

Twenty Twenty-Two Welcome to the development repository for the default theme that will launch with WordPress 5.9. About Twenty Twenty-Two is designed

null 414 Nov 28, 2022
Easy handle APlayer on WordPress. A shortcode for WordPress to using APlayer.

Description Easy handle APlayer on WordPress. A shortcode for WordPress to using APlayer. Support [audio] tag, compatible with AMP. Requirement WordPr

Karl Chen 24 Nov 3, 2022
WordPress plugin that lets you use Discourse as the community engine for a WordPress blog

WP Discourse Note: the wp-discourse plugin requires >= PHP-5.4.0. The WP Discourse plugin acts as an interface between your WordPress site and your Di

Discourse 497 Dec 10, 2022
WordPress & TypeScript. Simple starter template for WordPress projects

WordPress & TypeScript. Simple starter template for WordPress projects that want to use TypeScript in combination with @wordpress/scripts

Make it WorkPress 11 Sep 27, 2022
Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library.

Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library. Import Jamendo playlists with tracks in WordPress posts.

Pierre Saikali 3 Dec 7, 2022
Automattic 10.7k Jan 2, 2023
WordPress Framework based on parent theme

Cherry Framework The most delicious WordPress framework Fully responsive design, easy install, steady updates, great number of shortcodes and widgets,

Cherry Framework 158 Nov 23, 2022
A better way to create WordPress themes.

Runway Framework for WordPress Visit the Runway website: RunwayWP.com A better way to create WordPress themes. Runway was built for creating WordPress

Parallelus 214 Nov 18, 2022
The easiest to use WordPress option framework.

Titan Framework The easiest to use WordPress options framework. Titan Framework allows theme and plugin developers to create admin pages, options, met

Gambit Technologies 374 Nov 14, 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 zero-configuration #0CJS developer toolkit for building WordPress Gutenberg block plugins.

create-guten-block is zero configuration dev-toolkit (#0CJS) to develop WordPress Gutenberg blocks in a matter of minutes without configuring React, w

Ahmad Awais ⚡️ 3.1k Dec 23, 2022
Examples for extending WordPress/Gutenberg with blocks.

Gutenberg Examples Examples for extending Gutenberg with plugins which create blocks. See also: Gutenberg developer documentation Installation Gutenbe

null 1.1k Dec 29, 2022
Documents WordPress Classic Editor integration points and their Gutenberg equivalents

Gutenberg Migration Guide This repository documents WordPress Classic Editor customization points and their Gutenberg equivalents (if such exist). Its

Daniel Bachhuber 185 Nov 16, 2022