LoginSignup
0
1

More than 3 years have passed since last update.

Raspberry Pi に WordPress をインストールする

Last updated at Posted at 2020-05-02

ネットで拾ってきた情報の寄せ集めですが
最近すぐに忘れてしまうので、冒険の記録を取っておくことにします。

環境

  • Raspberry pi 3 Model B Rev 1.2
  • Raspbian GNU/Linux 9.4 (stretch)
  • Linux version 4.14.79
  • MySQL version 15.1 Distrib 10.1.38-MariaDB
  • WordPress 5.4.1

WordPress のデータベースとユーザーを作成する

何気なく MySQL 使ってますがインストールは
外為で勝つために その2 ~ MySQL 接続編 をご参照ください。

pi@raspberrypi:~ $ sudo mysql -p
MariaDB [(none)]> CREATE DATABASE wordpress;
MariaDB [(none)]> CREATE USER 'wordpress'@'localhost' IDENTIFIED BY '************';
MariaDB [(none)]> USE mysql;
MariaDB [mysql]> SELECT user, password, plugin FROM user;
+------------+-------------------------------------------+--------+
| user       | password                                  | plugin |
+------------+-------------------------------------------+--------+
| root       | ***************************************** |        |
| wordpress  | ***************************************** |        |
+------------+-------------------------------------------+--------+
5 rows in set (0.00 sec)

MariaDB [mysql]> GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY '************';

多分ないとは思いますが、WordPress 管理者のパスワードを忘れたときのために
転ばぬ先の phpMyAdmin を入れておくと便利ですね。リセットできるので。

phpMyAdmin は下記の記事でインストールしてます。
外為で勝つために その3 ~ LAMP 構築編

WordPress をインストール

ちなみに www-data は Apache のサービスアカウントとのことです。
wordpress ディレクトリにその所有権を付ける必要があるかというと、特に無くてまあ何となく付けてみた感じなので気にしなくても良いです。

