# Deploying Rishta Website on Namecheap Shared Hosting

This guide will help you deploy your rishta website on Namecheap shared hosting step by step.

## Prerequisites

- Namecheap shared hosting account
- Domain name (optional, can use temporary URL)
- FTP client (FileZilla recommended) or cPanel File Manager
- phpMyAdmin access

## Step 1: Access Your Namecheap cPanel

1. Log in to your Namecheap account
2. Go to **Hosting List** 
3. Click **Manage** next to your hosting package
4. Click **cPanel** button to access your hosting control panel

## Step 2: Create MySQL Database

1. In cPanel, find **Databases** section
2. Click **MySQL Database Wizard**
3. **Step 1: Create a Database**
   - Enter database name (e.g., `rishta_db`)
   - Click **Next Step**
4. **Step 2: Create Database Users**
   - Enter username (e.g., `rishta_user`)
   - Enter a strong password
   - Click **Create User**
5. **Step 3: Add User to Database**
   - Select the user and database you just created
   - Check **ALL PRIVILEGES**
   - Click **Make Changes**
6. Note down the following information:
   - Database Name: `yourusername_rishta_db`
   - Database Username: `yourusername_rishta_user`
   - Database Password: (the password you created)
   - Database Host: `localhost` (usually)

## Step 3: Import Database Schema

1. In cPanel, go to **Databases** section
2. Click **phpMyAdmin**
3. Select your database from the left sidebar
4. Click **Import** tab
5. Click **Choose File** and select `database.sql` from your computer
6. Click **Go** at the bottom
7. You should see "Import has been successfully finished"

## Step 4: Upload Files

### Option A: Using FileZilla (Recommended)

1. Open FileZilla
2. Get your FTP credentials from cPanel:
   - In cPanel, go to **Files** → **FTP Accounts**
   - Find your main FTP account or create a new one
   - Note down the FTP Host, Username, and Password
3. In FileZilla:
   - Host: your domain name or server IP
   - Username: your FTP username
   - Password: your FTP password
   - Port: 21
4. Click **Quickconnect**
5. Navigate to `public_html` folder (this is your website root)
6. Upload all files from your local `rishta` folder to `public_html`
7. Make sure to upload:
   - All PHP files
   - `css/` folder
   - `js/` folder
   - `.htaccess` file

### Option B: Using cPanel File Manager

1. In cPanel, go to **Files** → **File Manager**
2. Navigate to `public_html` folder
3. Click **Upload** at the top
4. Upload all files one by one or zip them first:
   - Zip all your files locally
   - Upload the zip file
   - Right-click the zip file and select **Extract**
5. Ensure `.htaccess` is uploaded (it might be hidden)

## Step 5: Create Upload Directories

1. In cPanel File Manager, navigate to `public_html`
2. Create two new folders:
   - `uploads`
   - Inside `uploads`, create: `photos` and `payments`
