centOS-stream8にphpMyAdminをインストール

apacheのインストール

以前セットアップした記事の内容そのままですが、一応書いておきます。

apache(httpd)インストール

apache用ユーザーの作成とapacheインストールを行います。自動起動設定等も行います。

[root@server hoge]# useradd -s /sbin/nologin www
[root@server hoge]# passwd www
ユーザー www のパスワードを変更。
新しいパスワード:
新しいパスワードを再入力してください:
passwd: すべての認証トークンが正しく更新できました。
[root@server hoge]# cat /etc/passwd | grep www
www:x:1001:1001::/home/www:/sbin/nologin
[root@server hoge]# dnf list | grep httpd
centos-logos-httpd.noarch                              82.0-2.el8                                        @appstream
httpd.x86_64                                           2.4.37-30.module_el8.3.0+462+ba287492.0.1         @appstream
httpd-filesystem.noarch                                2.4.37-30.module_el8.3.0+462+ba287492.0.1         @appstream
httpd-tools.x86_64                                     2.4.37-30.module_el8.3.0+462+ba287492.0.1         @appstream
httpd-devel.x86_64                                     2.4.37-30.module_el8.3.0+462+ba287492.0.1         appstream
httpd-manual.noarch                                    2.4.37-30.module_el8.3.0+462+ba287492.0.1         appstream
keycloak-httpd-client-install.noarch                   1.0-2.el8                                         appstream
libmicrohttpd.i686                                     1:0.9.59-2.el8                                    baseos
libmicrohttpd.x86_64                                   1:0.9.59-2.el8                                    baseos
python3-keycloak-httpd-client-install.noarch           1.0-2.el8                                         appstream
[root@server hoge]# dnf -y install httpd httpd-tools httpd-devel httpd-manual
 ...//色々出てきますが省略//
完了しました!
[root@server hoge]# dnf list installed | grep httpd
centos-logos-httpd.noarch            82.0-2.el8                                @appstream
httpd.x86_64                         2.4.37-30.module_el8.3.0+462+ba287492.0.1 @appstream
httpd-devel.x86_64                   2.4.37-30.module_el8.3.0+462+ba287492.0.1 @appstream
httpd-filesystem.noarch              2.4.37-30.module_el8.3.0+462+ba287492.0.1 @appstream
httpd-manual.noarch                  2.4.37-30.module_el8.3.0+462+ba287492.0.1 @appstream
httpd-tools.x86_64                   2.4.37-30.module_el8.3.0+462+ba287492.0.1 @appstream
[root@server hoge]# which httpd
/usr/sbin/httpd
[root@server hoge]# systemctl start httpd
[root@server hoge]# systemctl status httpd

firewallの設定変更

publicゾーンにhttpdサービスを追加します。

[root@server hoge]# firewall-cmd --add-service=http --zone=public --permanent
[root@server hoge]# firewall-cmd --add-service=http --zone=home --permanent
[root@server hoge]# firewall-cmd --reload

httpd.confの設定変更

[root@server hoge]# cd /etc/httpd/conf
[root@server conf]# ls
httpd.conf  magic
[root@server conf]# cp -p httpd.conf httpd.conf.org
[root@server conf]# ls
httpd.conf  httpd.conf.org  magic
[root@server conf]# vim httpd.conf

以下、変更内容

...
User www    #変更69行目(変更前:User apache)
Group www    #変更70行目(変更前:Group apache)
...
ServerAdmin webmaster.[任意のドメイン]    #変更98行目(変更前:ServerAdmin root@localhost)
...
ServerName web.[任意のドメイン]:80    #変更98行目(変更前:ServerName www.example.com:80)
...
DocumentRoot "/home/www/html"    #変更122行目(変更前:DocumentRoot "/var/www/html")
...
<Directory "/home/www">    #変更127行目(変更前:<Directory "/var/www">)
...
<Directory "/home/www/html">    #変更134行目(変更前:<Directory "/var/www/html">)
...
Options FollowSymLinks    #変更147行目(変更前:Options Indexes FollowSymLinks)
...
    ScriptAlias /cgi-bin/ "/home/www/cgi-bin/"    #変更250行目(変更前:ScriptAlias /cgi-bin/ "/var/www/cgi-bin/")
