itsahappymedium / wp-deployer
Deploy WordPress websites with ease.
Installs: 1 060
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 1
Open Issues: 5
Requires
- php: ^7.3|^8.0
- deployer/dist: ^6.8
- paragonie/random-lib: ^2.0
- twig/twig: ^3.4.3
- wp-cli/wp-cli-bundle: ^2.6
README
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.
* Bold variable names are required to be set.
extra_files default value
auth.json
{{wp_content_dir}}/themes/{{theme_name}}/*.css
{{wp_content_dir}}/themes/{{theme_name}}/*.map
{{wp_content_dir}}/themes/{{theme_name}}/js/*.js
{{wp_content_dir}}/themes/{{theme_name}}/js/*.map
Deployer Variabes
These variables are built-in to Deployer. You can read more here: https://deployer.org/docs/6.x/configuration.
* 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
auth.json
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
Overwriting Variables
You can easily overwrite any of the above variables by defining them in your config.yml
file. You can also overwrite or add to them by using Deployer Functions in your deploy.php
file like this:
<?php require_once('./vendor/autoload.php'); new WP_Deployer(); use function Deployer\{ add, set }; add('extra_files', array( 'scripts.js', 'lib/bootstrap/bootstrap.css' )); set('ssh_multiplexing', false); ?>
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 db:backup:<local/remote> [stage]
Exports and downloads the database from stage
(or local).
dep uploads:<push/pull> <stage>
Downloads/uploads the contents of your content/uploads
directory to/from stage
.
dep shared:<push/pull> <stage>
Downloads/uploads all contents of all directories listed in shared_dirs
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.