RockyLinux9.5でWordPress環境構築した際のメモです。
今回はWebサーバーApacheをインストールし設定します。
Apacheのインストール
「httpd」「httpd-tools」「mod_ssl」をインストール
sudo dnf install httpd httpd-tools mod_ssl
httpdを起動し、ステータスを確認
sudo systemctl start httpd
sudo systemctl status httpd
サーバを再起動しても自動的に起動するように設定
sudo systemctl enable httpd
sudo systemctl is-enabled httpd
ブラウザでサイトURL http://xxx.xxx.xxx.xxx (IPアドレス)にアクセスし、Apatchのテストページが表示れていれば成功です。
ドキュメントルートディレクトリの作成
sudo mkdir /var/www/html/yoursite.com
sudo mkdir chown apache.apache /var/www/html/yoursite.com/
設定ファイル(httpd.conf)の編集
オリジナルをバックアップ
sudo cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.org
vimで開いて編集
sudo vim /etc/httpd/conf/httpd.conf
以下の部分を編集します。
/etc/httpd/conf/httpd.conf
# ServerName www.example.com:80
↓
ServerName yoursite.com:80
/etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html"
↓
DocumentRoot "/var/www/html/yoursite.com"
/etc/httpd/conf/httpd.conf
<Directory "/var/www/html">
↓
<Directory "/home/www/html/yoursite.com">
/etc/httpd/conf/httpd.conf
Options Indexes FollowSymLinks
↓
Options FollowSymLinks
/etc/httpd/conf/httpd.conf
Options Indexes FollowSymLinks
↓
Options FollowSymLinks
/etc/httpd/conf/httpd.conf
DirectoryIndex index.html
↓
DirectoryIndex index.php index.html
設定ファイルの確認
以下のコマンドでエラーが表示される場合、設定ファイルやディレクトリ構成に問題があります。
sudo httpd -t
Apacheを再起動
sudo systemctl restart httpd.service