Configure WordPress#

Apache#

Follow the Configure Apache documentation, using the wordpress configuration at the Add sites step.

In the service’s Pillar file, add, for example:

apache:
  public_access: True
  sites:
    coalition:
      configuration: wordpress
      servername: www.open-spending.eu
      serveraliases: ['open-spending.eu']
      context:
        user: coalition
        socket: /var/run/php/php-fpm-coalition.sock

MySQL and PHP#

Follow the Configure MySQL and Configure PHP documentation.

PHP-FPM#

Configure PHP-FPM to correspond to the Apache configuration. For example:

phpfpm:
  sites:
    coalition:
      configuration: default
      context:
        user: coalition
        listen_user: www-data
        socket: /var/run/php/php-fpm-coalition.sock

Note

You can create a custom configuration, if needed.

WordPress#

Note

Salt contains WordPress states, but they are limited. Also, WordPress is often deployed by copying files, rather than via fresh installs.

  1. Configure WP-CLI. In the service’s Pillar file, add, for example:

    wordpress:
      cli_version: 2.7.1
    
  2. Deploy the service.

  3. Connect to the server as the WordPress user (e.g. coalition).

  4. Change to the public_html directory:

    cd ~/public_html
    
  5. Download WordPress:

    wp core download --locale=en_US
    
  6. Create the wp-config.php file, and configure the database connection, to correspond to the MySQL configuration. For example:

    wp config create --dbname=DBNAME --dbuser=USERNAME --dbpass=PASSWORD
    
  7. Set WP_AUTO_UPDATE_CORE, to enable minor WordPress updates only.

    wp config set WP_AUTO_UPDATE_CORE minor
    
  8. Install WordPress, with a siteadmin user associated to sysadmin@open-contracting.org. For example:

    wp core install --url=www.open-spending.eu --title="www.open-spending.eu" --admin_user=siteadmin --admin_password=PASSWORD --admin_email=sysadmin@open-contracting.org --skip-email
    
  9. Uninstall default plugins:

    wp plugin uninstall hello
    
  10. Add a must-use plugin to auto-update plugins for non-major versions only:

    mkdir -p wp-content/mu-plugins
    cat > wp-content/mu-plugins/opencontracting_auto_update_plugin.php <<'END'
    <?php
    // Auto-update a plugin if a new version is available and it is neither a new major version
    // nor a new minor version within major version zero.
    // https://core.trac.wordpress.org/ticket/51126
    function opencontracting_auto_update_plugin( $value, $item ) {
            // https://developer.wordpress.org/reference/functions/wp_plugin_directory_constants/
            $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $item->plugin , false, false );
            // https://developer.wordpress.org/reference/functions/get_plugin_data/#return
            $old_version = explode( '.', $plugin_data['Version'] );
            $new_version = explode( '.', $item->new_version );
            // https://github.com/dependabot/fetch-metadata/blob/924483a/src/dependabot/update_metadata.ts#L77-L94
            if (
                    $old_version !== $new_version
                    && $old_version[0] === $new_version[0]
                    && ( $old_version[0] !== '0' || $old_version[1] === $new_version[1] )
            ) {
                    return true;
            }
            return $value;
    }
    // https://developer.wordpress.org/advanced-administration/upgrade/upgrading/#configuration-via-filters
    // https://developer.wordpress.org/reference/functions/add_filter/
    // https://developer.wordpress.org/reference/hooks/auto_update_type/
    add_filter( 'auto_update_plugin', 'opencontracting_auto_update_plugin', 10, 2 );
    END
    
  11. If you have a custom theme, download and activate it. For example:

    git -C wp-content/themes/ clone https://github.com/open-contracting-partnership/www.open-spending.eu.git
    wp theme activate www.open-spending.eu
    

Migration#

When migrating domains or renaming themes, you might need to search and replace items in the database, using the wp search-replace command.

  1. Run the command with the --dry-run flag, for example:

    wp search-replace --report-changed-only --all-tables --precise --log=/tmp/wp-search-replace.log --dry-run 'open-spedning-coalition' 'www.open-spending.eu'
    
  2. Read the log file to check that no undesired replacements will be made:

    less /tmp/wp-search-replace.log
    
  3. Run the command without the --dry-run flag.

Strings to replace might include:

  • Developer email addresses

  • Domain names

  • Theme names

  • File paths

If the site uses these plugins, perform these operations to remove old items in the database:

  • Rank Math: Status & Tools menu item > Database Tools tab > Click the Delete Internal Links and Clear 404 Log buttons.

  • WordFence: Scan menu item -> Click the START NEW SCAN button. You can also manually delete rows from the wp_wfhits and wp_wflogins tables.