---
# System prepended metadata

title: Construct VM as XAMPP Server on NAS (QNAP)
tags: [主機維護]

---

# Construct VM as XAMPP Server on NAS (QNAP)

<!-- 標籤 -->
###### tags: `主機維護`

<!-- 內文編輯更新資訊，若有更動此份文件內容，請務必更新此項資訊 -->
> [name=Chia-Hung Huang, 黃嘉宏]
> [time=Sat, Apr 9, 2022 9:45 AM]

<!-- 筆記正文開始 -->

## Build a New VM
1. Get the `.iso` file, and put it into  `Public/OS/`.
    - Windows server 2016 
    - Linux (Ubuntu): https://ubuntu.com/download/desktop 
2. Go to `Visualization Station 3` on NAS and create a new VM. Select the `.iso` file you just put into `Public/OS/` and set the Storage to `Public/VM/` . For other setting details, please refer to the settings of the other VMs already on NAS.

## Network Settings on NAS
1. Go to `Network & Virtual Switch` on NAS.
2. Select an idle Physical Adapter (or create a new one). 
    - In the `IPv4` tab, select `Use static IP address` and do the following settings:
        - `Fixed IP address`: Set to be one of the available IP address. For IP address list, please refer to: https://docs.google.com/spreadsheets/d/1vJ2QMsyDoNt_3NYPdfaaj2HSeqewk9nBcHeyNNdoq14/edit#gid=1138232818
        - `Subnet Mask`: `255.255.255.0`
        - `Gateway`: `140.112.30.254`
    - In the `DNS` tab, select `Use the following DNS server address` and do the following settings:
        - `Primary DNS server`: `140.112.2.2`
        - `Secondary DNS server`: `140.112.4.254`
3. Add a virtual switch, choose `Advanced Mode`, and connect the physical adapter to the VM you just created. **Please note that you should NEVER touch the System Default Gateway**, or the whole NAS service may crush.
    - Select `Stacic IP`, `Use the same settings as the selected adapter`
    - Select `IPv6 Auto-Configuration (Stateless)`
    - For DNS Settings, manually assign `Primary DNS server` to `140.112.2.2` and `Secondary DNS server` to `140.112.4.254`
4. In the `Overview` tab, make sure there is a blue earth icon, which means "Internet connected", on the Physical Adapter and Vitrual Switch you just created. You can refer to the following image for example.
![](https://i.imgur.com/c2ZFEOW.png)
5. In the `ControlPanel` of the NAS service, go to `Network & File` > `Network Access` > `Service Binding`, and enable `Web server` and `SQL server` of the newly-added physical adapter.
![](https://i.imgur.com/E56uJXy.png)

## Network Settings on VM
- 前往`設定 > 網路和網際網路 > 乙太網路 > 內容 > IP 設定`，手動指派 IP：
    - IPv4 位址：Physical Adapter 的 IP
    - 子網路首碼長度：`24`
    - 閘道：`140.112.30.254`
    - DNS 伺服器：`140.112.2.2`、`140.112.4.254`
- 確認 VM 可以連上網路


## XAMPP Server
1. Install XAMPP and install : https://www.apachefriends.org/de/download.html
2. To avoid the UAC interference, please install XAMPP in a folder with the name `xampp` directly under `C:/` (i.e. `C:/xampp`, NOT `C:/program Files/xampp`)
3. Create a new web root directory `C:/WebRoot`
4. Go to the XAMPP Control Panel. Click `Config` (as shown in the image) and modify the following files:
![](https://i.imgur.com/S5KO7p4.png)
    - `Apache(httpd.conf)`:
        ```conf
        # Original
        Listen 80

        # Add IP port
        Listen 80
        
        
        # Original
        DocumentRoot "C:/xampp/htdocs"
        <Directory "C:/xampp/htdocs">
        
        # Change to
        DocumentRoot "C:/WebRoot"
        <Directory "C:/WebRoot">
        ```
    - `Apache(httpd-ssl.conf)`
        ```conf
        # Original
        DocumentRoot "C:/xampp/htdocs"
        
        # Change to
        DocumentRoot "C:/WebRoot"
        ```
    - `PHP(php.ini)`
        ```conf
        # Original
        include_path=C:\xampp\php\PEAR
        
       #Change to
       include_path=".;C:\xampp\php;C:\xampp\php\pear;C:\WebRoot;"
        ```
5. Forbid apache server to show the directory indexes.
    * `httpd.conf`
        ```conf
        # Original
        Options Indexes FollowSymLinks Includes ExecCGI
        
        # Change to
        Options FollowSymLinks Includes ExecCGI
        ```
7. Restart the Apache server. The `WebRoot` directory is now accessible from outside network with its IP.
8. Since the VM is built on the NAS, so it cannot be reached through NAS VPN.

## Follow-up
For further works, please refer to [DocuSky 架設程序 (移機)](https://hackmd.io/@6vl-R1QtRl-LuttqpoUdVA/r1jf8p86w)