# 🚀 cPanel Installation Guide for Earnify

## Step-by-Step Installation on cPanel

### Step 1: Create MySQL Database

1. Login to your **cPanel**
2. Go to **MySQL® Databases**
3. Create a new database:
   - Database Name: `earnify` (it will become `username_earnify`)
   - Click **Create Database**

### Step 2: Create Database User

1. Scroll down to **MySQL Users**
2. Create a new user:
   - Username: `earnify` (it will become `username_earnify`)
   - Password: Create a strong password
   - Click **Create User**

### Step 3: Add User to Database

1. Scroll down to **Add User To Database**
2. Select:
   - User: `username_earnify`
   - Database: `username_earnify`
3. Click **Add**
4. On privileges page, select **ALL PRIVILEGES**
5. Click **Make Changes**

### Step 4: Upload Files

1. Go to **File Manager** in cPanel
2. Navigate to `public_html` (or your domain folder)
3. Create folder: `earnify`
4. Upload all Earnify files to this folder
5. Extract if uploaded as ZIP

### Step 5: Run Installation

1. Open browser and go to: `https://yourdomain.com/earnify/install/`
2. Fill in the form with these details:

**Database Configuration:**
- **Database Host:** `localhost`
- **Database Username:** `username_earnify` (your full cPanel database username)
- **Database Password:** (the password you created in Step 2)
- **Database Name:** `username_earnify` (your full cPanel database name)

**Bot Configuration:**
- **Telegram Bot Token:** Get from [@BotFather](https://t.me/BotFather)
- **Admin Telegram ID:** Get from [@userinfobot](https://t.me/userinfobot)
- **Base URL:** `https://yourdomain.com/earnify`

3. Click **Install Earnify**

### Step 6: Set Webhook

After successful installation, visit this URL in your browser:

```
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=https://yourdomain.com/earnify/bot/webhook.php
```

Replace `<YOUR_BOT_TOKEN>` with your actual bot token.

You should see:
```json
{"ok":true,"result":true,"description":"Webhook was set"}
```

### Step 7: Security

**IMPORTANT:** Delete the `/install` folder:
1. Go to File Manager
2. Navigate to `public_html/earnify/`
3. Delete the `install` folder

### Step 8: Test Your Bot

1. Open Telegram
2. Search for your bot
3. Send `/start`
4. You should see the button menu

### Step 9: Access Admin Panel

1. Go to: `https://yourdomain.com/earnify/admin/`
2. Login with:
   - Username: `admin`
   - Password: `admin123`
3. **Change password immediately!**

## Common Issues & Solutions

### Issue: "Access denied for user"
**Solution:** Make sure you're using the FULL database username (e.g., `username_earnify`, not just `earnify`)

### Issue: "Database not found"
**Solution:** Use the FULL database name from cPanel (e.g., `username_earnify`)

### Issue: "Webhook not set"
**Solution:** 
- Ensure your domain has SSL (HTTPS required)
- Check bot token is correct
- Verify webhook URL is accessible

### Issue: "Bot not responding"
**Solution:**
- Check webhook is set correctly
- Verify file permissions (644 for files, 755 for folders)
- Check error logs in cPanel

## Finding Your Database Details

In cPanel, your database details are:
- **Database Name:** `cpanel_username_earnify`
- **Database User:** `cpanel_username_earnify`
- **Database Host:** `localhost`

Example: If your cPanel username is `john123`, then:
- Database Name: `john123_earnify`
- Database User: `john123_earnify`

## Support

If you encounter issues:
1. Check cPanel error logs
2. Verify all database credentials
3. Ensure PHP version is 8.x
4. Check file permissions

---

**Note:** The installation script has been updated to work seamlessly with cPanel's database restrictions.
