Loading...
「ツール」は右上に移動しました。
利用したサーバー: wtserver1
9いいね 272 views回再生

How to set up Apache Virtual Hosts on Windows Subsystem for LInux

View on website:
https://scottsweb.dev/how-to-set-up-a...

In this video we look at setting up apache virtual hosts on Windows Subsystem for Linux (WSL)

Why set up virtual hosts?

Virtual hosts allow you to have local domains instead of using localhost/site-name in your local URLs.

Setting up virtual hosts on WSL is a little bit different than windows/or linux because you have to update both OS's hosts file.

You'll need to repeat these steps for every virtual host you want to add.

Set up your hosts file

On Windows, open notepad as adminstrator and navigate to c:/windows/system32/drivers/etc/ and open the hosts file. You may have to click see all file types to see this file.

At the bottom, add new lines:

127.0.0.1 mysite1.local
::1 mysite1.local

On WSL, edit /etc/hosts, adding the same two lines to the bottom:
127.0.0.1 mysite1.local
::1 mysite1.local

Set up your apache virtual host conf file.

Navigate to /etc/apache2/sites-available

Create a file named mysite1.local.conf here (replacing mysite1.local with your local domain)

Add the following to the file, replacing with your details for servername and document root.

(Copy this code from website or replace [ with less than and ] with greater than in the code below)

[VirtualHost *:80]
ServerAdmin webmaster@localhost
ServerName mysite1.local
DocumentRoot /var/www/html/mysite1

[Directory /var/www/html/mysite1]
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
[/Directory]
[/VirtualHost]

Enable your site
sudo a2ensite mysite1.local.conf

Reload apache
sudo systemctl reload apache2

Visit your site in your browser at http :// mysite1 . local (replace with your site domain)

We learn how to set up SSL in a future video.

コメント