# Installing VLSM on a Windows Machine

### 0. Download

* Notepad++ or MicroSoft VS Code
* WampServer from [https://www.wampserver.com/en/](https://www.wampserver.com/en/). Check if Windows is 32 bit or 64 bit. Download WampServer 32 or 64 bit version based on the windows machine
* [VC Packages](https://wampserver.aviatechno.net/files/vcpackages/all_vc_redist_x86_x64.zip)


### 1. Installing WAMP Server

- Ensure Windows system is updated. This is important to ensure there is no issue on WampServer later on.
- Install VC Packages that we downloaded already - for 64 bit you need to install all, for 32 bit only install 32 bit ones
- Reboot machine after installing
- Now run WampServer and ensure it is showing green icon

### 2. Configuring PHP and MySQL

#### 2.1 PHP Setup

- Download cacert.pem from [https://curl.se/docs/caextract.html](https://curl.se/docs/caextract.html). Place it in `C:\wamp\` or `C:\wamp64\` path. This is needed to allow the application to communicate with VLSTS

- Change PHP version to 8.2.13. To do this, click on WampServer -> PHP -> version -> 8.2.13
- Next we will change PHP settings to make them more optimum for VLSM. To do this, click on WampServer -> PHP -> php.ini
   - When the file opens search for `memory_limit`. Change 128mb to 2G (or more if there is more RAM available on the computer)
   - Now search for `post_max_size`. Change 8M to 500M
   - Now search for `upload_max_filesize`. Change 2M to 500M
   - Find `;openssl.cafile=` and change it to `openssl.cafile='C:\wamp\cacert.pem'` or `openssl.cafile='C:\wamp64\cacert.pem'`
   - Find `;curl.cainfo =` and change it to `curl.cainfo ='C:\wamp\cacert.pem'` or `curl.cainfo ='C:\wamp64\cacert.pem'`
   - Now search for `error_reporting`. Change it to `error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED & ~E_WARNING`
   - Now search for `max_execution_time`. Change it to `max_execution_time = 1200`
  - **Open the php.ini file inside the C:\wamp64\bin\php\php8.2.13\php.ini and do these same edits there as well**





#### 2.2 MYSQL Setup

- Fixing the MySQL mode

   - Click on WampServer icon -> MySQL -> my.ini
   - When the file opens, search for `sql_mode` if it is already set comment out that line by adding a semi-colon `;` in the beginning of the line and add the following lines after that:

       ```
       sql_mode =
       innodb_strict_mode = 0
       ```

   - Search for `innodb_default_row_format=compact` and change it to `innodb_default_row_format=dynamic`
   - If it is not there then just add `innodb_default_row_format=dynamic`
   - Close the text file


- Next we will change MySQL password.
   - WampServer icon -> MySQL -> MySQL Console
   - Username is `root`
   - Password is blank (just press enter when it asks for password)
   - Now type this:

       ```
       ALTER USER 'root'@'localhost' IDENTIFIED WITH  mysql_native_password BY 'PASSWORD';
       FLUSH PRIVILEGES;
       exit;
       ```
   - Press enter after pasting these lines in the terminal

- Click on Wampserver icon and Restart all services

- Download latest version of composer from [https://getcomposer.org/download/](https://getcomposer.org/download/)

### 3. Setting up VLSM

#### 3.1 VLSM Application Setup

- Download VLSM from [https://github.com/deforay/vlsm](https://github.com/deforay/vlsm)
- Unzip and put it in `C:\wamp\www\vlsm` or `C:\wamp64\www\vlsm` path
- Put the composer.phar also inside the vlsm folder
- To complete VLSM installation, open the terminal and run the composer commands

```
cd C:\wamp64\www\vlsm

set PATH=C:\wamp64\bin\php\php8.2.13;%PATH%

php composer.phar install --no-dev
php composer.phar dump-autoload -o
```

- The latest VLSM database is inside the vlsm/sql/init.sql file.
- Start phpmyadmin by typing [http://localhost/phpmyadmin](http://localhost/phpmyadmin) in browser (login id is `root` and password is `mko)(*&^`)
- Click on `SQL` menu on top and type the following line
       ```CREATE DATABASE `vlsm` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;```
- This will create a blank vlsm database. Now click on vlsm on left and import the sql file downloaded earlier
- Also run the SQL commands from this link [https://github.com/deforay/vlsm/blob/master/sql/audit-triggers.sql](https://github.com/deforay/vlsm/blob/master/sql/audit-triggers.sql)
- Rename the file configs/config.production.dist.php to configs/config.production.php
- Enter Database User, Password, DB Name etc.

```php

// VLSTS URL
$systemConfig['remoteURL'] = 'https://STSURL';


// Enable/Disable Modules
// true => Enabled
// false => Disabled
$systemConfig['modules']['vl'] = false;
$systemConfig['modules']['eid'] = true;
$systemConfig['modules']['covid19'] = false;
$systemConfig['modules']['hepatitis'] = false;
$systemConfig['modules']['tb'] = false;

// Database Settings
$systemConfig['database']['host']       = 'localhost';
$systemConfig['database']['username']   = 'root';
$systemConfig['database']['password']   = 'PASSWORD';
$systemConfig['database']['db']         = 'vlsm';
$systemConfig['database']['port']       = 3306;
$systemConfig['database']['charset']    = 'utf8mb4';

.
.
.
.
.


// Enable/Disable Interfacing
// true => Enabled
// false => Disabled
$systemConfig['interfacing']['enabled'] = true;

// Interfacing Database Details (not needed if above feature set to false)
$systemConfig['interfacing']['database']['host'] = 'localhost';
$systemConfig['interfacing']['database']['username'] = 'root';
$systemConfig['interfacing']['database']['password'] = 'PASSWORD';
$systemConfig['interfacing']['database']['db'] = 'interfacing';
$systemConfig['interfacing']['database']['port'] = 3306;
$systemConfig['interfacing']['database']['charset'] = 'utf8mb4';

```

* Next step is creating a virtual host pointing to the vlsm application
   * Start notepad or notepad++ as admin user (go to start menu, search for notepad and right click and click on Run as administrator)
   * open this file `C:\windows\system32\drivers\etc\hosts`
   * Add this line at the bottom `127.0.0.1 vlsm` and save & close the file
   * Next open `C:\wamp\bin\apache\apache2.4.54.2\conf\extra\httpd-vhosts.conf`
   * change the existing vhost to the following:

       ```apache
       <VirtualHost *:80>
         ServerName localhost
         ServerAlias vlsm
         DocumentRoot "${INSTALL_DIR}/www/vlsm/public"
         <Directory "${INSTALL_DIR}/www/vlsm/public/">
           AddDefaultCharset UTF-8
           Options +Indexes +Includes +FollowSymLinks +MultiViews
           AllowOverride All
           Require local
         </Directory>
       </VirtualHost>
       ```
   * Save & Close this file
   * Click on WampServer icon and Restart all services
* Now go the command prompt and type these commands:

   ```
   cd C:\wamp64\www\vlsm
   
   set PATH=C:\wamp64\bin\php\php8.2.13;%PATH%

	php composer.phar post-install
   ```
* Now open [http://vlsm](http://vlsm)
   * Register a new Admin user and Login
   * Fill the instance details in the popup. Select BOTH for type of Instance
   * Now scroll to the bottom and click on `Force Remote Sync`. **Please wait for the sync to finish**.
* Once sync is finished go to [http://vlsm/system-admin](http://vlsm/system-admin)
   * Secret Key can be found in `C:\wamp64\www\vlsm\app\system-admin\secretKey.txt`
   * Register new System Admin and Login
   * Select Instance Type as 'Lab Instance' and then select the Lab name from dropdown and click on Submit. (Ignore SMTP settings)
   * You can sign out
* Users can now start using vlsm from [http://vlsm](http://vlsm) URL


#### 3.2 Task Scheduler

* Run Task Scheduler. Click on "Create Task"
* Name : VLSM TASK
* Select "Run whether user is logged on or not"
* Now Go to the ‘Triggers’ tab which is next to the ‘General’ tab. And Click on the ‘New’ button.
* Select 'Daily'
* Check "Repeat Task Every" and make it as "1 minutes" and choose for a duration of "Indefnitely"
* Check the checkbox ‘Stop the task if it runs longer than’. It is optional. If the script goes in an indefinite loop or a similar situation due to any reason, the task will be terminated automatically after the day/time defined in this option. By default the value is ‘3 days’. Leave the default value.
* Click OK
* Click on the ‘Actions’ tab and click on the ‘New’ button inside it.
* in the Program/Script find the php exe file for eg. `C:\wamp\bin\php\php8.2.13\php.exe` or  `C:\wamp64\bin\php\php8.2.13\php.exe`
* in Add Arguments type `C:\wamp\www\vlsm\vendor\bin\crunz schedule:run` or `C:\wamp64\www\vlsm\vendor\bin\crunz schedule:run`
* Click on OK
* When prompted for password, please enter the Windows user password (might be cphd123, but check with lab first)



### 4. Setting up Interfacing

* Start phpmyadmin by typing [http://localhost/phpmyadmin](http://localhost/phpmyadmin) in browser (login id is `root` and password is `mko)(*&^`)
- Click on `SQL` menu on top and type the following lines

   ```
   CREATE DATABASE `interfacing` CHARACTER SET utf8mb4
   COLLATE utf8mb4_general_ci;

   CREATE USER 'interfaceadmin'@'%' IDENTIFIED
   WITH mysql_native_password AS 'interface@12345';

   GRANT USAGE ON *.* TO 'interfaceadmin'@'%' REQUIRE NONE
   WITH MAX_QUERIES_PER_HOUR 0
   MAX_CONNECTIONS_PER_HOUR 0
   MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;

   GRANT ALL PRIVILEGES ON
   `interfacing`.* TO 'interfaceadmin'@'%';
   ```

- This will create a blank interfacing database. Now click on interfacing on left and import the sql file
- Download the latest Interfacing executable
- Install the executable and login with the credentials `admin` and `admin`
- On the settings screen, please enter the correct MySQL details and Instrument Interface details
- Ensure that the interface shows connected before releasing results from the machine