1
1

More than 3 years have passed since last update.

UMINサーバー に WordPress を導入する

Last updated at Posted at 2020-10-31

UMINサーバー に WordPress を導入する

以前(数年前)、UMINサーバーへのMySQL導入について記事にしたことがあったのですが、色々いじっていたら動かなくなってしまい、しばらく放置していました。

これまで、UMINサーバーへWordPressを導入することは度々あり、現在ここ以外に3つのWordPressサイトを立ち上げています。これまでの内容も踏まえて覚書として記録しておきます。この記事を参考にされる場合は、あくまで自己責任でお願いいたします。

SSHで接続

(Macなら)Terminal でSSH接続。Windowsであれば TeraTermWindows Terminal を使用してください。

ssh {account}@plaza.umin.ac.jp

{account} は各自のアカウントIDを入力して下さい。

{account}@plaza.umin.ac.jp's password:

と尋ねられるので、開設通知書にかかれているパスワードを入力。

Last login: Wed Oct 14 04:16:26 2020 from 114.171.105.111

とログインできます。

.htaccess、.my.cnfの作成

/home/{account}/ 直下に .htaccess を作成。ローカルでエディタソフトで .htaccess を作成して、アップロードする方法もありますが、今回は vim で統一します。vimの使い方については、ターミナル上で、

vimtutor

と入力してみてください。

.htaccessの作成

cd /home/{account}/
touch .htaccess
vim .htaccess

i を押して、インサートモードへ。下記を入力します。

# .htaccess

php_value mysql.default_port {port}
php_value mysql.default_socket /home/{account}/tmp/mysql.sock

{port} は、下記を参考にしながら1025番以降で現在使われていないポート番号を入力してください。入力が終わったら、Esc でインサートモードを終了し、:wp を入力して保存・終了してください。

PLAZAサーバは、ユーザー側でデータベースをインストールして利用することができます。但し、RPM等の管理者権限を必要とする方法でのインストールはできませんので、 データベースをソースファイルからコンパイルしていただくことになります。 又、標準ポート(例:MySQLの場合は3306番)はUMIN側で予約しておりますので、 ポート番号1025番以降で空いているポートを割り当ててご利用下さい。
【コマンド】 netstat -nat | grep LISTEN | awk '{print $4}'
使用中のポート番号をご確認いただけます。
https://www.umin.ac.jp/faq/hp/

.my.cnfの作成

/home/{account}/ 直下に .my.cnf を作成。

# /home/{account}/ 

touch .my.cnf
vim .my.cnf
# .my.cnf

[client]
port={port}
socket= /home/{account}/tmp/mysql.sock
[mysqld]
explicit_defaults_for_timestamp = 1
port={port}
socket= /home/{account}/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M
pid-file=/home/{account}/tmp/mysql.pid
socket = /home/{account}/tmp/mysql.sock
datadir= /home/{account}/tmp/mysql_data/
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
[mysqldump]
quick
[mysqld_safe]
log-error=/home/{account}/tmp/mysql_data/log/mysqld.log
pid-file=/home/{account}/tmp/mysql_data/mysqld/mysqld.pid

[mysqld]explicit_defaults_for_timestamp = 1 はMySQL 5.7 以降は入力しておいたほうが良さそうです(入れておかないと--initialize-insecure の際にエラーがでます。)。

datadirの設置

ここで記載している /home/{account}/tmp/mysql_data/ のフォルダを作成しておきます。

# /home/{account}/ 

mkdir tmp
mkdir tmp/mysql_data

/home/{account}/tmp/mysql_data/ の中には何もデータを入れないようにしておいてください。

boost の準備

MySQLをインストールする際に boost が必要になるので設置。

今回は、/home/{account}/public_html/usr/local/src というフォルダをつくって、そこにboostを置きます。

# /home/{account}/

cd public_html
mkdir usr
mkdir usr/local
mkdir usr/local/src
cd usr/local/src

/home/{account}/public_html/usr/local/src で、boost の解凍(boost 1.50.0)

# /home/{account}/public_html/usr/local/src 

wget http://sourceforge.net/projects/boost/files/boost/1.50.0/boost_1_50_0.tar.gz
tar zxvf boost_1_50_0.tar.gz

MySQLのソースインストール

最新版のMySQLだと cmake3 が必要と怒られてしまうので、今回はMySQL 5.7 を使用します。

