Upgrade your WordPress site to use Composer
Back to home
On this page
Composer helps you declare, manage, and install all the dependencies needed to run your project. It allows you to make your WordPress site more stable, more secure, and easier to maintain.
With Composer, you don’t need to commit all of WordPress core, its themes and plugins to your project’s Git repository. You also don’t need to manage any of these elements as Git submodules.
Before you begin
To update your WordPress site to use Composer, check that:
- You already have a vanilla version of WordPress installed locally.
- Your project has been set up for deployment on Upsun Fixed. If you don’t have Upsun Fixed configuration files in your repository, deploy WordPress without Composer before upgrading to a Composer-based site.
- You have downloaded and installed Composer.
1. Install WordPress with Composer
To install WordPress with Composer, complete the following steps:
-
Switch to a new Git branch.
To safely make changes to your repository and Upsun Fixed environment, run the following command:
$ git checkout -b composer -
Turn your repository into a Composer repository.
To use Composer, you need:
- A
composer.jsonfile listing all the dependencies needed for your project to run (WordPress itself, its plugins, and its themes). - A
composer.lockfile listing the exact versions of all the dependencies installed on your project. Generated from thecomposer.jsonfile, it ensures repeatable builds until you update.
To turn your repository into a Composer repository and generate those files, run the following command:
$ composer initWhen prompted, set metadata attributes for your project, such as its name and license information. When you get to the part about installing dependencies, type
no, as you add them in step 5. - A
-
Clean up WordPress core.
If you’ve been managing WordPress and its dependencies as Git submodules, remove the submodules.
Otherwise, your existing installation of WordPress core is assumed to be in a subdirectory of your repository (often named
wordpress). For Composer to manage WordPress, remove this subdirectory:$ rm -rf wordpressThen, at the end of your existing
.gitignorefile, add the content of Upsun Fixed’s template.gitignorefile.This adds the
wordpresssubdirectory to the resulting.gitignorefile. This way, after Composer reinstalls WordPress, thewordpresssubdirectory is ignored in commits.Now remove WordPress from the repository:
$ git rm -rf --cached wordpress && rm -rf wordpress $ git add . && git commit -m "Remove WordPress" -
Launch the installation of WordPress with Composer.
Now that you have made your WordPress site into a Composer project, you can download packages via Composer.
To download WordPress itself, run the following commands:
$ composer require johnpbloch/wordpress-core-installer $ composer require johnpbloch/wordpress-coreThe two dependencies are now listed in your
composer.jsonfile:{ "require": { "johnpbloch/wordpress-core-installer": "^2.0", "johnpbloch/wordpress-core": "^6.0" } } -
Complete the installation:
$ composer installComposer reinstalls WordPress into the
wordpresssubdirectory.
2. Install WordPress themes and plugins with Composer
Just like with WordPress core, you can install themes and plugins with the composer require command.
To do so, complete the following steps:
-
Configure the WPackagist repository.
By default, when you download dependencies using Composer, you retrieve them through Packagist, which is the primary Composer repository for public PHP packages. Some themes and plugins for WordPress are also on Packagist, but most of them are accessible through a similar service specific to WordPress called WPackagist.
To allow Composer to download packages from the WPackagist repository, run the following command:
$ composer config repositories.wppackagist composer https://wpackagist.orgWPackagist is now listed in your
composer.jsonfile:{ "repositories": { "wppackagist": { "type": "composer", "url": "https://wpackagist.org" } } } -
Optional: Configure theme and plugin destination.
By default, Composer places installed dependencies in a
vendorsubdirectory.You can configure a different destination for your themes and plugins. For instance, to install them into
wp-content, add the following configuration:composer.json"extra": { "installer-paths": { "wordpress/wp-content/plugins/{$name}": [ "type:wordpress-plugin" ], "wordpress/wp-content/themes/{$name}": [ "type:wordpress-theme" ], "wordpress/wp-content/mu-plugins/{$name}": [ "type:wordpress-muplugin" ] } }Make sure you add the new destination subdirectories to your
.gitignorefile.After inspecting package metadata, Composer now installs plugins with a
typeofwordpress-pluginintowordpress/wp-content/plugins/instead ofvendor. And similarly for themes and must-use plugins. -
Launch the installation of plugins and themes with Composer.
To search for themes and plugins in WPackagist and install them through Composer, run a
composer requirecommand:# Plugin $ composer require wpackagist-plugin/wordpress-seo # Theme $ composer require wpackagist-theme/huemanThe two dependencies are now listed in your
composer.jsonfile. -
Complete the installation:
$ composer installEach dependency is now installed.
3. Deploy to Upsun Fixed
Switching to a Composer-based installation doesn’t require any modifications to the Upsun Fixed configuration files created when you deployed your vanilla version. Make sure that your project contains those three files. You can then commit all your changes and deploy your new Composer-based WordPress site to Upsun Fixed:
git add . && git commit -m "Composerify plugins and themes."
git push platform composer 4. Update your Composer-based WordPress site
Perform a standard update with Composer
Updating WordPress, your themes and plugins becomes a lot simpler with Composer. When a new version becomes available, create a new branch and launch the update:
git checkout -b updates
composer update Automate your updates with a source operation
Tier availability
This feature is available for Elite and Enterprise customers. Compare the tiers on our pricing page, or contact our sales team for more information.
Source operations allow you to automate the maintenance of your Composer-based WordPress site. For instance, you can update all the dependencies in your project with a single command.