Get your WordPress installation into version control with wp-composer
wp-composer allows you to convert your existing WordPress site (or new WordPress project) into a version-controlled Git repository where WordPress is installed as a Composer dependency.
The power of this package lies in the ability to create version-controlled WordPress project where rapid, collaborative theme and plugin development is made easy. This method is not well-suited for WordPress sites which depend heavily on third-party plugins and themes which need to be updated through wp-admin.
What does wp-composer change in WordPress?
1. Makes a better directory structure for your WordPress project which looks like this:
- /public/ — The publicly-accessible root
- /public/wp — WordPress files installed by Composer (not included in version control)
- /public/wp-content — The wp-content directory contains all the plugins and themes unique to your WordPress project. Typically, when migrating an existing WordPress site to wp-composer, you would install using a “composer install” and copy the contents of your existing wp-content to this directory
- / — The project root is behind the publicly accessible web root and contains any other dependencies you might want to require in the vendor directory.
2. Improvement in WordPress configuration. In the project root you’ll find a local-config.sample.php — the modified wp-config.php located in the public directory will look first for a production-config.php and then fall back on a local-config.php. This will allow you to seamlessly manage your local/production configuration.
- Clone this repo into a fresh directory
- Copy the contents of your wp-content directory into public/wp-content
- Modify the .gitignore according to which parts of wp-content you’d like to include in version control. By default the wp-content/uploads directory is ignored
- Copy local-config.sample.php to local-config.php and migrate your configuration values
- Run composer install
- In your wp-options table, be sure to set your siteurl option to http://yourdomain.com/wp and your home option to http://yourdomain.com
- In his article on using Composer to manage Git, Gilbert Pellegrom discusses using composer to manage the installation of WordPress plugins and themes. This package doesn’t proclude you from doing so, but I’ve found it is much easier to solely deal with plugin and theme installations in the traditional way.
- The installation of plugins and themes often alters tables in the database. If your public/wp-content/plugins is included in version control, take care to install the plugin on both environments (from within the WordPress admin).
- This package was created based on part 4 of Gilbert Pellegrom’s 4 part series on working with WordPress in Git and Composer.
Checkout wp-composer on Github!