3. Set proper permissions:
   - Right-click `uploads` folder → **Change Permissions**
   - Set permissions to **755** (or **777** if 755 doesn't work)
   - Do the same for `uploads/photos` and `uploads/payments`

## Step 6: Update Configuration File

1. In cPanel File Manager, right-click `config.php`
2. Select **Edit**
3. Update the database credentials:

```php
<?php
// Database Configuration
define('DB_HOST', 'localhost'); // Usually localhost on shared hosting
define('DB_USER', 'yourusername_rishta_user'); // Your actual database username
define('DB_PASS', 'your_actual_password'); // Your actual database password
define('DB_NAME', 'yourusername_rishta_db'); // Your actual database name

// The rest remains the same...
```

4. Update BASE_URL to your domain:

```php
// Base URL
define('BASE_URL', 'https://yourdomain.com');
// Or if using temporary URL:
// define('BASE_URL', 'https://serverIP/~username');
```

5. Click **Save Changes**

## Step 7: Test Your Website

1. Open your browser
2. Go to your domain name (e.g., `https://yourdomain.com`)
3. You should see the rishta homepage

## Step 8: Access Admin Panel

1. Go to `https://yourdomain.com/admin-login.php`
2. Login with:
   - Username: `admin`
   - Password: `admin123`
3. **IMPORTANT**: Change the default password immediately!

## Step 9: Change Admin Password (Security)

### Method 1: Through Database

1. Go to phpMyAdmin in cPanel
2. Select your database
3. Click on `admins` table
4. Click **Edit** next to the admin user
5. Generate a new password hash using this PHP code:
   ```php
   <?php
   echo password_hash('your_new_password', PASSWORD_DEFAULT);
   ?>
   ```
6. Copy the hash and paste it in the `password` field
7. Click **Go** to save

### Method 2: Create a PHP file temporarily

1. Create `change_password.php` in your hosting:
   ```php
   <?php
   require_once 'config.php';
   $new_password = 'your_new_password';
   $hashed = password_hash($new_password, PASSWORD_DEFAULT);
   $stmt = $conn->prepare("UPDATE admins SET password = ? WHERE username = 'admin'");
   $stmt->bind_param("s", $hashed);
   $stmt->execute();
   echo "Password changed successfully!";
   ?>
   ```
2. Access `https://yourdomain.com/change_password.php`
3. Delete this file after changing the password

## Step 10: Configure SSL (HTTPS)

Namecheap shared hosting usually includes free SSL:

1. In cPanel, go to **Security** → **SSL/TLS Status**
2. Find your domain and click **Run AutoSSL**
3. Wait for SSL to be installed (usually a few minutes)
4. Force HTTPS by editing `.htaccess`:
   ```apache
   RewriteEngine On
   RewriteCond %{HTTPS} off
   RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
   ```

## Step 11: Test All Features

1. **User Registration**: Try registering a new account
2. **User Login**: Login with the new account
3. **Post Listing**: Try posting a listing with photo and payment slip
4. **Admin Panel**: Login as admin and approve the listing
5. **View Listings**: Check if approved listings appear on homepage
6. **Filters**: Test all filter options
7. **Contact Protection**: Verify contact numbers are hidden for non-logged-in users

## Common Issues & Solutions

### Issue: Database Connection Error

**Solution:**
- Verify database credentials in `config.php`
- Ensure database user has all privileges
- Check database name format (usually `username_databasename`)

### Issue: File Upload Not Working

**Solution:**
- Check folder permissions (755 or 777)
- Verify upload directories exist
- Check PHP upload limits in cPanel → **Select PHP Version** → **Switch to PHP Options**
  - Set `upload_max_filesize` to 5M or higher
  - Set `post_max_size` to 5M or higher

### Issue: 500 Internal Server Error

**Solution:**
- Check `.htaccess` file syntax
- Verify PHP version (PHP 7.4+ recommended)
- Check error logs in cPanel → **Metrics** → **Errors**

### Issue: Images Not Displaying

**Solution:**
- Verify image paths in database
- Check if images are uploaded to correct folders
- Ensure folder permissions allow reading

### Issue: Session Not Working

**Solution:**
- Check PHP session configuration
- Ensure session directory is writable
- Try clearing browser cookies

## Security Recommendations

1. **Delete test files**: Remove any test files you created
2. **Strong passwords**: Use strong passwords for database and admin
3. **Regular backups**: Set up automatic backups in cPanel
4. **Keep updated**: Keep PHP and MySQL updated
5. **Monitor logs**: Regularly check error and access logs
6. **Limit login attempts**: Consider adding rate limiting
7. **Use HTTPS**: Always enforce HTTPS

## Performance Optimization

1. **Enable caching**: The `.htaccess` already includes caching rules
2. **Optimize images**: Compress images before uploading
3. **Database optimization**: Run `OPTIMIZE TABLE` commands periodically
4. **CDN**: Consider using Cloudflare (free) for CDN and DDoS protection

## Backup Strategy

### Automatic Backups (Namecheap)

1. In cPanel, go to **Files** → **Backup**
2. Configure automatic backups (daily, weekly, monthly)
3. Download backups periodically to your computer

### Manual Backup

1. **Database Backup**:
   - Go to phpMyAdmin
   - Select your database
   - Click **Export**
   - Choose **Quick** export method
   - Click **Go**

2. **Files Backup**:
   - Use FileZilla to download all files
   - Or use cPanel → **Backup** → **Download a Full Website Backup**

## Domain Configuration (If Using Custom Domain)

1. In Namecheap dashboard, go to **Domain List**
2. Click **Manage** next to your domain
3. Go to **DNS** section
4. Point A record to your hosting IP (provided by Namecheap)
5. Wait for DNS propagation (up to 48 hours, usually 1-2 hours)

## Support Resources

- **Namecheap Knowledgebase**: https://www.namecheap.com/support/knowledgebase/
- **cPanel Documentation**: https://docs.cpanel.net/
- **PHP Documentation**: https://www.php.net/docs.php

## Quick Reference

**cPanel Login**: `yourdomain.com/cpanel`
**phpMyAdmin**: cPanel → Databases → phpMyAdmin
**File Manager**: cPanel → Files → File Manager
**FTP Host**: `yourdomain.com` or server IP
**Database Host**: `localhost`

## Post-Deployment Checklist

- [ ] Database imported successfully
- [ ] All files uploaded to public_html
- [ ] Upload directories created with proper permissions
- [ ] config.php updated with correct credentials
- [ ] Website loads in browser
- [ ] User registration works
- [ ] User login works
- [ ] Post listing works with file uploads
- [ ] Admin panel accessible
- [ ] Admin password changed
- [ ] SSL/HTTPS configured
- [ ] All filters working
- [ ] Contact protection working
- [ ] Backup configured
- [ ] Security measures implemented

---

**Congratulations!** Your rishta website is now live on Namecheap shared hosting.
