Fashionable WordPress®1 construction has more and more embraced Composer to be able to set up dependencies and give a boost to workflow consistency. Whether or not you’re the usage of a tradition Composer setup or a framework like Bedrock, WP Engine helps deploying those initiatives—with a couple of changes.

This information covers the way to construction and deploy a Composer-based web site to WP Engine the usage of GitHub Movements, together with Bedrock-specific notes.

Advantages of The usage of Composer for WordPress

Composer is a dependency control software in PHP that provides a number of benefits for WordPress construction:

  • Dependency Control: Simply set up WordPress core, plugins, subject matters, and PHP programs.
  • Model Keep watch over: Stay observe of actual variations of all dependencies, making sure consistency throughout environments.
  • Automation: Automate updates and deployments, decreasing guide mistakes.
  • Cleaner Repositories: Keep away from committing seller information or plugin code, retaining your repository blank and fascinated about tradition code.

By means of leveraging Composer, you’ll be able to create a extra maintainable and scalable WordPress challenge.

Managing Plugins and Subject matters with WPackagist

WPackagist mirrors the WordPress.org plugin and theme directories as Composer programs, permitting you to regulate them as dependencies.

Tip

At WP Engine, we consider that making sure the stableness and reliability of crucial developer infrastructure is very important to the WordPress ecosystem. That’s why we’re now the maintainer of WPackagist.

To make use of WPackagist:

1. Upload WPackagist as a repository for your composer.json:

{
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    }
  ]
}

2. Require plugins or subject matters the usage of the wpackagist-plugin or wpackagist-theme prefixes:

{
  "require": {
    "wpackagist-plugin/advanced-custom-fields": "^6.0",
    "wpackagist-theme/twentytwentysix": "*"
  }
}

3. Run composer set up to put in the required plugins and subject matters.

This manner guarantees that your plugins and subject matters are version-controlled and can also be simply up to date or rolled again as wanted.

Challenge Construction Issues

Standard Composer-based websites transfer the WordPress core information to another listing, for instance /internet or /public and with that the wp-content listing housing the plugins and subject matters will transfer there too. Then again, it is a other construction anticipated via WP Engine as a controlled website hosting platform. Bedrock additionally organizes WordPress information another way than the standard construction anticipated via WP Engine.

Bedrock Construction:

├── composer.json
├── composer.lock
├── config/
├── internet/
│   ├── app/            # wp-content similar
│   ├── wp/             # WordPress core
│   ├── index.php
│   └── wp-config.php
└── .env

WP Engine Anticipated Construction:

├── wp-content/
├── wp-includes/
├── wp-admin/
├── index.php
├── wp-config.php
...

To deploy a Composer or Bedrock-based web site to WP Engine, you’ll want to restructure your challenge all through the deployment procedure to check WP Engine’s expectancies.

Deployment with GitHub Movements

Use WP Engine’s reputable GitHub Motion to automate deployments. This manner syncs your wp-content/ listing and runs Composer all through the construct step.

Usual Composer Setup

For websites the usage of Composer with a typical WordPress construction:

call: Deploy to WP Engine

on:
  push:
    branches:
      - primary

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - call: Checkout repository
        makes use of: movements/checkout@v4

      - call: Setup PHP
        makes use of: shivammathur/setup-php@v2
        with:
          php-version: '8.2'
          equipment: composer:v2

      - call: Set up Composer dependencies
        run: composer set up --no-dev --optimize-autoloader --prefer-dist

      - call: Deploy to WP Engine
        makes use of: wpengine/github-action-wpe-site-deploy@v3
        with:
          WPE_SSHG_KEY_PRIVATE: ${{ secrets and techniques.WPE_SSHG_KEY_PRIVATE }}
          WPE_ENV: your-environment-name
          SRC_PATH: wp-content/
          REMOTE_PATH: wp-content/
          FLAGS: -azvr --inplace --delete --exclude='uploads'

Together with Composer Dependencies (Not obligatory)

In case your plugins or subject matters require PHP programs from seller/, you’ll want to come with it within the deployment. Since simplest wp-content/ is synced to WP Engine, replica seller into wp-content/ and upload a mu-plugin to load the autoloader:

- call: Set up Composer dependencies
        run: composer set up --no-dev --optimize-autoloader --prefer-dist

      - call: Get ready seller for deployment
        run: |
          mkdir -p wp-content/mu-plugins

          # Create autoloader mu-plugin
          cat > wp-content/mu-plugins/00-autoloader.php << 'EOF'
          

Composer’s autoloader makes use of relative paths, so it really works accurately from wp-content/seller/.

Bedrock Setup

For Bedrock initiatives, you’ll want to restructure from internet/app/ to wp-content/ all through the construct.

Bedrock in most cases a lot the Composer autoloader by way of its wp-config.php. Since WP Engine manages wp-config.php, the workflow beneath creates a mu-plugin to load it as an alternative. The 00- prefix guarantees it a lot prior to different mu-plugins.

FLAGS: -azvr --inplace --delete --exclude='uploads'

Setup Necessities

  1. SSH Key: Upload your WP Engine SSH personal key as a repository secret named WPE_SSHG_KEY_PRIVATE. Generate by way of WP Engine Person Portal > SSH Keys.
  2. Surroundings Identify: Substitute your-environment-name together with your WP Engine surroundings call.
  3. Department Triggers: Modify the branches cause as wanted (e.g., primary for manufacturing, staging for staging).

Essential Notes

  • WordPress core: WP Engine manages core information. Simplest deploy your wp-content/ or similar.
  • Uploads: Media uploads don't seem to be integrated in deployments. Use SFTP or WP Engine’s backup/repair equipment.
  • Seller listing: Required for Bedrock to allow the mu-plugin listing loader and any Composer dependencies. Come with the 00-autoloader.php mu-plugin to load it.
  • Surroundings variables: Bedrock makes use of .env information. Be certain that environment-specific config is treated as it should be for WP Engine.
  • First deploy: After your first deployment, log in to WordPress and turn on your theme. The deploy makes use of --delete which gets rid of the default theme, so that you’ll want to turn on the theme you deployed.

Additional Studying

  1. WP Engine is a proud member and supporter of the group of WordPress® customers. The WordPress® logos are the highbrow assets of the WordPress Basis, and the Woo® and WooCommerce® logos are the highbrow assets of WooCommerce, Inc. Makes use of of the WordPress®, Woo®, and WooCommerce® names on this website online are for identity functions simplest and don't suggest an endorsement via WordPress Basis or WooCommerce, Inc. WP Engine isn't recommended or owned via, or affiliated with, the WordPress Basis or WooCommerce, Inc. ↩

The submit Deploying a Composer-Based totally WordPress Website (Together with Bedrock) to WP Engine seemed first on WP Engine®.

WordPress Hosting

[ continue ]