※ CentOS7がサポート終了となったことを踏まえ、私は自宅サーバーを外部に公開せず、自宅内で閲覧できる、Webサーバーの構築方法をまとめることにしました。一般的な家庭内LANに設置するのであれば、便利に使えます。
※この方法は「FireWall」「SELINUX」その他のセキュリティソフトやセキュリティ対策を行うことは考えて書かれておりません。ご利用になる際はその点をご理解の上、ご自身の責任で行って下さい。当方では責任は取れません。
【Fedora Server 41のインストール】
●Windows11Proを用い、下記のサイトから、Fedora Server 41のNetwork Install用のisoファイルをダウンロードする。
https://fedoraproject.org/ja/server/download
●Fedora-Server-netinst-x86_64-41-1.4.iso ←最新版を使う。古いとうまくいかないことが多い。私の時はこれが最新版だった。
●ダウンロードしたisoファイルを新しいDVD-Rに焼く。
●出来上がった Fedora Server 41,x86_64用DVD-R からインストールする。
●家庭内LANにつないだ状態(ネットワーク経由のインストールができる状態)にしておく。
●2TBのHDD1枚 ←私のサーバーの仕様です。
●BIOSで、DVDからの起動を選択、再起動。
≪GRUB画面で≫
「Install Fedora 41」を選ぶ。
≪インストーラに従い、下記のように選択≫
○インストール時に使用する言語「日本語(日本)」
○キーボード:「日本語, English(US)」
○言語サポート:「日本語(日本)」
○ネットワーク設定:NIC「eno1」のIPv4を下記設定、IPv6を「無視する」
IPアドレス:「192.168.1.5」 ←自分のLAN内でのIPアドレスに読みかえて下さい。
ネットマスク:「255.255.255.0」
ゲートウェイ:「192.168.1.1」←自分のLAN内でのゲートウェイアドレスに読みかえて下さい。
DNS:「192.168.1.1」
ドメインを検索:「yourdomain.com」
ホスト名を「localhost.localdomain」から、「yourdomain.com」に変更。
○日付と時間:「アジア」「東京」「Network Time」
○インストールソース:「ローカルメディア」
○ソフトウェアの選択:
ベース環境:「BASICサーバー(GUI)」
選択した環境のアドオン:すべてチェックしない。
○インストール先:すべてのパーティションを削除し、「自動パーティション」
すべての領域を使用する。
○インストールを開始
○パスワード設定
root
ID:root
パスワード:password
パスワードによるrootSSHログインを許可
user
ID:user
パスワード:password
このユーザーを管理者権限を付与しない
パスワードを要求する
○「インストールの開始」を押す。
長時間待つ。
「システムの再起動」を押す。
○インストールDVD-Rを取り出す。
【Fedora 41 インストール後の設定】
≪ここから Windows10Pro 端末から teraterm(telnet) でリモートコントロール≫
●hostsファイルの編集
# vi /etc/hosts
## 2025.02.26(Wed) Changed ## ←いつのものか書いておくと良い。
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.1 gateway.localnet ##
192.168.1.05 yourdomain.com ## Linux Server
192.168.1.50 windows.localnet ## Windows 11 Pro
●SELinux (Security-Enhanced Linux)の設定変更(ここでは無効にする)
# grubby –update-kernel ALL –args selinux=0
# reboot ←再起動する
●Firewalld ←個人で適切な設定(ここでは無効)にして下さい。
# systemctl stop firewalld
# systemctl disable firewalld
に変更。再起動。
# reboot
●ネットワークの設定(要確認) ←デバイス名(eno1)は自分の物と読みかえて下さい。
# nmcli device
DEVICE TYPE STATE CONNECTION
eno1 ethernet 接続済み eno1
lo loopback 接続済み (外部) lo
# nmcli device show eno1
GENERAL.DEVICE: eno1
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:D8:61:A3:51:F7
GENERAL.MTU: 1500
GENERAL.STATE: 100 (接続済み)
GENERAL.CONNECTION: eno1
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2
WIRED-PROPERTIES.CARRIER: オン
IP4.ADDRESS[1]: 192.168.1.5/24
IP4.GATEWAY: 192.168.1.1
IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.1.1, mt = 100
IP4.ROUTE[2]: dst = 192.168.1.0/24, nh = 0.0.0.0, mt = 100
IP4.DNS[1]: 192.168.1.1
IP4.SEARCHES[1]: yourdomain.com
IP6.GATEWAY: —
【 DNS 設定】
●BINDの導入
# yum -y install bind bind-utils
○BINDの設定
○named.confを編集する。
# vi /etc/named.conf
//
// named.conf
//
// Provided by Red Hat bind package to cousergure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named couserguration files.
//
// See the BIND Administrator’s Reference Manual (ARM) for details about the
// couserguration located in /usr/share/doc/bind-{version}/Bv9ARM.html
options {
listen-on port 53 { any; };
listen-on-v6 { none; };
directory “/var/named”;
dump-file “/var/named/data/cache_dump.db”;
statistics-file “/var/named/data/named_stats.txt”;
memstatistics-file “/var/named/data/named_mem_stats.txt”;
recursing-file “/var/named/data/named.recursing”;
secroots-file “/var/named/data/named.secroots”;
allow-query { localhost; };
allow-transfer { localhost; };
/*
– If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
– If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
– If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file “/etc/named.iscdlv.key”;
managed-keys-directory “/var/named/dynamic”;
pid-file “/run/named/named.pid”;
session-keyfile “/run/named/session.key”;
};
logging {
channel default_debug {
file “data/named.run”;
severity dynamic;
};
};
view “internal” {
match-clients {
localhost;
192.168.1.5/24;
};
zone “.” IN {
type hint;
file “named.ca”;
};
zone “yourdomain.com” IN {
type master;
file “yourdomain.com.lan”;
allow-update { none; };
};
zone “1.168.192.in-addr.arpa” IN {
type master;
file “1.168.192.db”;
allow-update { none; };
};
include “/etc/named.rfc1912.zones”;
include “/etc/named.root.key”;
};
○内部向け正引き情報の設定ファイル作成
# vi /var/named/yourdomain.com.lan
$TTL 86400
@ IN SOA yourdomain.com. root.yourdomain.com. (
20250226 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
IN NS yourdomain.com.
IN A 192.168.1.5
IN MX 10 yourdomain.com.
www IN A 192.168.1.5
○内部向け逆引きの設定ファイル作成
# vi /var/named/1.168.192.db
$TTL 86400
@ IN SOA yourdomain.com. root.yourdomain.com. (
20250226 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
IN NS yourdomain.com.
5 IN PTR yourdomain.com.
○BIND の起動
# systemctl start named
# systemctl enable named
○正引きの確認
# dig yourdomain.com
; <<>> DiG 9.18.33 <<>> yourdomain.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50403
;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;yourdomain.com. IN A
;; ANSWER SECTION:
yourdomain.com. 0 IN A 192.168.1.5
;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Wed Feb 26 12:20:16 JST 2025
;; MSG SIZE rcvd: 55
○逆引きの確認
# dig -x 192.168.1.5
; <<>> DiG 9.18.33 <<>> -x 192.168.1.5
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53251
;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;5.1.168.192.in-addr.arpa. IN PTR
;; ANSWER SECTION:
5.1.168.192.in-addr.arpa. 0 IN PTR yourdomain.com.
5.1.168.192.in-addr.arpa. 0 IN PTR yourdomain.
5.1.168.192.in-addr.arpa. 0 IN PTR yourdomain.local.
;; Query time: 7 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Wed Feb 26 12:21:04 JST 2025
;; MSG SIZE rcvd: 123
【 FTP 設定】
●vsftpd の利用
# yum -y install vsftpd
○vsftpd.confを編集する。
# vi /etc/vsftpd/vsftpd.conf
# 12行目:匿名ログイン禁止
anonymous_enable=NO
# 82,83行目:コメント解除 ( アスキーモードでの転送を許可 )
ascii_upload_enable=YES
ascii_download_enable=YES
# 100,101行目:コメント解除 ( chroot有効 )
chroot_local_user=YES
chroot_list_enable=YES
# 103行目:コメント解除 ( chroot リストファイル指定 )
chroot_list_file=/etc/vsftpd/chroot_list
# 109行目:コメント解除 ( ディレクトリごと一括での転送有効 )
ls_recurse_enable=YES
# 114行目:変更 ( IPv4をリスンする )
listen=YES
# 123行目:変更 ( もし不要なら IPv6 はリスンしない )
listen_ipv6=NO
●FTPを使うユーザーを登録しておく
# vi /etc/vsftpd/chroot_list
root
user
●起動
# systemctl start vsftpd
# systemctl enable vsftpd
【送信メールサーバー 設定】
●postfixのインストール
# yum -y install postfix
●postfixの設定
○main.cfを編集する。
# vi /etc/postfix/main.cf
# 98行目:コメント解除しホスト名指定
myhostname = yourdomain.com
#myhostname = virtual.domain.tld
# 106行目:コメント解除しドメイン名指定
mydomain = yourdomain.com
# 122行目:コメント解除
myorigin = $mydomain
# 187行目:追記
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# 290行目:コメント解除し自ネットワーク追記
mynetworks = 168.100.189.0/28, 127.0.0.0/8, 192.168.1.0/24
# 447行目:コメント解除しMaildir形式へ移行
home_mailbox = Maildir/
# 602行目:追記
smtpd_banner = $myhostname ESMTP
##ADD## ←最終行に以下を加える
# for SMTP-Auth
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_auth_destination, permit_sasl_authenticated, reject
# 起動
# systemctl start postfix
# systemctl enable postfix
【受信メールサーバー 設定】
●dovecotのインストール
# yum -y install dovecot
●dovecotの設定
○設定ファイルの編集
# vi /etc/dovecot/dovecot.conf
# line 24: uncomment
protocols = imap pop3 lmtp submission
# line 30: uncomment and change ( if not use IPv6 )
listen = *
○設定ファイルの編集
# vi /etc/dovecot/conf.d/10-auth.conf
# line 10: uncomment and change ( allow plain text auth )
disable_plaintext_auth = no
# line 100: add
auth_mechanisms = plain login
○設定ファイルの編集
#vi /etc/dovecot/conf.d/10-mail.conf
# line 30: uncomment and add
mail_location = maildir:~/Maildir
○設定ファイルの編集
# vi /etc/dovecot/conf.d/10-master.conf
# line 110-114: uncomment and add
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix # add
group = postfix # add
}
○設定ファイルの編集
# vi /etc/dovecot/conf.d/10-ssl.conf
# line 8: change (not require SSL)
ssl = no
●起動
# systemctl start dovecot
# systemctl enable dovecot
【 WordPress 導入の前提条件】
● Apache2.4 と PHP8.0 と MariaDB10.8 が準備できた状態に WordPress の最新版をインストールします。
【 Apache httpd のインストール】
httpd -v コマンドでApache httpd のバージョン確認します。
# httpd -v
Server version: Apache/2.4.54 (IUS)
Server built: Jul 20 2022 23:47:24
新しいバージョンが入っているようです。
もしも、バージョンが古いようでしたら、一度、httpdをアンインストールしてみましょう。
httpd 停止・削除
# systemctl stop httpd
# yum remove httpd
# yum remove httpd-tools
入ってなければインストール
# yum -y install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
・・・略・・・
Complete!
httpd -v コマンドでApache httpd のバージョン確認します。
httpd -v
Server version: Apache/2.4.63 (Fedora Linux)
Server built: Jan 24 2025 00:00:00
設定します。
# vi /etc/httpd/conf/httpd.conf
# 91行目:管理者アドレス指定
ServerAdmin user@yourdomain.com
# 100行目:コメント解除しサーバー名指定
ServerName yourdomain.com:80
# 149行目
Options Indexes FollowSymLinks を
Options FollowSymLinks とする。
# 156行目:変更
AllowOverride All
# 164行目:ディレクトリ名のみでアクセスできるファイル名を追記
DirectoryIndex index.html index.cgi index.php
##ADD## 最終行に追記
ServerTokens Prod
KeepAlive On
再起動
# systemctl restart httpd
# systemctl enable httpd
(リモート)ブラウザで
http://yourdomain.com/
で、画面を確認。
【 PHP のインストール】
php -v コマンドで php のバージョン確認します。
# php -v
bash: php: command not found…
インストールします。
# dnf -y install php php-mbstring php-pear
確認します。
# php -v
PHP 8.3.17 (cli) (built: Feb 11 2025 22:03:03) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.3.17, Copyright (c) Zend Technologies
with Zend OPcache v8.3.17, Copyright (c), by Zend Technologies
これだけでは WordPressが 動かないので、php.ini を編集します。
※私はこの php.ini の編集を行わないでながいことエラーに悩んだ経験があります。
php.iniの場所を確認しましょう。
# php -i | grep php.ini
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
viエディタで編集
# vi /etc/php.ini
どこに下記の記載があるかわからない時は「/」の後に検索したい文字列を入れます。
例えば、
/date.timezone
で、[Enter]すると、該当する文字列が表示されます。以下の設定にかえて下さい。
行頭に「;」があるときは削除して下さい。そのままだとコメントアウトされます。
date.timezone = “Asia/Tokyo” ←line 942
mbstring.language = Japanese ←line 1502
mbstring.internal_encoding = utf-8 ←line 1509
mbstring.http_input = utf-8 ←line 1517
mbstring.http_output = pass ←line 1527
mbstring.encoding_translation = Off ←line 1535
mbstring.detect_order = utf-8 ←line 1540
mbstring.substitute_character = none ←line 1545
# systemctl restart httpd
# systemctl enable httpd
# systemctl status php-fpm
● php-fpm.service – The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; preset: disabled)
Drop-In: /usr/lib/systemd/system/service.d
mq10-timeout-abort.conf, 50-keep-warm.conf
Active: active (running) since Mon 2025-03-03 06:39:36 JST; 1h 51min ago
Invocation: 695da5a7acdb492ba079385ddc134eb9
Main PID: 4245 (php-fpm)
Status: “Processes active: 0, idle: 5, Requests: 9, slow: 0, Traffic: 0.00req/sec”
Tasks: 6 (limit: 38282)
Memory: 19.3M (peak: 19.6M)
CPU: 469ms
CGroup: /system.slice/php-fpm.service
tq4245 “php-fpm: master process (/etc/php-fpm.conf)”
tq4246 “php-fpm: pool www”
tq4247 “php-fpm: pool www”
tq4248 “php-fpm: pool www”
tq4249 “php-fpm: pool www”
mq4250 “php-fpm: pool www”
3月 03 06:39:35 yourdomain.com systemd[1]: Starting php-fpm.service – The PHP FastCGI Process Manager…
3月 03 06:39:36 yourdomain.com systemd[1]: Started php-fpm.service – The PHP FastCGI Process Manager.
PHPInfo を作成して動作確認
# echo ‘‘ > /var/www/html/info.php
(リモート)ブラウザで
http://yourdomain.com/info.php
で、画面を確認。
【 MariaDB のバージョン確認】
# yum list installed | grep mariadb
mariadb-libs.x86_64 1:5.5.68-1.el7 @anaconda
古いバージョンの MariaDB が確認されたら、削除します。
# yum remove mariadb-libs
【 MariaDB のインストール】
# dnf -y install mariadb-server
# vi /etc/my.cnf.d/charset.cnf
# 新規作成
# デフォルトの文字コードを設定
# 未設定の場合のデータベースのデフォルトは [latin1]
# 絵文字等 4 バイト長の文字を扱う場合は [utf8mb4]
# 3 バイト長の文字を扱う場合は [utf8mb3] (非推奨)
# [utf8] ⇒ [utf8mb3] のエイリアス
[mysqld]
character-set-server = utf8mb4
[client]
default-character-set = utf8mb4
# systemctl enable –now mariadb
時間がかかるかもしれません。
# mariadb-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
haven’t set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer ‘n’.
Switch to unix_socket authentication [Y/n] n
… skipping.
You already have your root account protected, so you can safely answer ‘n’.
Change the root password? [Y/n] n
… skipping.
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] n
… skipping.
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 利用方法】
# root で接続確認
# mysql -u root -p
Enter password: # root に設定したパスワード「password」で認証
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.9.2-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)]>
WordPress用データベース「wp」を作成、権限を「user」に与える。
MariaDB [(none)]> grant all on *.* to root@localhost identified by ‘password’;
MariaDB [(none)]> grant all on *.* to root@’%’ identified by ‘password’;
MariaDB [(none)]> create database wp;
MariaDB [(none)]> grant all on wp.* to user@localhost identified by ‘password’;
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
Bye
再起動します。
# systemctl restart mariadb
# systemctl enable mariadb
【php-mysqli 拡張をインストール】
# dnf install php-mysqlnd
# php -m | grep mysqli
mysqli
となれば、php-mysqli 拡張が有効になっています。
【 WordPress のインストール】
(リモート)ブラウザで
http://yourdomain.com/
を確認したら、Apacheのウェルカムページが出てきます。
これを削除します。
# rm -f /etc/httpd/conf.d/welcome.conf
/var/wwwにて、
# cd /var/www
# wget https://ja.wordpress.org/latest-ja.tar.gz
解凍します。
# tar xvf latest-ja.tar.gz
# ls
cgi-bin html latest-ja.tar.gz wordpress
「html」をいったん削除し、「wordpress」を「html」に変更します。
# rm -RI html
rm: remove 1 argument recursively? y
# mv wordpress html
「html」の所有者を「apache」に変更します。
# chown -R apache:apache html
念のため、再起動します。
# systemctl start httpd
# systemctl enable httpd
http://yourdomain.com/
を(リモート)ブラウザで確認したら、
http://yourdomain.com/wp-admin/setup-config.php
WordPressへようこそ。始める前に、以下の項目を知っておく必要があります。・・・
が表示された。
データベース名:wp
データベースのユーザー名:user
データベースのパスワード:password
データベースホスト:localhost
テーブル接頭辞 (1つのデータベースに複数の WordPress を作動させる場合):wp_
を確認し、後は画面の指示に従えば、インストールされ、設定画面にログインできます。