...
<Directory "/home/www/cgi-bin">    #変更258行目(変更前:<Directory "/var/www/cgi-bin">)
...

ドキュメントディレクトリの作成

.htmlあるいは.php等を保存するためのドキュメントディレクトリを作成しておきます。ディレクトリの所有者はwwwに設定しておき、パーミッションは"755"とします。

[root@server conf]# cd /home/www
[root@server www]# mkdir html
[root@server www]# mkdir cgi-bin
[root@server www]# chown www:www html
[root@server www]# chown www:www cgi-bin
[root@server www]# chmod 755 ./html
[root@server www]# chmod 755 ./cgi-bin
[root@server www]# cd ~
[root@server www]# systemctl restart httpd

SElinuxのcontext設定

SElinux有効の場合は必要な作業です。

[root@server hoge]# semanage fcontext -d -t user_home_t /home/www/html    //contextの初期化が必要な場合
[root@server hoge]# semanage fcontext -a -t httpd_sys_content_t /home/www/html
[root@server hoge]# restorecon -v /home/www/html
Relabeled /home/www/html from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0
[root@server hoge]# semanage fcontext -d -t user_home_t /home/www/cgi-bin    //contextの初期化が必要な場合
[root@server hoge]# semanage fcontext -a -t httpd_sys_script_exec_t /home/www/cgi-bin
[root@server hoge]# restorecon -v /home/www/cgi-bin
Relabeled /home/www/cgi-bin from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_script_exec_t:s0
[root@server hoge]# ls -Z /home/www
unconfined_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin      unconfined_u:object_r:httpd_sys_content_t:s0 html

以上でcontext設定が完了しました。context設定は手動で変更しない限り上位ディレクトリの設定が引き継がれます。

PHPのインストールとセットアップ

こちらも以前の記事と同様の内容ですが、一応書いておきます。

インストール

[root@server hoge]# dnf search php
##色々出てきますが省略します##
[root@server hoge]# dnf info php php-mbstring php-xml php-xmlrpc php-gd php-pdo php-mysqlnd php-json
##パッケージ確認。色々出てきますが省略します##
[root@server hoge]# dnf install -y php php-mbstring php-xml php-xmlrpc php-gd php-pdo php-mysqlnd php-json
##インストール。色々出てきますが省略します##
[root@server hoge]# php -v
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
[root@server hoge]# dnf list installed | grep php-fpm
php-fpm.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 @appstream

php-fpm設定ファイルの変更

[root@server hoge]# cp -p /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.org    #初期設定をコピー
[root@server hoge]# ls /etc/php-fpm.d/    #無事コピーしたのを確認
www.conf  www.conf.org
[root@server hoge]# vim /etc/php-fpm.d/www.conf    #php-fpmの設定変更

/etc/php-fpm.d/www.confの変更内容

...
user = www    #24行目あたり(初期値user = apache)
...
group = www    #26行目あたり(初期値group = apache)
...
listen.owner = www    #48行目あたり(初期値;listen.owner = nobody)
listen.group = www    #49行目あたり(初期値;listen.group = nobody)
listen.mode = 0666    #50行目あたり(初期値;listen.mode = 0660)
...
pm.max_children = 25    #115行目あたり(コメントアウト削除)
...
pm.min_spare_servers = 10    #126行目あたり(初期値;pm.min_spare_servers = 5)
...
pm.max_spare_servers = 20    #131行目あたり(コメントアウト削除)
...
pm.max_requests = 500    #142行目あたり(コメントアウト削除)
...

今回は仮想サーバー上でリソースが少なめなので、値を調整しています。

php-fpmの自動起動設定

[root@server hoge]# systemctl start php-fpm
[root@server hoge]# systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.

php.iniの設定変更

[root@server hoge]# cp -p /etc/php.ini /etc/php.ini.org
[root@server hoge]# vim /etc/php.ini

/etc/php.iniの変更内容

