LAMP(Linux、Apache、MySQL、PHP)を構築し、CMS(Content Management System)である、WordPressをインストールするための準備をします。
事前準備
CentOS8は最小限のインストールを選択しました。そこで、開発ツールなどの基本的なパッケージをインストールしておきます。
OSのバージョン確認方法
# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)OSのバージョン確認方法
# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)
開発ツールのインストール
最初は開発ツールなどの基本的なパッケージをインストールします
# yum -y groupinstall base
# yum -y groupinstall development
# yum -y groupinstall network-tools
インストール済みのパッケージを、最新版にアップデートします。
# yum -y update
Firewallの設定
Apacheサービスを利用するために、ファイアウォールの設定をしておきます。
ファイアウォールの状態を確認します
# firewall-cmd –list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3
sources:
services: cockpit dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
Apacheの使うポートを開けておきます。
# firewall-cmd –permanent –zone=public –add-service=http
# firewall-cmd –permanent –zone=public –add-port=80/tcp
# firewall-cmd –permanent –zone=public –add-service=https
# firewall-cmd –permanent –zone=public –add-port=443/tcp
# firewall-cmd –reload
設定内容を再度確認します
# firewall-cmd –list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3
sources:
services: cockpit dhcpv6-client http https ssh
ports: 80/tcp 443/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
SELINUXの設定
ドキュメントルートのコンテキストを調べておきます。なお、この作業はApacheをインストール後に行います!Apacheがインストールされていないと、デフォルトの公開フォルダも、出来ていない様です。
# cd /var/www
# ls -Z
system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin
system_u:object_r:httpd_sys_content_t:s0 html
上記になっている場合は、SELINUXでの設定は必要ありません。なっていない場合はドキュメントルートには下記のコンテキストを設定しておきます
# semanage fcontext -a -t httpd_sys_content_t “/var/www/html(/.*)?”
設定を反映するには下記コマンドを実行します
# restorecon -R -v /var/www/html/
次に、SSL証明書の設置場所にもSELINUXの設定を行う必要があります。
以下のコマンドで確かめます
# cd /etc/pki/tls
# ls -Z
system_u:object_r:cert_t:s0 cert.pem
system_u:object_r:cert_t:s0 certs
system_u:object_r:cert_t:s0 ct_log_list.cnf
system_u:object_r:cert_t:s0 misc
system_u:object_r:cert_t:s0 openssl.cnf
system_u:object_r:cert_t:s0 private
コンテキストが、cert_t となっていれば設定が出来ています。
ここからはLAMPの構築です
Apache httpdのインストール
# yum -y install httpd-devel # yum -y install mod_ssl Apacheのバージョン確認 # httpd -v Server version: Apache/2.4.37 (centos) Server built: Oct 7 2019 21:42:02
PHPのインストール
# yum -y install php php-devel php-pdo php-mysqlnd php-mbstring php-gd php-pear php-pecl-apc-devel zlib-devel php-json PHPのバージョン確認 # php-fpm -v PHP 7.2.11 (fpm-fcgi) (built: Oct 9 2018 15:09:36) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
MySQLのインストール
# yum -y install mysql-devel # yum -y install mysql-server MySQLのバージョン確認 # mysql --version mysql Ver 8.0.17 for Linux on x86_64 (Source distribution)
Apacheの設定
# cd /etc/httpd/conf/ # cp httpd.conf httpd.conf.org # vi httpd.conf 内容変更部 98行目 ServerName east-mikas.com:80
# cd /etc/httpd/conf.d/ # vi ssl.conf 44行目 ServerName east-mikas.com:443 59行目 SSLProtocol -all +TLSv1.1 +TLSv1.2 +TLSv1.3 85行目 SSLCertificateFile /etc/pki/tls/certs/server.crt 93行目 SSLCertificateKeyFile /etc/pki/tls/private/server.key
# systemctl start httpd # systemctl status httpd # systemctl enable httpd Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
PHPの設定
# vi /etc/php.ini 374行 expose_php = On ↓ expose_php = Off 460行目 error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT ↓ error_reporting = E_ALL & ~E_NOTICE 825行目 upload_max_filesize = 2M ↓ upload_max_filesize = 20M 903行目 ;date.timezone = ↓ date.timezone = 'Asia/Tokyo'
PHP-FPMの起動
# systemctl start php-fpm # systemctl enable php-fpm
MySQLの設定
# cd /etc/my.cnf.d/ # vi mysql-server.cnf 末尾に下記を追加します slow_query_log=ON slow_query_log_file=/var/log/mysql/slow_query.log long_query_time=1.0 log_timestamps=SYSTEM skip-character-set-client-handshake
MySQLの起動
# systemctl start mysqld # systemctl enable mysqld
MySQLのrootのパスワードを設定
# mysql_secure_installation --use-default (略) Please set the password for root here. New password: <新しいパスワード> Re-enter new password: <新しいパスワード> (略) Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y (不要なユーザーやDBを削除) All done!
