Webサイト構築・運用

VPSサーバ構築3

PHPAdminとデータベースの導入

MariaDBのインストール

次のように入力。

# yum install mariadb-server

インストールの有無を聞かれるのでyを入力してEnterを押下する。

MariaDBインストール

 

completeと表示されれば完了する。

MariaDBインストール

 

MariaDBの起動

# systemctl enable mariadb

# systemctl start mariadb

MariaDB instration

MariaDBのパスワード設定

# mysql_secure_installation

途中以下のようなところで止まるがそのままEnter。

Enter currene password for root (enter for none):

MariaDBインストール

 

パスワードを設定するかを聞かれるのでYを押下してEnter.

MariaDBインストール

 

管理者ユーザrootのパスワードの設定の有無を聞かれるのでYを押下してNew password:の後にパスワードを設定入力する。
そのあとにRemove anonymous user? [Y/n]と聞かれるのでYでEnter。

MariaDBインストール

 

Remove test database and access to it? [Y/n]でYでEnter。

MariaDBインストール

 

Reloading the privilege tables will ensure that all change made so far will take effect immidiately.

 

Reload privilege tables now? [Y/n]

と聞かれるのでYでEnter。

MariaDBインストール

 

完了すれば以下のようなメッセージが出る。

MariaDBインストール

 

パスワードを入力してEnter。

MariaDBインストール

 

show databases;と入力すれば以下3つのデータベーステーブルが表示される。

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+

 

MariaDBインストール

phpMyAdminのインストール

インストールしたMariaDBを操作するためにphpMyadminのインストールを行う。

 

# yum install --enablerepo=remi,remi-php74 phpMyAdmin

 

Yを入力してEnter。

phpMyAdmin installation

 

以下のようにCompleteと表示されれば完了。

phpMyAdmin installation

 

phpMyAdminのコンフィグ操作

phpMyAdminファイルの設定を変更する。
次のようにフォルダ移動してphpMyAdmin.confのコピーをバックアップしてから次のようにRequire localとなっているところの先頭行に#を入力してコメントアウトしてその下にRequire all grantedと入力する。

[root@〜〜〜〜〜〜 ~]# cd /etc/httpd/conf.d
[root@〜〜〜〜〜〜 conf.d]# cp phpMyAdmin.conf phpMyAdmin.conf.old
[root@〜〜〜〜〜〜 conf.d]# vim phpMyAdmin.conf

 

# phpMyAdmin - Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

 

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

 

AddDefaultCharset UTF-8
SSLRequireSSL
#Require local
Require all granted

 

Require local

 

# These directories do not require access over HTTP - taken from the original

phpMyAdmin installation

localのみに使用するようになっているのですべてのアクセスを可能にするために上記のようにファイル内を書き換えている。

書き換えが終わったらwq:で保存してhttpdを起動させる。

# systemctl restart httpd

 

次のように

http://xxx.xxx.xxx.xxx/phpmyadmin

へ入ってリロードして次のような画面が表示されていれば成功になる。

phpmyadminインストール

 

URLの変更

上記のphpmyadminだと推測されやすいのでエイリアス設定を変更する。
再度phpMyAdmin.confファイルへ入っていき次のような箇所、

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

 

をコメントアウトしてphpMyAdminのあとに推測されにくいテキストxxxxx(←は適当なアルファベットの文字列)を入力して保存する。

#Alias /phpMyAdmin /usr/share/phpMyAdmin
#Alias /phpmyadmin /usr/share/phpMyAdmin
Alias /phpMyAdminxxxxx /usr/share/phpMyAdmin

 

phpMyAdmin installation

 

上記設定が終わったら次のようにしてhttpdを再起動させる。

# systemctl restart httpd

 

再度phpMyAdminではなくphpMyAdminxxxxxを入力してEnterを押下すれば先ほどのphpMyAdminの表示される。

phpadminのhttps化

httpではなくhttpsでアクセスさせるためsslのインストールを行う。
次のように管理者権限で入力。

# yum install mod_ssl

httpdを再起動(systemctl restart httpd)させる。
アドレスバーでhttp://xxx.xxx.xxx.xxx/phpmyadmin だったのを今度はhttps://xxx.xxx.xxx.xxx/phpmyadminxxxxx で接続をする。

 

次のように表示されるが危険性を承知で続行を押下すればphpMyAdminへ接続ができるようになる。

phpMyAdmin installation

 

httpアクセスの停止

httpでのアクセスを停止する。
httpdのconf.dファイルへ移動。

# cd /etc/httpd/conf.d/

 

vimでファイルを編集するので以下のように入力。

# vim phpMyAdmin.conf

 

次のように追記入力する(太字の部分を追記する)。

<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
SSLRequireSSL
#Require local
Require all granted
</Directory>

phpMyAdmin installation

phpMyAdminのバージョンアップ

定期的に以下を確認するようにすること。

remiのリストを取得

# yum check-update --enablerepo=remi

PHP varsion chech

 

phpmyadminのバージョンの情報

# yum info --enablerepo=remi phpMyAdmin