...
expose_php = Off    #374行目あたり(初期値expose_php = On)
...
post_max_size = 256M    #672行目あたり(初期値post_max_size = 8M)
...
upload_max_filesize = 128M    #825行目あたり(初期値upload_max_filesize = 2M)
...
date.timezone = "Asia/Tokyo"    #902行目あたり(初期値;date.timezone =)
...
mbstring.language = Japanese    #1510行目あたり(コメントアウト削除)
...
mbstring.internal_encoding = UTF-8    #1517行目あたり(初期値;mbstring.internal_encoding =)
...
mbstring.http_input = UTF-8    #1524行目あたり(初期値;mbstring.http_input =)
...
mbstring.http_output = pass    #1534行目あたり(初期値;mbstring.http_output =)
...
mbstring.encoding_translation = On    #1542行目あたり(初期値;mbstring.encoding_translation =)
...
mbstring.detect_order = auto    #1547行目あたり(コメントアウト削除)
...
mbstring.substitute_character = none    #1552行目あたり(コメントアウト削除)

php-fpmとhttpdのリスタート

[root@server hoge]# systemctl restart php-fpm
[root@server hoge]# systemctl status php-fpm
[root@server hoge]# systemctl restart httpd

以上で設定完了です。

MariaDBのインストール

mariadb,mariadb-server,mariadb-develのインストール

インストールから起動、自動実行の設定までを行います。

[root@server hoge]# dnf install mariadb mariadb-server mariadb-devel
[root@server hoge]# systemctl start mariadb
[root@server hoge]# systemctl status mariadb
[root@server hoge]# systemctl enable mariadb

mysql_secure_installationの実行

mariaDBの管理者パスワード設定、匿名ユーザー削除、管理者のリモート接続禁止等を設定します。管理者パスワード以外は全て"y"選択みたいな感じです。

[root@server hoge]# 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:
Re-enter new 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!

mariadb-server.cnfの編集

[root@server hoge]# cp -p /etc/my.cnf.d/mariadb-server.cnf /etc/my.cnf.d/mariadb-server.cnf.original_bk
[root@server hoge]# vim /etc/my.cnf.d/mariadb-server.cnf

/etc/my.cnf.d/mariadb-server.cnfの変更内容

...
# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
character-set-server = utf8mb4
[client-mariadb]
default-character-set = utf8mb4
...

MariaDBの再起動

[root@server hoge]# systemctl restart mariadb

テストDBで動作確認

管理者ユーザーでmariaDBにアクセスして、テストDBの動作確認をします(********は設定した管理者パスワード)。

[root@server hoge]# mysql -uroot -p*********
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 48
Server version: 10.3.27-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 test_db;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test_db            |
+--------------------+
4 rows in set (0.000 sec)
MariaDB [(none)]> use test_db;
Database changed
MariaDB [test_db]> drop database test_db;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> quit

以上でMariaDBのセットアップと確認は完了です。

phpMyAdminのセットアップ

wgetコマンドのインストール

phpMyAdminをネットからインストールするためにwgetコマンドをインストールします。

[root@server html]# yum install wget
//省略//
...
インストール済み:
  wget-1.19.5-10.el8.x86_64

完了しました!

phpMyAdminのダウンロード

wgetコマンドを使用してphpMyAdminの最新版を入手します。zip形式で圧縮されているため、解凍も行います。

[root@server hoge]# cd /home/www/html
[root@server html]# wget https://files.phpmyadmin.net/phpMyAdmin/5.1.0/phpMyAdmin-5.1.0-all-languages.zip
--2021-05-23 04:11:30--  https://files.phpmyadmin.net/phpMyAdmin/5.1.0/phpMyAdmin-5.1.0-all-languages.zip
files.phpmyadmin.net (files.phpmyadmin.net) をDNSに問いあわせています... 2a02:6ea0:d300::8, 89.187.160.8
files.phpmyadmin.net (files.phpmyadmin.net)|2a02:6ea0:d300::8|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 15054188 (14M) [application/zip]
`phpMyAdmin-5.1.0-all-languages.zip' に保存中

phpMyAdmin-5.1.0-all-language 100%[==============================================>]  14.36M  8.77MB/s 時間 1.6s

2021-05-23 04:11:32 (8.77 MB/s) - `phpMyAdmin-5.1.0-all-languages.zip' へ保存完了 [15054188/15054188]
[root@server html]# unzip phpMyAdmin-5.1.0-all-languages.zip
Archive: phpMyAdmin-5.1.0-all-languages.zip
//省略//
...
[root@server html]# ls
index.html phpMyAdmin-5.1.0-all-languages phpMyAdmin-5.1.0-all-languages.zip

