# URVault Server — Windows Installation Guide

## System Requirements

- Windows 10 or Windows 11 (64-bit)
- 4 GB RAM minimum (8 GB recommended)
- 20 GB free disk space minimum for the server; additional space for backups
- Internet connection (for Cloudflare tunnel and automatic dependency installation)

Node.js and MySQL are installed automatically by the installer if not already present.

---

## Installation

1. Download `urvault-server-v1.2.20-windows.zip` from [urvault.net](https://urvault.net)
2. Right-click the zip and choose **Extract All**
3. Open the extracted **urvault-server** folder
4. Double-click **Install URVault.bat**
5. Click **Yes** on the Windows UAC (administrator) prompt

The installer will walk through 6 steps automatically:

| Step | What happens |
|------|-------------|
| 1/6  | Checks for Node.js 18+ — installs via winget if missing |
| 2/6  | Checks for MySQL 8+ — installs and initializes if missing |
| 3/6  | Configures the MySQL database and creates a secure URVault user |
| 4/6  | Installs server dependencies |
| 5/6  | Generates security keys, writes `.env`, downloads Cloudflare tunnel binary |
| 6/6  | Registers URVault as a Windows service (auto-starts on boot) via NSSM |

When complete, open your browser to **http://localhost:5173** to finish the setup wizard.

---

## First-Time Setup

1. Open `http://localhost:5173` in your browser
2. Complete the setup wizard: create your admin account and confirm settings
3. Pair your phone: open the URVault app, tap **Add Server**, and scan the QR code

---

## Starting and Stopping the Server

The Windows service starts automatically on boot. To manage it manually:

```cmd
:: Start
net start URVaultServer

:: Stop
net stop URVaultServer

:: Restart
net stop URVaultServer && net start URVaultServer

:: Check status
sc query URVaultServer
```

You can also double-click **start-server.bat** in the server folder to run it in a console window.

---

## Remote Access

On each startup, the server launches a Cloudflare tunnel and registers the URL with the URVault relay. This allows the mobile app to reach your server from any network without port forwarding or a static IP.

The tunnel URL is updated automatically in `.env` each session.

---

## File Locations

| Item | Location |
|------|----------|
| Server files | Wherever you extracted the zip |
| `.env` config | Inside the server folder |
| Backup storage | Chosen during install (default: `C:\ProgramData\URVault\backups`) |
| Service log | `server.log` in the server folder |

---

## Troubleshooting

### Browser shows "This site can't be reached" on port 5173
- Check the service is running: `sc query URVaultServer`
- Start it manually: `net start URVaultServer` or double-click `start-server.bat`
- Check `server.log` in the server folder for errors

### MySQL connection errors
- Verify MySQL is running: `sc query MySQL84` (or `MySQL80` depending on version)
- Start it: `net start MySQL84`
- Confirm `.env` contains the correct `DB_PASSWORD`

### Firewall blocking access from phone
- The installer adds a firewall rule for TCP port 5173 automatically
- To verify: `netsh advfirewall firewall show rule name="URVault Server"`
- To re-add: `netsh advfirewall firewall add rule name="URVault Server" dir=in action=allow protocol=TCP localport=5173`

### Re-running the installer
The installer is safe to re-run. It will skip steps that are already complete (MySQL, database, existing `.env`).

---

## Uninstalling

1. Stop and remove the service:
   ```cmd
   net stop URVaultServer
   nssm remove URVaultServer confirm
   ```
2. Delete the server folder
3. Optionally remove backup data: `C:\ProgramData\URVault\backups`
4. Optionally drop the database: `mysql -u root -p -e "DROP DATABASE urvault;"`

---

## Support

Email: support@urvault.net
Website: https://urvault.net
