# Ubuntu Sunucu Kurulum Rehberi

## 🚀 Bot'u Ubuntu Sunucuda Çalıştırma

### Senaryo 1: Bot'u Windows'ta Çalıştırma (Önerilen)

Eğer veritabanınız Windows XAMPP'ta ise, bot'u da Windows'ta çalıştırın:

1. **Windows'ta bot klasörüne gidin:**
```cmd
cd C:\XAMPP\XAMPP\htdocs\oyunsloty\bot
```

2. **Gerekli Python paketlerini yükleyin:**
```cmd
pip install python-telegram-bot pymysql
```

3. **Bot'u başlatın:**
```cmd
python bot.py
```

### Senaryo 2: Veritabanını Ubuntu'ya Taşıma

#### 1. Ubuntu'da MySQL Kurulumu
```bash
sudo apt update
sudo apt install mysql-server python3-pip
sudo mysql_secure_installation
```

#### 2. MySQL'e Root Erişimi
```bash
sudo mysql
```

MySQL içinde:
```sql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
FLUSH PRIVILEGES;
EXIT;
```

#### 3. Veritabanını Windows'tan Export Etme
Windows'ta phpMyAdmin'e gidin ve:
1. `slot_game` veritabanını seçin
2. "Export" sekmesine tıklayın
3. "Go" butonuna basın
4. SQL dosyasını kaydedin

#### 4. Ubuntu'da Veritabanını Import Etme
```bash
# Veritabanı oluştur
mysql -u root -e "CREATE DATABASE slot_game;"

# SQL dosyasını import et (dosyayı önce sunucuya yükleyin)
mysql -u root slot_game < slot_game.sql
```

#### 5. Bot Dosyalarını Ubuntu'ya Kopyalama
```bash
cd /var/www/html
mkdir -p bot
cd bot
```

Dosyaları kopyalayın:
- `bot.py`
- `config.json`

#### 6. Python Bağımlılıklarını Yükleme
```bash
pip3 install python-telegram-bot pymysql
```

#### 7. Bot'u Çalıştırma
```bash
python3 bot.py
```

### Senaryo 3: Uzak Veritabanı Bağlantısı (Gelişmiş)

Windows'taki MySQL'e uzaktan bağlanmak için:

1. **Windows'ta MySQL'i dış bağlantılara aç:**
   - XAMPP Control Panel'den MySQL Config → my.ini
   - `bind-address = 127.0.0.1` satırını `bind-address = 0.0.0.0` yapın
   - MySQL'i yeniden başlatın

2. **Windows Firewall'da 3306 portunu açın**

3. **MySQL'de uzak kullanıcı oluşturun:**
```sql
CREATE USER 'botuser'@'%' IDENTIFIED BY 'güçlü_şifre';
GRANT ALL PRIVILEGES ON slot_game.* TO 'botuser'@'%';
FLUSH PRIVILEGES;
```

4. **Bot config.json'u güncelleyin:**
```json
"database": {
    "host": "WINDOWS_IP_ADRESI",
    "user": "botuser",
    "password": "güçlü_şifre",
    "database": "slot_game",
    "charset": "utf8mb4"
}
```

## 🔧 Sorun Giderme

### Bot başlamıyor
```bash
# Log'ları kontrol edin
python3 bot.py 2>&1 | tee bot.log
```

### Veritabanı bağlantı hatası
```bash
# MySQL'in çalıştığını kontrol edin
sudo systemctl status mysql

# Port'un açık olduğunu kontrol edin
netstat -an | grep 3306
```

### Permission hatası
```bash
# Bot dosyalarına izin verin
chmod +x bot.py
```

## 📝 Systemd Servisi Oluşturma (Opsiyonel)

Bot'un otomatik başlaması için:

1. **Servis dosyası oluşturun:**
```bash
sudo nano /etc/systemd/system/papiplay-bot.service
```

2. **İçeriği ekleyin:**
```ini
[Unit]
Description=Papiplay Telegram Bot
After=network.target mysql.service

[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/html/bot
ExecStart=/usr/bin/python3 /var/www/html/bot/bot.py
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
```

3. **Servisi başlatın:**
```bash
sudo systemctl daemon-reload
sudo systemctl enable papiplay-bot
sudo systemctl start papiplay-bot
sudo systemctl status papiplay-bot
```

## 🎯 Önerilen Çözüm

**En kolay yol:** Bot'u Windows'ta çalıştırın çünkü veritabanınız zaten orada. Ubuntu sunucunuz sadece web sitesini servis etsin. 