Configure WordPress¶
Apache¶
Follow the Configure Apache documentation, using the wordpress configuration at the Add sites step.
In the server’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
This will:
Enable the proxy_fcgi Apache module
Install the PHP-FPM service
Create a
/var/log/php-fpm/coalition/log directoryCreate a
/etc/php/-/fpm/pool.d/coalition.confconfiguration fileInstall PHP packages
The configuration file enables log_errors and sets error_log to /var/log/php-fpm/coalition/coalition.log.
Configure logrotate for the log files:
logrotate:
conf:
php-site-logs:
source: php-site-logs
context:
php_version: '8.1'
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.
Configure WP-CLI and the site. In the server’s Pillar file, add, for example:
wordpress: cli_version: 2.7.1 sites: coalition: database: coalition_wp cron: contact: - sysadmin@open-contracting.org
Connect to the server as the WordPress user (e.g.
coalition).Change to the
public_htmldirectory:cd ~/public_html
Download WordPress:
wp core download --locale=en_US
Create the
wp-config.phpfile, and configure the database connection to correspond to the MySQL configuration. For example:wp config create --dbname=DBNAME --dbuser=USERNAME --dbpass=PASSWORD
Install WordPress, creating a user for yourself. For example:
wp core install --url=www.open-spending.eu --title="www.open-spending.eu" --admin_user=jmckinney --admin_password=PASSWORD --admin_email=jmckinney@open-contracting.org --skip-email
Uninstall default plugins:
wp plugin uninstall hello
Install Two Factor (2FA is required for administrators by the
require-two-factormust-use plugin):wp plugin install two-factor --activate
Install Sentry for WordPress. Activation is optional, as it’s loaded by the
00-sentrymust-use plugin.wp plugin install wp-sentry-integration
Add or override any constants, setting values to strings of PHP source. (The constants under
wordpress:constantsin thepillar/cms.slsfile are configured on every site.) For example:wordpress: sites: USERNAME: constants: WP_AUTO_UPDATE_CORE: 'false'
Create a project in Sentry, and set its DSN in the site’s private Pillar file:
wordpress: sites: USERNAME: constants: WP_SENTRY_PHP_DSN: "'https://1234567890abcdef1234567890abcdef@o123456.ingest.sentry.io/1234567890123456'"
Note
The SDK sends each event over HTTPS as the request ends, occupying a PHP-FPM worker until the send completes.
WP_SENTRY_CLIENTBUILDER_CALLBACKcaps each send at a second.Tip
To monitor browser JavaScript errors, create a new project, and set the
WP_SENTRY_BROWSER_DSNconstant.Add any must-use plugins, with any context they need. (The must-use plugins under
wordpress:mu_pluginsin thepillar/cms.slsfile are installed on every site.) For example:wordpress: sites: USERNAME: mu_plugins: - fathom-analytics context: FATHOM_ANALYTICS_ID: ABCDEFGH
Schedule checks. Omit
integrityif the site uses a security plugin’s file scanner, andupdatesif an administrator updates plugins manually:wordpress: sites: USERNAME: checks: scheduled: - integrity - updates - silent premium_plugins: - advanced-custom-fields-pro
Interpreting the emails it sends
The
integritycheck lists core and plugin files that differ from wordpress.org’s copy: modified, missing or added. A plugin that writes to its own directory can cause a false positive. Confirm changes before restoring files from a backup.wordpress.org has no copy of a premium plugin, so the
integritycheck instead lists the files that changed while the plugin’s version didn’t. It records the files of each new version inpremium-plugin-checksums.json, in the site’s home directory.The
updatescheck lists the updates that won’t install automatically: a major version, ifWP_AUTO_UPDATE_COREis'minor'; a plugin or theme whose auto-updates are off; and a version that requires a newer PHP version than the server runs.The
silentcheck lists the plugins whose update API gave no answer, which can be due to an HTTP timeout, an expired license, or the plugin being closed on wordpress.org.
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
Reference: Hardening WordPress
Migration¶
When migrating domains or renaming themes, you might need to search and replace items in the database, using the wp search-replace command.
Run the command with the
--dry-runflag, 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'
Read the log file to check that no undesired replacements will be made:
less /tmp/wp-search-replace.logRun the command without the
--dry-runflag.
Strings to replace might include:
Developer email addresses
Domain names
Theme names
File paths