PHPackages                             yashus/wordpress-deploy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. yashus/wordpress-deploy

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

yashus/wordpress-deploy
=======================

CI/CD for wordpress

1.0.3(3mo ago)09↓90.9%MITPHP

Since Mar 30Pushed 3mo agoCompare

[ Source](https://github.com/aslamhus/WordpressDeploy)[ Packagist](https://packagist.org/packages/yashus/wordpress-deploy)[ RSS](/packages/yashus-wordpress-deploy/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

WordpressDeploy
===============

[](#wordpressdeploy)

A composer package to help you pull and push your wordpress site with a handy CLI tool `wpd` (**W**ord**P**ress-**D**eploy)

Push
----

[](#push)

To perform a push:

```
vendor/bin/wpd push
```

Where `env` is `staging` or `production`

### Push options

[](#push-options)

```
# Default push
# You will be asked interactively if you'd like to push wp-content, the database, composer (if set), and whether you'd like to flush the cache
vendor/bin/wpd push
# Push without interaction. Assumes you want to push everything (wp-content,database,composer and flush cache)
vendor/bin/wpd push  --no-interaction

## ‼️ Beware, setting any of the following options will disable interaction
## Push only wp-content
vendor/bin/wpd push  --wp-content
## Push only db
vendor/bin/wpd push  --db
## Push only composer
vendor/bin/wpd push  --composer
## Flush the cache
vendor/bin/wpd push  --flush-cache
## Push a combination
vendor/bin/wpd push  --wp-content --composer --flush-cache

## Negate
## Alternatively , you can choose to negate certain options
## push everything except wp-content
vendor/bin/wpd push  --no-wp-content
## push everything except db
vendor/bin/wpd push  --no-db
## push everything except composer and do not flush cache
vendor/bin/wpd push  --no-composer --no-flush-cache
```

Pull
----

[](#pull)

Pull the database

```
vendor/bin/wpd pull db
```

Pull wp-content

```
vendor/bin/wpd pull wp-content
```

Deploy ignore files
-------------------

[](#deploy-ignore-files)

Add a .deployginore file to your project root to exclude files in your public directory when you push to your remote site

For example:

```
*.tar.gz
wp-content
/test.txt
second-test.txt
```

The above will ignore:

- all files with ".tar.gz" extension in all directories,
- all directories of wp-content
- test.txt in the root directory only
- second-test.txt in all directories

### Unexpected behaviour

[](#unexpected-behaviour)

When using the `upload_type` "archive" instead of rsync in your .wpd.json, your deployignore patterns may produce slightly unexpected results. For example:

```
/*.tar.gz
test.txt
```

You might expect `/*.tar.gz` to only target files with extension .tar.gz in the root directory, but it will still target all files with that extension. Wildcards can't be anchored to the root directory. This is a quirk of both `gnutar` and `bsdtar`, which are used to archive your site before deploying. In this case, it's recommended to use explicit paths instead of wildcards or to use `rsync` as your `upload_type`.

Choosing between rsync and archive for deployment
-------------------------------------------------

[](#choosing-between-rsync-and-archive-for-deployment)

You can choose between rsyncing each file in public to your remote site, or archiving the public directory, pushing it to remote and then unzipping it on the server. The latter method is good for large scale changes, like uploading a new site for the first time. The former is more efficient when you only want to upload a few file changes and not the entire site.

Both methods will ignore files you set in your `.deployignore` (see above).

To change between `rsync` / `archive`, update your `upload_type` property in your `wpd.json` file.

```
{
  "upload_type": "rsync"
}
```

Test against your wpd.json file
-------------------------------

[](#test-against-your-wpdjson-file)

You can run tests against your own settings. From your project root, run:

```
vendor/bin/wpd test
```

List the available tests

```
vendor/bin/wpd test --list
```

Perform a test of your settings json.

***Note: this only tests the structure/type of your settings, not whether the filepaths exists.***

```
vendor/bin/wpd test settings
```

You can get verbose testing output by passing the `-v` option.

Assumptions
-----------

[](#assumptions)

1. Assumes wordpress directory is in root / public directory. See wpd.json settings.
2. Built to work with docker, but can in theory work without a docker container, i.e. in a MAMP / XAMPP environment

Inject ENV Files
----------------

[](#inject-env-files)

In your `wpd.json` file, you can specify files that should be updated based on the environment (staging,local,production). See `files` property.

### Example

[](#example)

```
{
    ...,
  "files": [
     [
      ".htaccess", // target file
      {
        "directory": "", // the directory to search for the target file and env file (defaults to 'public')
        "local": ".dev.htaccess", // files to replace based on environment
        "production": ".prod.htaccess",
        "staging": ".staging.htaccess"
      }
    ],
    [
      "wp-config.php",
      {
        "directory": "",
        "local": "wp-config-local.php",
        "production": "wp-config-production.php",
        "staging": "wp-config-staging.php"
      }
    ],
    [
      ".env",
      {
        "directory": "",
        "local": ".local.env",
        "production": ".prod.env",
        "staging": ".staging.env"
      }
    ]
  ],
}
```

Note: Make sure all the env files are in the same directory as the target file or you will encounter the error: `Target file not found: ' . $target_file. '. Please make sure that the injecting files exist in the same directory`

Add your own custom scripts to the push process
-----------------------------------------------

[](#add-your-own-custom-scripts-to-the-push-process)

The push command has two hooks for custom scripts, `prePush` and `postPush`. Here's an example of how to run a `prePush` script.

### Example

[](#example-1)

1. Add scripts to your wpd.json file:

```
  ...,
 "hooks": {
    "prePush": ["bin/test", "bin/test2"],
    "postPush": ["bin/cloudflare"]
  }
```

2. Make sure to give your scripts execute privileges by running `chmod +x `
3. Add a hashbang to specify your script language

```
##!/usr/bin/env php
