# Installing the VNC India website on a new server

The `website/` folder is the complete site. Everything else in this zip (`schema.sql`, `migration.sql`, this file) is for setup only and must **not** be uploaded to the web folder.

## Requirements

- PHP 8.1 or newer, with the `mysqli`, `curl` and `fileinfo` extensions (standard on cPanel/DirectAdmin hosting; `mbstring` is recommended)
- MySQL 5.7+ or MariaDB 10.3+
- Apache or LiteSpeed with `.htaccess` files enabled (`AllowOverride All`) and `mod_rewrite`. For nginx, see the end of this file.
- An SSL certificate (HTTPS). Razorpay and VNC Roots both need it, and the site redirects all visitors to https://.
- The site must be at the root of its domain (e.g. `https://vncindia.org/`, not `https://example.org/vncindia/`), because some links start with `/`.

## 1. Database

Create an empty database and a user with full access to it (hosting panel → MySQL Databases).

- **New, empty site:** import `schema.sql` (phpMyAdmin → select the database → Import).
- **Moving the existing site:** export the database from the old server and import that instead. If the old database hasn't had `migration.sql` run on it yet, run it afterwards (phpMyAdmin → SQL tab → paste → Go).

## 2. Upload the files

Upload the **contents** of `website/` into the domain's web folder (usually `public_html`), keeping the folder structure. Make sure the hidden `.htaccess` files are uploaded too (in the root and in `api/`, `includes/`, `lib/`, `storage/` and `uploads/`); some FTP programs and file managers hide files starting with a dot.

If you're moving the existing site and want to keep the CVs, copy the old `uploads/` files across as well (keep the new `uploads/.htaccess`).

## 3. Configuration

In the web folder, copy `config.sample.php` to `config.php` and fill in every value:

- SMTP details (Brevo) for admin emails
- the database name, user and password from step 1
- Razorpay key, key secret and webhook secret
- `VNC_ROOTS_SECRET` from VNC Roots (Settings → Website donations)
- `FORWARD_RETRY_KEY`: any random string of 24+ characters; keep it private
- `SITE_URL`: the site's address, e.g. `https://vncindia.org`
- `DMS_ENABLED` is `false` in the sample. Set it to `true` (and fill in `DMS_API_KEY`) only if the old DMS should still receive payments.

## 4. Folder permissions

PHP must be able to write to `storage/` (logs and the rate limiter) and `uploads/` (CVs). On most shared hosting this works as-is. If forms fail with an error, set both folders to 755 (or 775), owned by the hosting account user.

## 5. External services

- **Razorpay** (Dashboard → Settings → Webhooks): add or update the webhook URL to `https://YOUR-DOMAIN/api/webhook.php`, event **payment.captured**, with the same secret as `RZP_WEBHOOK_SECRET`.
- **VNC Roots**: ask VNC to add the new server's IP address to the allowed list (shown in the hosting panel). Without it every payment is refused with a 403.
- **Domain**: point the domain's DNS to the new server and install the SSL certificate (most panels offer free Let's Encrypt).

## 6. Check it's working

Pages: open the home page, `/about`, `/donate`, `/get-involved` and `/contact`.

Each of these must show **403 Forbidden**, never the file. If any shows content, `.htaccess` isn't active; ask the host to enable it.

- `/config.php`
- `/lib/settings.php`
- `/storage/`
- `/uploads/`
- `/PHPMailer/PHPMailer.php`

Payments: make a ₹10 donation with your own details. Within a minute or two, `https://YOUR-DOMAIN/api/retry_forwards.php?key=YOUR_RETRY_KEY` should show `roots: done`, and the donation should appear in VNC Roots with the receipt arriving by email.

Forms: send a test message from the contact page and check the admin email arrives.

## 7. Automatic retries (recommended)

If VNC Roots is unavailable when someone pays, the payment waits in a queue. With cron on the server, add this job every 15 minutes:

```
*/15 * * * * curl -fsS "https://YOUR-DOMAIN/api/retry_forwards.php?key=YOUR_RETRY_KEY" > /dev/null
```

Without cron, create the same request as a free job at cron-job.org. (Without either, retries still happen whenever someone pays or opens a payment page.)

## Settings you may want to change later

All in `website/lib/settings.php`:

- membership plans, fees and which are shown (the Student plan is hidden: set its `'enabled'` to `true` to show it; names and fees must match VNC Roots exactly)
- minimum and maximum donation amounts
- the Monthly donations tab (keep it off until Razorpay Subscriptions are built)

## nginx instead of Apache

nginx ignores `.htaccess`, so the same rules must go in the server block:

```nginx
root /path/to/website;
index index.php;
error_page 404 /404.php;

location ~ ^/(lib|storage|uploads|PHPMailer)/        { deny all; }
location ~ ^/includes/.*\.php$                        { deny all; }
location ~ /\.                                        { deny all; }
location ~ ^/(config|config\.sample)\.php$            { deny all; }
location ~ \.(log|sql|md|bak|ini|lock)$               { deny all; }

location / { try_files $uri $uri/ $uri.php?$args =404; }

location ~ \.php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/run/php/php8.2-fpm.sock;   # adjust to your PHP-FPM socket
}

add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options SAMEORIGIN always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
```
