# WAMP Server Setup for IFRAP Multi-Tenant

## Step 1: Install WAMP

Download from: https://www.wampserver.com/

Choose: **WampServer 64 bit** (latest version)

Install kar:
1. Next → Next → Choose folder (default: `C:\wamp64`)
2. Choose default port: **80**
3. Choose text editor: Notepad
4. Install complete

Start WAMP → Tray icon me wala run ho.

---

## Step 2: Configure Hosts File

**Open File:** `C:\Windows\System32\drivers\etc\hosts`

Right-click → Edit with Notepad (as Administrator)

Add these lines at end:
```
127.0.0.1 dev.ifrap.com
127.0.0.1 dev.localtenant.com
127.0.0.1 test.localtenant.com
127.0.0.1 staging.localtenant.com
```

Save (Ctrl+S) and close.

Flush DNS:
```bash
ipconfig /flushdns
```

---

## Step 3: Place Project Files

Extract IFRAP project folder to:
```
C:\wamp64\www\IFRAP
```

So you have:
```
C:\wamp64\www\IFRAP\
  ├── app/
  ├── config/
  ├── public/
  ├── .env
  ├── artisan
  └── ...
```

---

## Step 4: Configure Apache Virtual Host

**Open File:** `C:\wamp64\bin\apache\apache2.4.x\conf\extra\httpd-vhosts.conf`

(Right-click WAMP tray → Apache → httpd-vhosts.conf)

**Clear existing content** or **go to end** and add:

```apache
<VirtualHost *:80>
    ServerName dev.ifrap.com
    ServerAlias *.localtenant.com localhost
    DocumentRoot "C:/wamp64/www/IFRAP/public"

    <Directory "C:/wamp64/www/IFRAP/public">
        AllowOverride All
        Require all granted
        
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^ index.php [QSA,L]
        </IfModule>
    </Directory>

    ErrorLog "logs/ifrap-error.log"
    CustomLog "logs/ifrap-access.log" combined
</VirtualHost>
```

Save and close.

---

## Step 5: Enable Mod Rewrite

WAMP tray → Apache → Apache Modules

Check if `rewrite_module` is **enabled** (checkbox checked).

If not checked → Click to enable.

---

## Step 6: Restart Apache

WAMP tray → Apache → Restart All Services

Wait for tray icon to turn **green** (all services running).

---

## Step 7: PHP Configuration

WAMP tray → PHP → php.ini

Edit these settings (find and change):

```ini
memory_limit = 512M
post_max_size = 100M
upload_max_filesize = 100M
max_execution_time = 300
```

Save and close.

Restart Apache again.

---

## Step 8: Laravel Setup

Open CMD/PowerShell and navigate:

```bash
cd C:\wamp64\www\IFRAP
```

Install dependencies:
```bash
composer install
```

Generate key:
```bash
php artisan key:generate
```

Create .env (copy from .env.example):
```bash
copy .env.example .env
```

---

## Step 9: Configure .env

Edit: `C:\wamp64\www\IFRAP\.env`

Set these values:

```env
APP_NAME="IFRAP"
APP_URL=http://dev.ifrap.com
APP_ENV=local
APP_DEBUG=true

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=ifrap_central
DB_USERNAME=root
DB_PASSWORD=

CENTRAL_DOMAINS=dev.ifrap.com,localhost,127.0.0.1
TENANT_DOMAIN_EXPECTED_HOST=dev.ifrap.com
TENANT_DOMAIN_TARGETS=dev.ifrap.com,127.0.0.1
```

---

## Step 10: Setup Database

WAMP tray → MySQL → MySQL Console

Or open phpMyAdmin:
```
http://localhost/phpmyadmin
```

Create database:
```sql
CREATE DATABASE ifrap_central CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```

---

## Step 11: Run Migrations

In CMD/PowerShell:

```bash
cd C:\wamp64\www\IFRAP
php artisan migrate
php artisan optimize:clear
```

---

## Step 12: Test Setup

Browser mein open karo:

```
http://dev.ifrap.com
```

You should see login page or dashboard.

---

## Step 13: Add Test Domain

1. Login
2. Go to: `/tenants/projects/{project-slug}/settings`
3. Click: **Tenant Domain** tab
4. **Add Domain:** `dev.localtenant.com`
5. Click: **+ Add Domain**

Domain will be added and attached automatically (local domains auto-verify).

---

## Step 14: Test Multi-Tenant

Open in browser:

```
http://dev.localtenant.com
```

You should see the **same tenant project theme** load (not central admin).

If you see wrong theme:
```bash
php artisan optimize:clear
php artisan cache:clear
```

Then refresh browser.

---

## Troubleshooting

**"Forbidden" error or blank page?**
- Check hosts file saved correctly
- Flush DNS: `ipconfig /flushdns`
- Restart WAMP
- Check folder path is `C:\wamp64\www\IFRAP\public`

**"Class not found" or "autoload" error?**
```bash
composer install
php artisan optimize:clear
```

**Database connection error?**
- Check phpMyAdmin works: `http://localhost/phpmyadmin`
- Check DB_USERNAME/PASSWORD in .env
- Run migration again

**Domain not resolving?**
- Ping test: Open CMD → `ping dev.ifrap.com`
- Should return: `Pinging dev.ifrap.com [127.0.0.1]`
- If not, edit hosts file again (save as Admin)

**Apache won't restart?**
- Close other applications using port 80
- Or change vhost port to 8080 and use: `http://dev.ifrap.com:8080`

---

## Adding More Domains Later

Just edit hosts file and add:
```
127.0.0.1 mynewdomain.localtenant.com
```

Flush DNS, then add in panel. Auto-attach ho jayega!

---

## Team Sharing

Share this .env with team (database details match everyone):
```env
APP_URL=http://dev.ifrap.com
CENTRAL_DOMAINS=dev.ifrap.com,localhost,127.0.0.1
TENANT_DOMAIN_EXPECTED_HOST=dev.ifrap.com
TENANT_DOMAIN_TARGETS=dev.ifrap.com,127.0.0.1
```

Everyone follow same hosts + vhost setup, phir same .env use karo.
