LoginSignup
0
1

More than 3 years have passed since last update.

【PHP/Laravel】php artisan serveを使わずにVirtual Hostを設定する

Posted at

【PHP/Laravel】php artisan serveを使わずにVirtual Hostを設定する

使用環境

  • windows 10 Home(COREi7)
  • XAMPP 7.3.18
  • Laravel 6

そもそもVirtual Hostって何?

バーチャルホストという用語は、1 台のマシン上で (company1.com と company2.com のような) 二つ以上のウェブサイトを扱う運用方法のことを指します。
Apache バーチャルホスト説明書

virtual hostの設定

  • C:\xampp\apache\conf\extra の中のhttpd-vhost.confファイルをまずコピーを取っておく。

  • 以下の部分を書き換える

##NameVirtualHost *:80

・・・中略・・・

##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host.example.com
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

  • 下記を参考に書き換える
NameVirtualHost *:80

・・・中略・・・

Listen 10001
<VirtualHost localhost:10001>
    ##ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "C:\laravel\practice\public"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
    <Directory "C:\laravel\practice\public">
      AllowOverride All
      Options +Indexes
      Require all granted
    </Directory>
</VirtualHost>


  • 新しくポートを作る。

  • 任意で指定するポート番号を付ける(今回は10001を使用)
    Listen 10001と記入

  • その下にVirtualHostの設定を書き込む
    DocumentRootの#を外しディレクトリ設定を書き込む
     AllowOverride All
     →.htaccessで設定可能なものは全て有効になる

 Options +Indexes
 →ディレクトリに対するリクエストに対して、DirectoryIndex で指定したファイル(index.html 等)が存在しない場合に、ディレクトリ内ファイルの一覧を表示

 Require all granted
 →無条件でアクセスを許可

Apache HTTP SERVER PROJECT

  • DocumentRootとDirectoryにLaravelプロジェクト(今回はpractice)のpublicを指定する

参考

Qiita:ApacheのVirtual Hostってなんだ

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