[root@〜〜〜〜〜 ~]# yum info --enablerepo=remi phpMyAdmin
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp-srv2.kddilabs.jp
* epel: ftp.iij.ad.jp
* extras: ftp-srv2.kddilabs.jp
* remi: cdn.centos.no
* remi-safe: cdn.centos.no
* updates: ftp-srv2.kddilabs.jp
Installed Packages
Name : phpMyAdmin
Arch : noarch
Version : 5.2.1
Release : 1.el7.remi
Size : 47 M
Repo : installed
From repo : remi
Summary : A web interface for MySQL and MariaDB
URL : https://www.phpmyadmin.net/
License : GPL-2.0-or-later AND MIT AND BSD 2-Clause AND BSD 3-Clause AND
: LGPL-3.0-or-later AND MPL-2.0 AND ISC
Description : phpMyAdmin is a tool written in PHP intended to handle the
: administration of MySQL over the Web. Currently it can create and
: drop databases, create/drop/alter tables, delete/edit/add fields,
: execute any SQL statement, manage keys on fields, manage
: privileges,export data into various formats and is available in 50
: languages

PHP varsion chech

 

新しいバージョンがあれば次のようにしてアップデートする。

# yum update --enablerepo=remi phpMyAdmin

SSL証明書のインストール

今から四半世紀前まではhttpが大半だったが現在ではhttpsが主流になっている。理由はワイアシャークなどで簡単にパスワードなどの情報が閲覧できるため。
なので常時SSLをインストールする。

 

httpsの確認

# firewall-cmd --list-all

firewall chech

 

Lets’Encryptのインストール。

# yum install certbot python2-certbot-apache

 

今回取得したドメインがdiff-eq.comなので次のように入力してEnter

# certbot --apache -d diff-eq.com

 

Emailを入力して規約に同意、ssl.confを選択してhttpをhttpsにリダイレクトにする。

 

再起動をする。

# system restart httpd

ドメインの取得

今回取得した新規ドメインはdiff-eq.com
以下のように入力。

# certbot --apache -d diff-eq.com

上記diff-eq.comの部分はそれぞれ取得したドメインを入れる。

 

今回取得したドメインSSLを発行しようとしたところ次のようなエラーメッセージが出る。

[root@i〜〜〜〜〜〜 ~]# certbot --apache -d diff-eq.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Requesting a certificate for diff-eq.com
Performing the following challenges:
http-01 challenge for diff-eq.com
Cleaning up challenges
Unable to find a virtual host listening on port 80 which is currently needed for Certbot to prove to the CA that you control your domain. Please add a virtual host for port 80.

最後の一文はポート80に仮想ホストを追加してくださいということらしい。

なのでhttpd.confファイルの編集を行うので次のように入力。

# vim /etc/httpd/conf/httpd.conf

最後のほうに行って以下のテキストを追加入力する。

<VirtualHost *:80>
ServerAdmin root@diff-eq.com
DocumentRoot /var/www/html
ServerName diff-eq.com
</VirtualHost>

上記のdiff-eq.comの部分はそれぞれ取得したドメインに変更して行う。

 

保存して再度certbot〜を入力して以下のようにCongratulations!〜と表示されれば完了になる。

[root@〜〜〜〜〜〜 ~]# certbot --apache -d diff-eq.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Requesting a certificate for diff-eq.com
Performing the following challenges:
http-01 challenge for diff-eq.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/httpd/conf/httpd-le-ssl.conf
Deploying Certificate to VirtualHost /etc/httpd/conf/httpd-le-ssl.conf
Enabling site /etc/httpd/conf/httpd-le-ssl.conf by adding Include to root configuration
Redirecting vhost in /etc/httpd/conf/httpd.conf to ssl vhost in /etc/httpd/conf/httpd-le-ssl.conf

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://diff-eq.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Subscribe to the EFF mailing list (email: ***************@gmail.com).
Starting new HTTPS connection (1): supporters.eff.org

 

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/diff-eq.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/diff-eq.com/privkey.pem
Your certificate will expire on 2023-08-03. To obtain a new or
tweaked version of this certificate in the future, simply run
certbot again with the "certonly" option. To non-interactively
renew *all* of your certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:

 

Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

 

certbot error


VPSサーバ構築3関連ページ

Wordpressカテゴリ作成と投稿の配置方法
Webサイト運用におけるサーバ構築やHTML,CSSなどの気づいた点などの管理人用の備忘録的な内容になっています。このエントリーではデフォルトで表示されるcategoryの削除の方法と新規で作成したカテゴリの配置と投稿記事の該当カテゴリへの子分類としての配置方法などについて解説していきます。
VPSサーバ構築4
Webサイト構築におけるサーバ構築やHTML,CSSなどの気づいた点や管理人用の備忘録的な内容になっていますので、その辺のところ何卒よろしくお願いしまスミダ。
VPSサーバ構築2
Webサイト構築におけるサーバ構築やHTML,CSSなどの気づいた点などの管理人用の備忘録的な内容になっています。その辺のところ何卒よろしくお願いしまスミダ。
VPSサーバ構築1
Webサイト構築におけるサーバ構築やHTML,CSSなどの気づいた点などの管理人用の備忘録的な内容になっていますので、その辺のところ何卒よろしくおながいしまスミダ<`ω´>。

ホーム RSS購読 サイトマップ
TOP 線形代数 ベクトル解析 慣性モーメント 解析力学 微分方程式 NEへの道しるべ