LoginSignup
0
1

More than 5 years have passed since last update.

CentOS7 httpdバーチャルホストの設定【1/2】

Last updated at Posted at 2017-04-22

CentOS7にLAMP環境を構築して、1つのサーバーで複数ドメインのWEBサイトを構築することがあったのでその手順の備忘録
まずは環境の構築編

こちらにまとめなおしました。
こちらを参照してください。
https://qiita.com/salt_field/items/31acb1cbb707102e0702

前提

今回は1つのサーバーに複数ドメインのWEBサイトを構築し、それぞれでwordpressを稼働させます。
また、すべてのドメインでSSL(https)を強制します。
今回使用するSSL証明書はLet's Encryptを使用します。

メインドとかユーザーの情報

項目 メインドメイン バーチャルホスト
ドメイン main.test.com sub.test.com
ユーザー User1 User2
パスワード User1Pass User2Pass
DB Main Sub

共通
rootのパスワード「rootpass」

※ユーザー名とパスワードはOS・DB・Wordpress全て同じものを使用したと仮定します。
※実際に構築する際は必要に応じて変更してください。

環境

conohaのVPS(512MBプラン)
お申込みはこちらから
サーバー運用の支援をお願い致します。
https://www.conoha.jp/referral/?token=EHzpH4qBxC2nEldYUngHXpxv9ja17c0iqAenX5M6pbFMNPgLFFc-B34

CentOS7(7.3.1611)
apache(2.4.6)
mariaDB(10.1)
php(7.0.18)

apacheの構築

apacheのインストール

httpインストール
yum install httpd

設定の変更

/etc/httpd/conf/httpd.conf
#ServerName www.example.com:80

ServerName test.com:80 ← サーバー名を指定


Options Indexes FollowSymLinks

Options Includes ExecCGI FollowSymLinks ← CGI,SSIの許可


AllowOverride None

AllowOverride All ← .htaccessの許可


AddDefaultCharset UTF-8

#AddDefaultCharset UTF-8 ← コメントアウト(文字化け対応)


#AddHandler cgi-script .cgi

AddHandler cgi-script .cgi .pl ← CGIスクリプトに.plを追加

ファイルの一覧を表示しないようにする

/etc/httpd/conf.d/autoindex.conf
<Directory "/usr/share/httpd/icons">
    Options MultiViews ← iconsディレクトリのファイル一覧を表示しないようにする
    AllowOverride None
    Require all granted
</Directory>

テストページの削除

rm -f /etc/httpd/conf.d/welcome.conf

Perlコマンドへ/usr/local/bin/perlでもアクセスできるようにする。

ln -s /usr/bin/perl /usr/local/bin/perl

ユーザー作成時にpublic_htmlフォルダを自動で生成するようにする。

mkdir /etc/skel/public_html
chgrp apache /etc/skel/public_html
chmod 755 /etc/skel/public_html

ユーザーを作成する

ユーザーを作成するが、SSHでログインできないようにする。

useradd -s /sbin/nologin 【ユーザー名】
passwd 【ユーザー名】

passwdコマンドの後に2回パスワードを聞かれるので入力する。

メインドメインのドキュメントルート所有者を変更

chown user1 /var/www/html/

ひとまずここまで構築する

PHPの構築

yumリポジトリの追加

EPELとRemiリポジトリの追加
yum install epel-release
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

PHP7.0のインストール

yum install --enablerepo=remi,remi-php70 php php-devel php-mbstring php-pdo php-gd php-pear php-mcrypt php-mysql php-mysqlnd

PHPの設定変更

/etc/php.ini
date.timezone = "Asia/Tokyo"
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = UTF-8
mbstring.http_output = pass
mbstring.encoding_translation = On
mbstring.detect_order = auto
mbstring.substitute_charset = none

MariaDBの構築

mariadbのリポジトリを作成する。

ファイルの中身はこのリンクから作成できる。
https://downloads.mariadb.org/mariadb/repositories/

/etc/yum.repos.d/MariaDB.repo
# MariaDB 10.1 CentOS repository list - created 2017-04-22 14:53 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

MariaDBをインストールする

sudo yum install MariaDB-server MariaDB-client

文字コードをutf8に変更

/etc/my.cnf.d/server.cnf
[mysqld]
character-set-server=utf8

初期セットアップ

サービスを開始する。
自動起動の設定をしないと起動しないので注意

# systemctl enable mariadb.service
# systemctl start mariadb.service

初期設定
mysql_secure_installation

最初は何も入力せずに「Enter」を押す。
それ以外はすべて「y」を入力する。
2回目の項目に関してはyのあとにパスワードを入力する
ここではrootpassとする。

今回はここまで、実際のインストールはまた次回

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1