pi@raspberrypi:~ $ cd /var/www/html
pi@raspberrypi:/var/www/html $ sudo wget http://wordpress.org/latest.tar.gz
YYYY-MM-DD hh:mm:ss (532 KB/s) - `latest.tar.gz' へ保存完了 [12389281/12389281]

pi@raspberrypi:/var/www/html $ sudo tar xzf latest.tar.gz
pi@raspberrypi:/var/www/html $ sudo rm latest.tar.gz
pi@raspberrypi:/var/www/html $ sudo chown -R www-data:www-data /var/www/html/wordpress

http://192.168.X.X/wordpress/ にアクセス
データベース名: wordpress
ユーザー名: wordpress
パスワード: ************
データベースのホスト名: localhost
テーブル接頭辞: wp_

サイトのタイトル: ************
ユーザー名: ************
パスワード: ************
メールアドレス: ************
検索エンジンがサイトをインデックスしないようにする: OFF

パーマリンク設定

これをやらないと、トップページ以外 404 エラーになってしまうようです。
調べるのには結構時間を費やしましたが、作業は簡単。

a2enmod rewrite を実行してリダイレクトを有効にします。
そして、apache2.confDirectory /var/www にある
AllowOverride NoneAllowOverride All に変えるだけです。

そうそう、再起動も忘れずに。

pi@raspberrypi:/var/www/html $ sudo a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
  systemctl restart apache2
pi@raspberrypi:/var/www/html $ sudo systemctl restart apache2
pi@raspberrypi:/var/www/html $ sudo vi /etc/apache2/apache2.conf

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

pi@raspberrypi:/var/www/html $ sudo systemctl restart apache2

PHP 7.0 → PHP 7.3 へ

WordPress は PHP 7.3 推奨だそうです。

あれ?
PHP 7.3 はすでにインストールしていましたが、apache では認識されていませんでした。
外為で勝つために その5 ~ Laravel 編

pi@raspberrypi:/usr/bin $ sudo a2enmod php7.3
Considering dependency mpm_prefork for php7.3:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php7.3:
Enabling module php7.3.
To activate the new configuration, you need to run:
  systemctl restart apache2
pi@raspberrypi:/usr/bin $ sudo systemctl restart apache2

pi@raspberrypi:~ $ sudo a2dismod php7.0
Module php7.0 disabled.
To activate the new configuration, you need to run:
  systemctl restart apache2
pi@raspberrypi:~ $ sudo systemctl restart apache2

pi@raspberrypi:~ $ sudo apt-get update
pi@raspberrypi:~ $ sudo apt install php7.3-mysql
pi@raspberrypi:~ $ sudo apt install php7.3-curl
pi@raspberrypi:~ $ sudo apt install php7.3-gd
pi@raspberrypi:~ $ sudo apt install phpmyadmin

やってることは PHP 7.3 を有効にして、PHP 7.0 を無効化してるだけです。
あと PHP 7.3 用の mysql, curl, gd, phpmyadmin をインストールしました。
phpmyadmin 以外は WordPress で必要みたいです。

ちなみに phpmyadmin で以下のような意味わからん警告が多発しました。
Warning in ./libraries/sql.lib.php#613

pi@raspberrypi:~ $ sudo vi /usr/share/phpmyadmin/libraries/sql.lib.php
613 | (count($analyzed_sql_results['select_expr'] == 1)
 ↓
613 | ((count($analyzed_sql_results['select_expr']) == 1)

613 行目のコードにカッコを付けてあげるだけで解消しました。なんだそれ。

imagemagick のインストール

ほとんどの問題は解消しましたが、imagemagick が読み込まれていないと WordPress からお達しがありました。
対応しなくても良さそうですが興味本位でやってみました。

結果、やるんじゃなかったと猛省。

pi@raspberrypi:~ $ sudo apt install libmagickwand-dev
pi@raspberrypi:~ $ sudo apt install imagemagick

pi@raspberrypi:~ $ cd /usr/bin
pi@raspberrypi:/usr/bin $ sudo wget http://pear.php.net/go-pear.phar
pi@raspberrypi:/usr/bin $ sudo php go-pear.phar

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation base ($prefix)                   : /usr
 2. Temporary directory for processing            : /tmp/pear/install
 3. Temporary directory for downloads             : /tmp/pear/install
 4. Binaries directory                            : /usr/bin
 5. PHP code directory ($php_dir)                 : /usr/share/php
 6. Documentation directory                       : /usr/docs
 7. Data directory                                : /usr/data
 8. User-modifiable configuration files directory : /usr/cfg
 9. Public Web Files directory                    : /usr/www
10. System manual pages directory                 : /usr/man
11. Tests directory                               : /usr/tests
12. Name of configuration file                    : /etc/pear.conf

1-12, 'all' or Enter to continue: [そのまま Enter]

Would you like to alter php.ini </etc/php/7.3/cli/php.ini>? [Y/n] : [そのまま Enter]

php.ini </etc/php/7.3/cli/php.ini> include_path updated.

Current include path           : .:/share/php
Configured directory           : /usr/share/php
Currently used php.ini (guess) : /etc/php/7.3/cli/php.ini
Press Enter to continue: 

The 'pear' command is now at your service at /usr/bin/pear

** The 'pear' command is not currently in your PATH, so you need to
** use '/usr/bin/pear' until you have added
** '/usr/bin' to your PATH environment variable.

Run it without parameters to see the available actions, try 'pear list'
to see what packages are installed, or 'pear help' for help.

For more information about PEAR, see:

  http://pear.php.net/faq.php
  http://pear.php.net/manual/

Thanks for using go-pear!

pi@raspberrypi:/usr/bin $ sudo pecl install imagick
pi@raspberrypi:/usr/bin $ pecl list
Installed packages, channel pecl.php.net:
=========================================
Package Version State
imagick 3.4.4   stable

pi@raspberrypi:/usr/bin $ sudo vi /etc/php/7.0/apache2/php.ini
# php.ini の extension 辺りに追加
extension=imagick.so

pi@raspberrypi:/usr/bin $ sudo service apache2 restart

pi@raspberrypi:/usr/bin $ sudo apt install php-imagick

php.ini の extension 追加ではうんともすんとも変わらず。
php-imagick をインストールしたら WordPress は喜んでくれました。
最後の1コマンドだけで他は必要なかった?

マルチサイト化

せっかくなので、マルチサイト化もやっておこうと思いまして。

pi@raspberrypi:~ $ /var/www/html/wordpress/wp-config.php

  // 以下のコードを追加
  /** Enable network (Multi-site function) */
  define( 'WP_ALLOW_MULTISITE', true );

  // ダッシュボード → ツール → サイトネットワークの設置
  // WordPress サイトネットワークの作成を行ったあと、以下のコードを追加
  define('MULTISITE', true);
  define('SUBDOMAIN_INSTALL', false);
  define('DOMAIN_CURRENT_SITE', '192.168.X.X');
  define('PATH_CURRENT_SITE', '/wordpress/');
  define('SITE_ID_CURRENT_SITE', 1);
  define('BLOG_ID_CURRENT_SITE', 1);

  // パーマリンクに問題(404 not found)がある場合
  // ダッシュボード → 設定 → パーマリンク設定 → 投稿名
  // を試してみること

  // 追加ここまで
  /* That's all, stop editing! Happy publishing. */


pi@raspberrypi:~ $ /var/www/html/wordpress/.htaccess

  # <IfModule mod_rewrite.c> ... </IfModule> を以下の内容に書き換える
  RewriteEngine On
  RewriteBase /wordpress/
  RewriteRule ^index\.php$ - [L]

  # add a trailing slash to /wp-admin
  RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]
  RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
  RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
  RewriteRule . index.php [L]

再度ログインしてマルチサイト化したことを確認します。
ああ、疲れた。もう二度とやりたくないですね。

まとめ

まともな思考を持っている人ならレンタルサーバーで運用することをお勧めします。
以上です。ここまでお読みいただきありがとうございました。

0
1
14

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1