Raspberry Pi でWordPressを動かす

備忘録を残すために,すでに運用していたRaspberryPi上にWordPressを構築します.環境は以下の通り.

  • Raspberry Pi 3 Model B+
  • apache2 + php
  • mariadb-server

パッケージのインストール

必要なパッケージをインストールします.

# apt install -y apache2 php mariadb-server

データベースの作成

WordPressで利用するデータベースとユーザを作成します.

# mysql
MariaDB [(none)]> create user 'wp'@'localhost' identified by 'password';
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> grant all privileges on wordpress.* to 'wp'@'localhost';

WordPressのダウンロード

WordPressの最新版をダウンロードします.

$ wget wget https://ja.wordpress.org/latest-ja.tar.gz

展開して配置します.

$ tar zxf latest-ja.tar.gz
# mv wordpress /var/www/wordpress
# chown -R www-data:www-data /var/www/wordpress

設定ファイルを編集します.

# mv /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php
# vi /var/www/wordpress/wp-config.php

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wp' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );

define( 'AUTH_KEY',         '乱数' );
define( 'SECURE_AUTH_KEY',  '乱数' );
define( 'LOGGED_IN_KEY',    '乱数' );
define( 'NONCE_KEY',        '乱数' );
define( 'AUTH_SALT',        '乱数' );
define( 'SECURE_AUTH_SALT', '乱数' );
define( 'LOGGED_IN_SALT',   '乱数' );
define( 'NONCE_SALT',       '乱数' );

Apacheの設定

phpを有効にします.

# a2enconf php7.4-fpm 

rewriteを有効にします.

# a2enmod rewrite

DocumentRootを変更します.

# vi /etc/apache2/sites-enabled/000-default.conf

DocumentRoot /var/www/wordpress

Apacheを再起動します.

# systemctl restart apache2

WordPressの初期設定

Webブラウザからアクセスして初期設定すれば完了.リバースプロキシ下でhttpsアクセスの場合はwp-config.phpに以下の設定を忘れずに.

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $_SERVER['HTTPS'] = 'on';
}