解凍したファイルをリネームします。また、ダウンロードした圧縮ファイルも削除しておきます。

[root@server html]# mv phpMyAdmin-5.1.0-all-languages phpmyadmin
[root@server html]# ls
index.html  phpMyAdmin-5.1.0-all-languages.zip  phpmyadmin
[root@server html]# rm -rf phpMyAdmin-5.1.0-all-languages.zip
[root@server html]# ls
index.html  phpmyadmin  phpstatus.php

phpMyAdmin設定ファイルの編集

解凍したphpmyadminの中にサンプル設定ファイルがあるため、それをコピーして設定ファイルを作成します。

[root@server html]# ls
index.html  phpmyadmin
[root@server html]# cd phpmyadmin
[root@server phpmyadmin]# ls
CONTRIBUTING.md     babel.config.json      examples     locale        show_config_errors.php  vendor
ChangeLog           composer.json          favicon.ico  package.json  sql                     yarn.lock
LICENSE             composer.lock          index.php    print.css     templates
README              config.sample.inc.php  js           robots.txt    themes
RELEASE-DATE-5.1.0  doc                    libraries    setup         url.php
[root@server phpmyadmin]# cp config.sample.inc.php ./config.inc.php
[root@server phpmyadmin]# ls
CONTRIBUTING.md     babel.config.json      doc          libraries     setup                   url.php
ChangeLog           composer.json          examples     locale        show_config_errors.php  vendor
LICENSE             composer.lock          favicon.ico  package.json  sql                     yarn.lock
README              config.inc.php         index.php    print.css     templates
RELEASE-DATE-5.1.0  config.sample.inc.php  js           robots.txt    themes

phpmyadminフォルダのユーザーを変更します。

[root@server phpmyadmin]# cd ..
[root@server html]# ls -l
合計 12
-rw-r--r--.  1 root root   20  5月 16 07:31 index.html
drwxr-xr-x. 12 root root 4096  5月 23 04:17 phpmyadmin
[root@server html]# chown -R www:www phpmyadmin
[root@server html]# ls -l
合計 12
-rw-r--r--.  1 root  root    20  5月 16 07:31 index.html
drwxr-xr-x. 12 wwwys wwwys 4096  5月 23 04:17 phpmyadmin

/etc/httpd/conf.d内にphpmyadmin.confを作成

[root@server html]# cd /etc/httpd/conf.d
[root@server conf.d]# vim phpmyadmin.conf

phpmyadmin.confの内容

## VirtualHost sv-neptune.db
<VirtualHost *:80>
ServerName [SeverName].[Domain]
ServerAlias www.[Domain]
ServerAdmin www@[Domain]
DocumentRoot "/home/wwwys/html/phpmyadmin"

<Directory "/home/www/html/phpmyadmin">
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>

ErrorLog logs/phpmyadmin-error_log
CustomLog logs/phpmyadmin-access_log combined
</VirtualHost>

次に/etc/httpd/conf.dの設定内容を確認し、httpdを再起動します。

[root@server conf.d]# httpd -t
Syntax OK
[root@server conf.d]# systemctl restart httpd

ここで、サーバーにアクセスしてみると、パーミッションエラーが出ます。なので追加でセッションファイルのユーザー変更を行います。

[root@server conf.d]# cd /var/lib/php/
[root@server php]# ls -l
合計 0
drwxrwx---. 2 root apache 6  5月  6  2020 opcache
drwxr-xr-x. 2 root root   6  5月  6  2020 peclxml
drwxrwx---. 2 root apache 6  5月  6  2020 session
drwxrwx---. 2 root apache 6  5月  6  2020 wsdlcache
[root@server php]# chown www:www session

以上で設定完了です。ブラウザで"http://[サーバーIP]"にアクセスして、phpMyAdminログインページにアクセス出来ればOKです。

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

two × one =