gilzow / 2023-HighEdWeb-Presentation

The Demo Site for the 2023 HighEdWeb Presentation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WordPress (Composer) for Platform.sh

Deploy on Platform.sh

This template builds WordPress on Platform.sh using the johnbloch/wordpress "Composer Fork" of WordPress. Plugins and themes should be managed with Composer exclusively. A custom configuration file is provided that runs on Platform.sh to automatically configure the database, so the installer will not ask you for database credentials. For local-only configuration you can use a wp-config-local.php file that gets excluded from Git.

WordPress is a blogging and lightweight CMS written in PHP.

Features

  • PHP 7.4
  • MariaDB 10.4
  • Automatic TLS certificates
  • Composer-based build

Post-install

  1. Run through the WordPress installer as normal. You will not be asked for database credentials as those are already provided.

  2. This example looks for an optional wp-config-local.php in the project root that you can use to develop locally. This file is ignored in Git.

Example wp-config-local.php:

<?php

define('WP_HOME', "http://localhost");
define('WP_SITEURL',"http://localhost");
define('DB_NAME', "my_wordpress");
define('DB_USER', "user");
define('DB_PASSWORD', "a strong password");
define('DB_HOST', "127.0.0.1");
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');

// These will be set automatically on Platform.sh to a different value, but that won't cause issues.
define('AUTH_KEY', 'SECURE_AUTH_KEY');
define('LOGGED_IN_KEY', 'LOGGED_IN_SALT');
define('NONCE_KEY', 'NONCE_SALT');
define('AUTH_SALT', 'SECURE_AUTH_SALT');

Customizations

The following changes have been made relative to WordPress as it is downloaded from WordPress.org. If using this project as a reference for your own existing project, replicate the changes below to your project.

  • It uses the johnbolch/wordpress "Composer Fork" of WordPress, which allow the site to be managed entirely with Composer.
  • The .platform.app.yaml, .platform/services.yaml, and .platform/routes.yaml files have been added. These provide Platform.sh-specific configuration and are present in all projects on Platform.sh. You may customize them as you see fit.
  • An additional Composer library, platformsh/config-reader, has been added. It provides convenience wrappers for accessing the Platform.sh environment variables.
  • The wp-config.php file has been modified to use the Config Reader to configure WordPress based on Platform.sh environment variables if present. If not, your own wp-config-local.php file will be loaded to configure the site for local development.
  • A base Landofile provides configuration to use this template locally using Lando.
  • Any themes and plugins present in the most recent version of WordPress are detected and have been added as dependencies in composer.json so they are easier to update.
  • The upstream composer.json file has been modified to include the script subdirComposer. It moves wp-config.php into the default install directory and docroot wordpress after composer install is run. It also removes a nested directory wordpress/wp-content/wp-content. Since WordPress is not by default intended to be installed via Composer, anything Composer-related wrapping around it does not always perfectly interact, and adding new themes and plugins via Composer is a case of this. If this command was not included, the initial deployment would work just fine, and the default themes and plugins would end up where you would expect in wordpress/wp-content/[themes|plugins]. However, once you composer require additional packages from WPackagist, those original default packages end up in a nested subdirectory wordpress/wp-content/wp-content and are inaccessible to WordPress. This is another reason that those default themes and plugins are added to composer.json, allowing us to remove this artifact when WordPress builds with Composer. You can view the original issue here.

Local development

This template has been configured for use with Lando. Lando is Platform.sh's recommended local development tool. It is capable of reading your Platform.sh configuration files and standing up an environment that is very similar to your Platform.sh project. Additionally, Lando can easily pull down databases and file mounts from your Platform.sh project.

To get started using Lando with your Platform.sh project check out the Quick Start or the official Lando Platform.sh documentation.

References

About

The Demo Site for the 2023 HighEdWeb Presentation


Languages

Language:PHP 100.0%