user3304698 user3304698 - 29 days ago 4x
PHP Question

How do you update database when using composer/jenkins and wordpress with plugins?

I am trying to get wordpress and all plugins managed by composer. I have followed instructions including:

and other similar instructions found here:

Composer => Wordpress plugin workflow

However my issue is that sometimes a wordpress update and/or a plugin update changes the database.

In some cases just downloading the files from a repo via composer works, but when the update makes major changes to the database (ie: WP 4.2 to 4.3) which changed the permalinks it doesn’t work.

What I need is a way to force the updates to run any needed database changes.

A little background on what I am dealing with here. I have 150 plus wordpress sites, some running different plugins and sometimes, if needed a different versions of wordpress.

I am version controlling the wp-content folder minus a bunch of files with git ignore.

I currently have a working continuous integration process working with frameworked sites (cake, zend, etc). This process uses git -> jenkins -> web server.

I would like my wordpress sites to follow a similar process.

Any help would be appreciated. Thanks.


So I used the following to create my solution


With a few modifications/Jank that I will detail below

The database update I found that as long as you don't run two word press updates that need database changes you will be fine.

Examples wordpress 4.2 to 4.3 works if you login in to wp admin and update the database

If you however update 4.2 to 4.3 do nothing and update 4.3 to 4.6 you sometimes have an issue, that I still have not solved

However I do have plugins and wordpress updating automatically


I made a base wordpress repo that all new projects are forked off of

My jenkins build runs composer update or composer install depending on if the vendor folder is present

I made a plugin repo for all "approved" plugins the plugin repos are just copies of the current plugin and must contain

  "type": "wordpress-plugin",
  "require": {
    "composer/installers": "v1.0.6"

I made these all public so that any site can access them with no creds

Also when updating the plugin just make a branch called "pluginversion"

Example 1.2.3

This will allow you to revert to an older version of a plugin when needed

Installing and updating wordpress and plugins

From the links above I created a composer.json that looks a bit like this

  "repositories": [
      "type": "composer",
      "url": ""
      "type": "git",
      "url": ""
  "type": "wordpress-core",
  "require": {
    "johnpbloch/wordpress-core-installer": "~0.1",
    "johnpbloch/wordpress": "4.*",
  "extra": {
    "wordpress-install-dir": "wp"

This will update the site to wordpress 4.X and install the latest version of your plugin on build

If you want to install a old version of the plugin you just change




This will install wp core in the root of the project in the wp folder and plugins in side the wp-content folder

You will need to alter index.php with this

require( dirname( __FILE__ ) . '/wp-blog-header.php' );


require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );

At this point if you followed the above links you might think you are done, well not exactly

Issues and fixes

These are my fixes they are likely not the best way to get this done but they work for me any input on improving these would be appreciated.

The first issue is .gitignore

You would think you can just ignore the plugins directory right ? Well this creates a problem that the plugins directory does not exist and the empty index.php does not exists

Second issue with this solution the uploads folder is versioned and user can not upload images (the will get deleted on build)

My solution to this is to not add the plugins to the repo but allow add the index.php file

also I am excluding all files in .gitignore from the final build step so they do not get overwritten

my .gitignore looks something like this (you may need to ignore other files)


This causes all the ignored files to be versioned and allows the upload folder to be changed by end users

It also means you have to manually upload the uploads folder to the server

Hopefully this helps you out if you are trying to version wordpress

EDIT: also in the db wp_options site url needs to be suffixed with /wp