August 02, 2019

How to create a virtual host on a port basis at apache2/PHP7

1. After opening the "/etc/apache2/ports.conf" file, add the following information.

1. "/etc/apache2/ports.conf" 파일을 오픈한 뒤, 아래와 같이 정보를 추가한다.

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in # /etc/apache2/sites-enabled/000-default.conf

Listen 8961
Listen 4241
Listen 3317

- Add the port what you want to open using the keyword "Listen".

- 개방하고자 하는 포트를 "Listen" 키워드를 사용하여 추가한다.




2. After opening the "/etc/apache2/sites-available/000-default.conf" file, add the following information.

2. "/etc/apache2/sites-available/000-default.conf" 파일을 열람한 뒤, 아래와 같이 정보를 추가한다.

<VirtualHost *:8961>
    DocumentRoot /var/www/abc1
</VirtualHost>

<VirtualHost *:4241>
    DocumentRoot /var/www/abc2
</VirtualHost>

<VirtualHost *:3317>
    DocumentRoot /var/www/abc3
</VirtualHost>

- Reflect the port you registered in "ports.conf" to the VirtualHost tag.

- "ports.conf"에 등록했던 포트를 VirtualHost 태그에 반영한다.

- Set the root directory of the virtual host using the keyword "DocumentRoot".

- "DocumentRoot" 키워드를 사용하여 해당 가상 호스트의 루트 디렉토리를 지정한다.