For a while, and despite the fact that we are Django (https://www.djangoproject.com/) fans, we develop and maintain several WordPress installations for customers.
We have wasted many times or wasted efforts in installing or retrieving an old development facility. Intolerable situation!
The question was therefore:
Considering that some plugins are systematically used and that it would be interesting to be able to use the same global installation to test and develop in parallel the different themes and sites of the clients.
The solution? A shell script to modify the environment of WordPress thanks to symbolic links from a single copy of a WordPress archive. We named it
wp-env and you can find it here: https://github.com/gotsunami/wp-env.
The general idea is to keep all the files except the directories used for development:
To do this, first follow the steps of a normal WordPress installation as explained here.
Configure a MySQL user and a database. Then install the plugins and themes you want to see systematically.
This will be your default environment and will be the basis for all your other environments.
You can reactivate it at any time to complete or modify it.
wp-env init, a
wp-envs directory is created at the root of the WordPress installation. This directory will contain the different configurations of WordPress (including
When creating new environments, a MySQL user is created in the
wp-config.php file, but you must create it yourself in your database.
Each environment therefore has a
wp-config.php configuration file, a database, separate themes and plugins. Awesome!
Just one note: switching from one environment to another can cause some problems with access to pages and administration as long as the browser cache, cookies and other equivalent systems are updated.
wp-config with other development tools?
For our part, we use git to follow the evolutions of our themes. This works very well with wp-config, initializing git directories at the root of each theme.
In order to avoid manipulation errors, you can also modify your prompt to indicate which configuration is active (see prompt.bashrc in the project repo for some ideas).
And for the rest, there is the README!
./wp-env Usage: ./wp-env <command> [<env_name>]
- init: Create the wordpress 'default' environment.
- create: Create a new wordpress environment in <env_name>.
If a 'default' environment exists, the newly created environment
is copied from it. Else, it is created from current WP installation.
- activate: Activate an existing wordpress environment.
- list: List the available wordpress environments.
- current: Display currently active wordpress environment.
1. Start with './wp-env init'. This will create and activate a 'default' environment equal to your current working WordPress.
2. Use './wp-env create <env_name>' to create a new environment copied from 'default'. Then edit './wp-envs/<env_name>/wp-env.php' if necessary. You also need to create a new database to match your new settings.
CREATE database <env_name> CHARACTER SET utf8mb4
GRANT ALL PRIVILEGES on <env_name>.* to <user>
3. Use './wp-env activate <env_name>' to load a environment