WordPress

Server

Create a server (following the usual process).

Configure the Salt pillar (see existing WordPress sites for an example).

Tip

If you are using the www subdomain, then don’t forget to add a redirect e.g. redirect: hatherleigh.info.

Add swap space to a server

Create a MySQL database using fabric, Database.

To view the database on the server:

mysql --user=www_hatherleigh_info --password=MyPassword www_hatherleigh_info

Database

Tip

We have two options for creating a MySQL backup. Our preference (at the moment) is to use Backup database using cPanel, Terminal rather than Backup database using phpMyAdmin. For more information, see Restore Issue (below)…

Backup database using cPanel, Terminal

cPanel, Advanced, Terminal, identify the folder containing your site e.g. www_hatherleigh_info. Check in wp-config.php for the database name, user and password, then backup:

mysqldump --user=www_hatherleigh_info --password=MyPassword --no-tablespaces www_hatherleigh_info > 2021-11-01-www_hatherleigh_info.sql

Download the backup to your server e.g:

ssh
wget ftp://72.720.72.72/2021-11-01-www_hatherleigh_info.sql --ftp-user=user@name.co.uk --ftp-password=abcdefgh

Then Restore database

Backup database using phpMyAdmin

From Backing Up Your Database. Log into cPanel, then phpMyAdmin:

  • Select the database in the left hand panel.

  • Export (make sure the correct database name is listed in Exporting tables from “…” database).

  • Quick

  • Format SQL

  • Go

e.g. wpbackup.sql

Copy the database backup to your server.

Restore database

Restore the database:

mysql --user=www_hatherleigh_info --password=MyPassword www_hatherleigh_info < wpbackup.sql

Restore Issue

MySQL had an issue restoring the backup:

ERROR 2013 (HY000) at line 308244: Lost connection to MySQL server during query

The MySQL log contains the following:

2021-11-01T09:06:02.289281Z 0 [ERROR] [MY-013183] [InnoDB] Assertion failure: ddl0builder.cc:1495:n >= IO_BLOCK_SIZE thread 140515207010048
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/8.0/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
09:06:02 UTC - mysqld got signal 6 ;

I managed to workaround this issue by backing up using mysqldump and the --no-tablespaces option (Backup database using cPanel, Terminal).

Although I did manage a successful restore after using Backup database using phpMyAdmin by setting net-read-timeout = 60 in /etc/mysql/mysql.cnf:

_images/2021-10-30-net-read-timeout.png

Files

Tip

Downloading files directly to the server will save time downloading to your workstation, then copying back to the cloud.

Tip

Backing Up Your WordPress Files says, The important files to back up would be your wp-config.php file, which contains your settings and your wp-content directory (plus its contents) which contains all your theme and plugin files.

Tip

Browse the folders in your project before downloaded. Check for very large files (e.g. old backups) and remove (if you are sure they aren’t used).

Tip

For our old notes on WordPress backup, see WordPress (Old Notes)

cPanel, Advanced, Terminal, identify the folder containing your site e.g. public_html and archive:

tar cvzf 2021-10-26-public_html.tgz public_html/

Download the archive to your server e.g:

ssh
wget ftp://72.720.72.72/2021-10-26-public_html.tgz --ftp-user=user@name.co.uk --ftp-password=abcdefgh

Extract the archive (as root):

sudo -i root
cd /home/web/repo/project/www.hatherleigh.info/live
tar --strip-components=1 -xzf /home/patrick/repo/temp/2021-10-26-public_html.tgz

Re-run the Salt states (or this command to set the initial permissions):

chown -R www-data:www-data /home/web/repo/project/www.hatherleigh.info/live/

Configure

SSL Certificate

Check that a DNS record exists for the domain, then create an SSL certificate:

init-letsencrypt www.hatherleigh.info - /home/web/repo/project/www.hatherleigh.info/live/

Tip

The above command has worked perfectly, but if you need to use a DNS challenge, see LetsEncrypt - DNS

Config

Tip

wp-config.php is found in the live folder e.g. ~/repo/project/www_hatherleigh.info/live/wp-config.php.

Update wp-config.php:

# update the database details
define('DB_NAME', 'www_hatherleigh_info');
define('DB_USER', 'www_hatherleigh_info');
define('DB_PASSWORD', 'MyPassword');

To override the domain name (for test sites etc), try setting:

define( 'WP_HOME', 'https://www.hatherleigh.info' );
define( 'WP_SITEURL', 'https://www.hatherleigh.info' );

Logging

Use the following in wp-config.php:

define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', 0);

// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
// define( 'SCRIPT_DEBUG', true );

Tip

define('WP_DEBUG', true); sends debug output to the log files (which is what we want)…

Warning

The important thing is to set @ini_set('display_errors', 0);, so the user doesn’t see errors on the screen.

Warning

It would be a security issue to log to the wp-content folder. To avoid this issue, our Salt states configure the PHP pool (see php/fpm.conf).

Check

Check your site health, https://www.hatherleigh.info/wp-admin/site-health.php?tab=debug

Filesystem Permissions shows whether WordPress is able to write to it’s own directories.

Mail

Follow instructions in postfix (check existing sites to make sure notes are up to date)!

Media Library

Check the upload_path for the Media Library:

mysql> SELECT * FROM wp_options WHERE option_name = "upload_path";
+-----------+-------------+---------------------------------------------------------------------+----------+
| option_id | option_name | option_value                                                        | autoload |
+-----------+-------------+---------------------------------------------------------------------+----------+
|        51 | upload_path | /home/web/repo/project/www.hatherleigh.info/live/wp-content/uploads | yes      |
+-----------+-------------+---------------------------------------------------------------------+----------+
1 row in set (0.01 sec)

Note

This example uses wp_ as the table prefix. This prefix may vary.

Swap Space

You may want to Add swap space to a server