はじめに
CentOS7でwordpress環境を構築 -サーバの初期セットアップ編- にて、サーバの初期セットアップが済んだのでwordpressを動かす為に必要なソフトウェアのインストールやセットアップを行います。
また、スクリプト言語であるPHPと関連パッケージのインストールもまとめて行います。
Apacheのインストールとセットアップ
Apacheのインストール
$ sudo yum -y install httpd
<<<略>>>
Complete!
Apacheの設定ファイルを開く
viで設定ファイルを開いて編集していきます。
$ sudo vi /etc/httpd/conf/httpd.conf
#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
# for a discussion of each configuration directive.
#
<<<略>>>
ServerNameの編集
[/ServerName]と検索して下記のように編集してください。
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
# ServerName www.example.com:80 ← 先頭の[#]を消す
DerectoryIndexについて
ここは基本編集する必要はないのですが、一応説明しておきます。
下記の部分はサイトのURLをブラウザに入力する際に、ディレクトリ名が省略された場合に表示されるページを設定する箇所です。
要するに[ http://www.mrchildren.jp/index.html/ ]を[ http://www.mrchildren.jp/ ]と入力しても表示されるようにする設定です。
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html ← ココ
</IfModule>
Apacheの設定ファイルの編集は以上です。
最後に構文チェックの為のコマンドを実行して[ syntax OK ]と表示されるか確認しておいて下さい。
$ httpd -t
Syntax OK
よくわからないErrorが出た場合は大抵スペルミスや、必要以上にテキストを削除してしまっています。
Error Msgの中に[ line 100 ]のように何行目がおかしいか表示してくれているはずなので、それを頼りに確認してみてください。
Apacheの起動と自動起動の有効化
$ sudo systemctl start httpd
$ sudo systemctl enable httpd
ステータスを見るときは下記を実行して下さい。
色々表示されますがLoadedのところがenabled、Activeがactive (running)と表示されればOKです。
$ systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since 火 2019-04-30 00:05:24 JST; 25s ago
///
Firewallへのアクセス許可設定
$ sudo firewall-cmd --permanent --add-service=http
success
& sudo firewall-cmd --reload
success
これで自分のVPSのIPアドレスをブラウザで叩けばApacheのテストページが表示されるはずです。
ドキュメントルートが空の場合はテストページが表示される仕様になっています。
試しに /var/www/html/ の配下に簡単なhtmlファイルを置いてみるのもよいと思います。
PHPのインストール
PHPでMySQLとMariaDBを扱う為のパッケージ等もまとめてインストールします。
$ sudo yum -y install php php-mbstring php-gb php-mysql
Apache側でPHPが扱えるようにする為、Apacheを再起動します。
$ sudo systemctl restart httpd
MariaDBのインストールとセットアップ
MariaDBのインストール
$ sudo yum -y install mariadb-server mariadb
$ sudo vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8 ← ココを追加する
mariaDBの起動と自動起動の有効化
$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb
MariaDBの初期設定
MariaDB の場合は対話型の初期設定ツール secure_installation があります。
必要な設定を[y/n]で選択していくだけですので最高ですね。
$ sudo 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):
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] Y
New password: ← passwordを入力(MariaDB Administrator Password)
Re-enter new password: ← passwordを再入力
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] Y
... Success!
By default, MariaDB 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? [Y/n] 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? [Y/n] Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
wordpress用のDB作成
MariaDBを作成します。
最初に求められるパスワードは先程設定したMariaDBの管理者パスワードを入力して下さい。
その後に[database_name][database_user_name_][database_user_password]を任意の値に変えてコマンドを入力して下さい。
$ mysql -u root -p
Enter password: ← 先程設定したMariaDBのadministrator passwordを入力
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE database_name;
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON database_name.* TO "database_username"@"localhost" IDENTIFIED BY "database_user_password";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
次はいよいよwordpressのインストールです。
CentOS7でwordpress環境の構築 -Wordpressのセットアップ編- に進んで下さい。