Linuxと生きていきたい

Arch LinuxとかRaspberry Piとか使って色々やってみたい

Arch Linux + VagrantでLEMP & wordpressをインストールしてみた。

その内Wordpressでブログやりたいと思ってたので。その備忘録。

目次

環境

基本はArch LinuxのWikiを参考に、ここではapacheは使わずnginxに拘る。

Vagrantの初期化

Vagrant用のディレクトリがある前提。

cd ~/vagrant
mkdir archlinux
cd archlinux
vagrant init archlinux/archlinux
vagrant up

そのままsshでarch linuxにログイン。

vagrant ssh

nginxユーザーの追加

wordpress専用のユーザーなら名前は問わない。ここではnginxとする。

# useradd nginx

nginxのインストール

とりあえずアップデート。

# pacman -Syu

後で結局全部入れる羽目になるけど、ここでは順を追ってインストールする。

# pacman -S nginx

とりあえずバージョン確認。

nginx -v
nginx version: nginx/1.14.1

PHP/MariaDBのインストール

ついでにapcuも入れとく。

# pacman -S php php-fpm mariadb php-apcu

PHPの設定

実行ユーザーを統一するため、先ほど作成しておいたnginxユーザーに設定する。

/etc/php/php-fpm.d/www.conf
- user = http
+ user = nginx
- group = http
+ group = nginx
- ;listen.owner = http
+ listen.owner = nginx
- ;listen.group = http
+ listen.owner = nginx

ここではunixソケットで待ち受ける事にする為、ソケットのユーザーも変更しておく。

後はプラグインを有効にして推奨設定に合わせておく。ついでに文字化け対策も。

/etc/php/php.ini
[mbstring]
- ;mbstring.language = Japanese
+ mbstring.language = Japanese
- ;mbstring.internal_encoding =
+ mbstring.internal_encoding = UTF-8


- ;extension=mysqli
+ extension=mysqli
- ;extension=pdo_mysql
+ extension=pdo_mysql
- ;zend_extension=opcache
+ zend_extension=opcache
+ extension=apcu
- ;extension=gd
+ extension=gd

[opcache]
- ;opcache.memory_consumption=128
+ opcache.memory_consumption=128
- ;opcache.interned_strings_buffer=8
+ opcache.interned_strings_buffer=8
- ;opcache.max_accelerated_files=1000000
+ opcache.max_accelerated_files=4000
- ;opcache.revalidate_freq=1
+ opcache.revalidate_freq=1
+ opcache.fast_shutdown=1
- ;opcache.enable_cli=1
+ opcache.enable_cli=1
# systemctl start php-fpm
# systemctl enable php-fpm

エラーが出なければOK。

MariaDBの設定

まずは文字化け対策。

/etc/mysql/my.cnf
[mysqld]
+ character-set-server=utf8

起動する前にこのコマンドを実行。忘れて何度も泣きを見た。

# mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

終わったら起動。エラーが出たら多分上のコマンド忘れてる。pacman -Rs mariadbして再起動してからインストールし直したらなんとかなるはず。

# systemctl start mariadb
# ststemctl enable mariadb

初期設定。testとかanounymousはいらないので削除。

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):(Enter)
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] (Enter)
New password: (rootパスワードを入力)
Re-enter new password: (再入力)

後は全部Enter。やってることはanonymousユーザーの削除と遠隔からのrootログインの禁止、testデータベースの削除。最後にデータベースをリロードして終わり。

データベースの作成

名前は適当にwpとする。

# mysql -u root -p
Enter password: (パスワード)
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.1.37-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wp;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;

こんな感じに表示されたら終わり。

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wp                 |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> exit

WordPressの導入

テスト環境なのでhomeディレクトリにどっしり構えてもらう。

cd ~/
curl -O https://ja.wordpress.org/wordpress-4.9.8-ja.tar.gz

tar -xvf wordpress-4.9.8-ja.tar.gz
sudo chown -R nginx:nginx wordpress/

ついでにapcuも入れとく。unzipしようとしたらunzipがなかった。

cd ~/
curl -O https://downloads.wordpress.org/plugin/apcu.1.0.3.zip
# pacman -S unzip

unzip apcu.1.0.3.zip
sudo -u nginx cp apcu/object-cache.php wordpress/wp-content/

nginxの設定

流石に長過ぎるのでここでは控える。基本的に参考にさせて頂いたサイトから拝借して適宜書き換えてる。

起動

念のため文法チェック

# nginx -t

エラーがなければ起動。

# systemctl start nginx
# systemctl enable nginx

vagrantipアドレスにアクセスして初期設定の画面が出たら終わり。後は手順に沿ってインストールを終わらせる。

感想

大人しくCentOSを使っておけばもう少し楽だったかも。しかしArchでやることに意義があると考えて後悔はしないことにする。

参考にさせて頂いたサイト様