# Ubuntu Sunucu Kurulum Rehberi

## 🚀 Adım 1: Veritabanını Windows'tan Export Et

1. Tarayıcıda açın:
   ```
   http://localhost/oyunsloty/export_database.php
   ```

2. SQL dosyasını indirin (örn: `slot_game_export_2024-01-31_15-30-45.sql`)

## 🖥️ Adım 2: Ubuntu Sunucuya Bağlanın

PuTTY'de:
```bash
ssh root@papiplay.net
```

## 📦 Adım 3: MySQL Kurulumu

```bash
# Sistem güncelleme
apt update && apt upgrade -y

# MySQL kurulumu
apt install mysql-server -y

# MySQL güvenlik ayarları
mysql_secure_installation
```

Sorulara cevaplar:
- VALIDATE PASSWORD component? **No**
- New password: **(boş bırakın veya güçlü şifre)**
- Remove anonymous users? **Yes**
- Disallow root login remotely? **Yes**
- Remove test database? **Yes**
- Reload privilege tables? **Yes**

## 🗄️ Adım 4: Veritabanı Oluşturma

```bash
# MySQL'e gir
mysql -u root

# Veritabanı oluştur
CREATE DATABASE slot_game CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

# Çık
EXIT;
```

## 📤 Adım 5: SQL Dosyasını Yükle

1. FileZilla veya WinSCP ile sunucuya bağlanın
2. SQL dosyasını `/root/` klasörüne yükleyin
3. PuTTY'de import edin:

```bash
# Import et
mysql -u root slot_game < /root/slot_game_export_*.sql

# Kontrol et
mysql -u root -e "USE slot_game; SHOW TABLES;"
```

## 🐍 Adım 6: Python ve Bot Kurulumu

```bash
# Python pip kurulumu
apt install python3-pip -y

# Bot klasörü oluştur
mkdir -p /var/www/html/bot
cd /var/www/html/bot

# Python paketleri
pip3 install python-telegram-bot pymysql
```

## 📁 Adım 7: Bot Dosyalarını Yükle

FileZilla ile şu dosyaları `/var/www/html/bot/` klasörüne yükleyin:
- `bot.py`
- `config.json`

## ⚙️ Adım 8: Config Ayarları

```bash
nano /var/www/html/bot/config.json
```

Değiştirin:
```json
"domain": "http://papiplay.net",
```

## 🤖 Adım 9: Bot'u Test Et

```bash
cd /var/www/html/bot
python3 bot.py
```

Bot çalışıyorsa:
- "✅ Veritabanı bağlantısı BAŞARILI!" göreceksiniz
- Telegram'da test edin: `/papiplay`
- **Ctrl+C** ile durdurun

## 🔧 Adım 10: Systemd Servisi

```bash
# Servis dosyası oluştur
nano /etc/systemd/system/papiplay-bot.service
```

İçeriği yapıştırın:
```ini
[Unit]
Description=Papiplay Telegram Bot
After=network.target mysql.service

[Service]
Type=simple
User=root
WorkingDirectory=/var/www/html/bot
ExecStart=/usr/bin/python3 /var/www/html/bot/bot.py
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
```

```bash
# Servisi başlat
systemctl daemon-reload
systemctl enable papiplay-bot
systemctl start papiplay-bot

# Durumu kontrol et
systemctl status papiplay-bot
```

## ✅ Adım 11: Final Test

1. Telegram grubunda `/papiplay` yazın
2. Gelen linke tıklayın
3. Oyunlara giriş yapın

## 🔍 Sorun Giderme

**Bot loglarını izle:**
```bash
journalctl -u papiplay-bot -f
```

**Bot'u yeniden başlat:**
```bash
systemctl restart papiplay-bot
```

**Veritabanı bağlantısını test et:**
```bash
mysql -u root -e "SELECT COUNT(*) FROM slot_game.users;"
```

## 💾 Veritabanı Güncelleme

Windows'ta geliştirme yaptıktan sonra:

1. `http://localhost/oyunsloty/export_database.php` ile export
2. FileZilla ile yükle
3. Ubuntu'da import:
   ```bash
   mysql -u root slot_game < /root/yeni_export.sql
   ```

## 🎉 Tebrikler!

Sisteminiz artık Ubuntu sunucuda çalışıyor. Bot ve veritabanı aynı sunucuda olduğu için sorunsuz çalışacak! 