LoginSignup
4
6

More than 5 years have passed since last update.

ローカル開発環境で複数サブドメインを動かす。

Last updated at Posted at 2018-03-14

目的: ディレクトリを追加したら、ゲストOSをいじる事なく、新たにディレクトリ名のドメイン名でページが動くようにする。

使用方法:
1. ~/workspace/ に xxxx.xxx/public_html/ のディレクトリ構成の開発ページを追加
2. /etc/hosts/ で ipaddress xxxx.xxxを追加
3. xxxx.xxxにブラウザからアクセスを確認

ほとんど個人的なメモですが、参考にしていただけるところがあれば嬉しいです。
参考にして使えなかったらすいません、コメント欄に僕への罵倒とともにエラーコードや問題点等をお書きください。
できる範囲で解決に向けて考えるようにします。

また、あくまで僕個人用のメモの域を出ないので、説明不足やざっくり感は拭えないですが、時間あれば追記します。

以下開発環境構築の手順

virtualbox
vagrant install
box addまでは下記サイトや、他サイトを参考
https://qiita.com/sudachi808/items/3614fd90f9025973de4b

Vagrantfile編集

# ~/vm/Vagrantfile
Vagrant.configure("2") do |config|
    #centosを使用
  config.vm.box = "centos/7"
    #ipaddressを指定
  config.vm.network "private_network", ip: "192.168.33.xx"
  #共有フォルダをマウント (ホスト側に ~/workspace ディレクトリを事前に追加。) 
  config.vm.synced_folder "../workspace", "/workspace", mount_options:['dmode=777','fmode=777']
  config.vm.synced_folder "./", "/vagrant",type:"virtualbox"
end  
#UP
vagrant up

apache install

#準備
$ sudo yum upgrade
#インストール&起動
$ sudo yum install httpd
$ sudo systemctl start httpd

.htaccess許可

# /etc/httpd/conf/httpd.conf


ServerRoot "/etc/httpd"

Listen 80

Include conf.modules.d/*.conf
Include conf.modules.d/*.conf

User vagrant
Group vagrant

ServerAdmin root@localhost

<Directory />
    AllowOverride all
    Require all denied
</Directory>


DocumentRoot "/var/www/html"


<Directory "/var/www">
    AllowOverride All
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"


LogLevel warn

<IfModule log_config_module>

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

        <IfModule logio_module>
          LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
        </IfModule>

        CustomLog "logs/access_log" combined
    </IfModule>

    <IfModule alias_module>

    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

</IfModule>


<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>    
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on

IncludeOptional conf.d/*.conf
Include conf.d/vhosts.conf

VirtualHost構築

# /etc/httpd/conf.d/vhosts.conf

<VirtualHost *:80>
    ServerAdmin warden
    #共有フォルダをドキュメントルートに指定
    VirtualDocumentRoot /workspace/%0/public_html
    #ServerNameはなんでもいいはず。。。大丈夫な理由はわからないけど・・・・
        ServerName develhost
    EnableSendfile Off

    <Directory /workspace/*/public_html>
        php_value display_errors On
        Order deny,allow
        Allow from all
        AllowOverride All
        Require all granted
    </Directory>

    SetEnv ENV_SERVER_TYPE devel
</VirtualHost>

php install

以下参考
https://qiita.com/ozawan/items/caf6e7ddec7c6b31f01e
インストール後php.ini設定

# /etc/php.ini

[PHP]
error_reporting = E_ALL | E_STRICT
display_errors on

[Date]
date.timezone="Asia/Tokyo"

[mbstring]
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = auto
mbstring.http_output = UTF-8
mbstring.encoding_translation = On
mbstring.detect_order = auto

mariadb install

yum install mariadb mariadb-server
rpm -qa | grep maria
#文字コード返還
# /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
character-set-server=utf8

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

!includedir /etc/my.cnf.d

#起動
systemctl enable mariadb.service
systemctl start mariadb.service

#初期設定
mysql_secure_installation

SEliux 無効化(必要であれば)

sudo sed -i.bak -e "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
sudo setenforce 0

Firewall 無効化(必要であれば)

sudo systemctl stop firewalld
sudo systemctl disable firewalld

apache 自動起動化&再起動

$ sudo systemctl enable httpd
$ sudo systemctl restart httpd

systemctl restart httpd でエラーが出た場合は下記の構文チェックを使用して漏れがないか調べる。

$ httpd -t

# Syntax OKが出ればOK。何かエラーがあれば修正して再チェック

参考サイト

構築全体
http://mssr-nm.hatenablog.com/entry/2016/03/23/133151#install
virtualhost
https://qiita.com/terrym/items/ba988394fbe6099b4485
phpインストール
https://qiita.com/ozawan/items/caf6e7ddec7c6b31f01e
https://qiita.com/pakiln/items/645e8a97cde46b59f9f8
SElinux
https://eng-entrance.com/linux-selinux
wp用参考サイト
https://rin-ka.net/wordpress-init/

その他

不備・間違い等見つけ次第修正予定
何か見つけましたら教えていただけますと幸いです。

4
6
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
4
6