# /home/{account}/public_html/usr/local/src 

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26.tar.gz
tar xvfz mysql-5.7.26.tar.gz
cd mysql-5.7.26
mkdir build
cd build
cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/home/{account}/public_html/usr/local/src/boost_1_67_0/boost -DCMAKE_INSTALL_PREFIX=/home/{account}/public_html/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make
make install

makemake install でそれぞれ 3o分〜1時間弱は時間がかかります。

MySQLの初期化

MySQL 5.7 から --initialize-insecure で初期化するようになったようです。

/home/{account}/public_html/usr/local/mysql/bin/mysqld --initialize-insecure

ここで

[Warning]TIMESTAMP with implicit DEFAULT value is deprecated.Please use --explicit_defaults_for_timestamp server option(see documentation for more details).

のようなエラー表示が出る場合は、.my.cnf[mysqld] explicit_defaults_for_timestamp = 1 が記載されているか確認してください。

[ERROR] --initialize specified but the data directory has files in it. Aborting.

のようなエラー表示が出る場合は、

/home/{account}/tmp/mysql_data/ の中が空になっていることを確認してください。

問題なければ下記のような表示が出ます。

2020-10-13T08:52:01.376346Z 0
[Warning] Changed limits: max_open_files: 1024 (requested 5000)
2020-10-13T08:52:01.376437Z 0
[Warning] Changed limits: table_open_cache: 431 (requested 2000)
2020-10-13T08:52:01.572774Z 0
[Warning] InnoDB: New log files created, LSN=45790
2020-10-13T08:52:01.598074Z 0
[Warning] InnoDB: Creating foreign key constraint system tables.
2020-10-13T08:52:01.651137Z 0
[Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5c35a8ff-0d31-11eb-8873-f48e38c521d8.
2020-10-13T08:52:01.651484Z 0
[Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2020-10-13T08:52:01.657115Z 1
[Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. 

MySQL サーバーの起動

/home/{account}/public_html/usr/local/mysql/support-files/mysql.server start

と入力すると

Starting MySQL. SUCCESS!

と表示されれば起動は成功です。

/home/{account}/public_html/usr/local/mysql/bin/mysql -u root -p

パスワードを求められますが、初期化に成功していれば、そのままエンターキーで先に進めることができます。次回以降はパスワードの設定が必要になるため、パスワードを設定しておきます。

set password='{password}';

{password} に任意のパスワードを入力してください。英語、数字、記号がそれぞれ含まれていないとエラーで返ってくることがあるため、注意してください。

一度 quit と入力して、MySQLを終了。その後、初期設定を行います。

/home/{account}/public_html/usr/local/mysql/bin/mysql_secure_installation

コロン(:)のあとの y / n がこちらが入力する部分です。この辺りは他の記事を参照してください。1

Securing the MySQL server deployment.

Enter password for user root: 

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup 

VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y
There are three levels of password validation policy:LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary filePlease enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n 
… skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database…
Success.

- Removing privileges on test database…

Success.Reloading the privilege tables will ensure that all changes made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

データベースの作成

再度MySQLを起動します。

/home/{account}/public_html/usr/local/mysql/bin/mysql -u root -p

ここで先程指定したパスワードを入力。(パスワードを忘れてしまったら、/home/{account}/tmp/mysql_data/ をもう一度空にしてから、再度初期化から手順を進めてください。)

# mysql>

create database {database_name};
create user '{user_name}'@'localhost' identified by '{password_2}';

{database_name}{user_name}{password_2} はそれぞれ任意のものを入力してください。{user_name} に権限を渡しておきます。

grant all privileges on  {database_name}.* to '{user_name}'@'localhost';

Word Press の設置

/home/{account}/public_html/ に移動し、WordPressをインストールします。

cd /home/{account}/public_html/
wget http://wordpress.org/latest.tar.gz
tar zxvf latest.tar.gz

hostname を確認し、メモしておいてください。({hostname}とします)

hostname -f

また、ここで実際のホームページをhttps://plaza.umin.ac.jp/{account}/wordpress/ではなくhttps://plaza.umin.ac.jp/{account}/wp/などにしたければ

# /home/{account}/public_html/

mv wordpress wp

と変更します。

https://plaza.umin.ac.jp/{account}/にしたければ、

# /home/{account}/public_html/

mv wordpress/* ./

として、https://plaza.umin.ac.jp/{account}/ 直下にフォルダ内のディレクトリをすべて移動します。(単純にhttps://plaza.umin.ac.jp/{account}/ にアクセスすればWordpressが表示されるようにしたければ、リダイレクトを設定するだけでも良いかもしれません。)

以下は、/home/{account}/public_html/wordpress のままで説明します。wp-config.php を作成。

# /home/{account}/public_html/wordpress

cp ./wp-config-sample.php ./wp-config.php
vim wp-config.php

i を押してインサートモードへ。

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '{database_name}');

/** MySQL database username */
define('DB_USER', '{user_name}');

/** MySQL database password */
define('DB_PASSWORD', '{password_2}');

/** MySQL hostname */
define('DB_HOST', '[hostname]:[port]');

と記載します。以下は追記すると、あとの設定が楽になりますが、なくても大丈夫です。2

define('FTP_HOST', 'plaza.umin.ac.jp');
define('FTP_USER', '**');
define('WPLANG','ja');

ページ下部にセキュリティキーを入力する画面が出てきます。
https://api.wordpress.org/secret-key/1.1/salt/
にアクセスして出てきた内容を上書きしてください。3

入力が完了したら Esc を押してインサートモードを終了。 :wq で保存、終了してください。

ここまでくると、ブラウザで、https://plaza.umin.ac.jp/{account}/wordpress/ にアクセスすると、設定画面が開きます。あとは必要事項を入力して起動して下さい。

.htaccessの設定

/home/{account}/public_html/wordpress の場所に .htaccess を新しく設置します。

# /home/{account}/public_html/wordpress

touch .htaccess
vim .htaccess 
# .htaccess

php_value mysql.default_port {port}
php_value mysql.default_socket /home/{account}/tmp/my_mysql.sock# BEGIN WordPress
RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress

パーミッションの設定

WordPressのパーミッションの設定は、色々な記事があるため、詳細は省きます。4 ただ、wp-config.php を「400」や「600」にすると、記事が表示されない場合があるかもしれないので注意してください。今回は、ストレージに写真をアップロードできるように設定をします。

# /home/{account}/public_html/wordpress

chmod -R 707 wp-content

Crontabの設定

UMINサーバーのメンテナンス後にMySQLが再起動しないことがあります。そのため、/home/{account}/etc/cron.txt を作成し、crontab に設定しておきます。

mkdir /home/{account}/etc/
cd /home/{account}/etc/
touch cron.txt
vim cron.txt
# cron.txt

@reboot /home/{account}/public_html/usr/local/mysql/support-files/mysql.server start
@reboot /home/{account}/public_html/usr/local/mysql/bin/mysqld_safe &

crontab へ設定。

crontab /home/{account}/etc/cron.txt

私が管理しているWordPressは、今の所この設定でうまく行っているようです。もし、UMINサーバーのメンテナンス後に「データベースに接続できません」といったエラーが出る場合は、手動で、

/home/{account}/public_html/usr/local/mysql/support-files/mysql.server start

もしくは、

/home/{account}/public_html/usr/local/mysql/bin/mysqld_safe &

を試してみてください。

リダイレクトの設定

https://plaza.umin.ac.jp/{account}/ 直下にwordpressを設定している方はこのページは読み飛ばしてください。https://plaza.umin.ac.jp/{account}/wordpress/ 直下にWordpressを入れている方が対象です。

https://plaza.umin.ac.jp/{account}/ にアクセスすると、 https://plaza.umin.ac.jp/{account}/wordpress/ に自動的にジャンプするようにリダイレクトを php で設定します。

# /home/{account}/public_html/

touch index.php
vim index.php

i を押して、インサートモードへ。index.php は以下のように設定します。

# index.php

<?php

header('Location:https://plaza.umin.ac.jp/{account}/wordpress/');

exit;
?>

Esc を押して、インサートモードを終了。 :wqvim を保存&終了。

これで、https://plaza.umin.ac.jp/{account}/ にアクセスすると、自動的にhttps://plaza.umin.ac.jp/{account}/index.php にジャンブし、その後リダイレクトで https://plaza.umin.ac.jp/{account}/wordpress/ にジャンプするようになりました。

言葉足らずのところもあると思いますが、参考になれば幸いです。この記事を参考にされる場合は、あくまで自己責任でお願いいたします。

1
1
0

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
1
1