359 lines
8.1 KiB
Markdown
359 lines
8.1 KiB
Markdown
# 🚀 Guía de Despliegue en Servidor
|
|
|
|
## 📋 Requisitos del Servidor
|
|
|
|
### Mínimos
|
|
- **PHP**: 8.0 o superior
|
|
- **MySQL/MariaDB**: 5.7 o superior
|
|
- **Servidor Web**: Apache/Nginx
|
|
- **SSL**: Certificado válido (HTTPS obligatorio para WhatsApp)
|
|
- **Memoria RAM**: Mínimo 512MB
|
|
- **Espacio**: 1GB libre
|
|
|
|
### Extensiones PHP Requeridas
|
|
```bash
|
|
php-pdo
|
|
php-pdo-mysql
|
|
php-curl
|
|
php-json
|
|
php-mbstring
|
|
php-openssl
|
|
```
|
|
|
|
## 🌍 Configuración por Tipo de Servidor
|
|
|
|
### 🔹 **VPS/Servidor Dedicado (Ubuntu/CentOS)**
|
|
|
|
#### 1. Instalar Dependencias
|
|
```bash
|
|
# Ubuntu/Debian
|
|
sudo apt update
|
|
sudo apt install apache2 mysql-server php8.0 php8.0-mysql php8.0-curl php8.0-json php8.0-mbstring
|
|
|
|
# CentOS/RHEL
|
|
sudo yum install httpd mysql-server php php-mysql php-curl php-json php-mbstring
|
|
```
|
|
|
|
#### 2. Configurar Apache
|
|
```apache
|
|
# /etc/apache2/sites-available/whatsapp-bot.conf
|
|
<VirtualHost *:80>
|
|
ServerName tudominio.com
|
|
DocumentRoot /var/www/html/bot
|
|
|
|
<Directory /var/www/html/bot>
|
|
AllowOverride All
|
|
Require all granted
|
|
</Directory>
|
|
|
|
# Redirigir HTTP a HTTPS
|
|
RewriteEngine On
|
|
RewriteCond %{HTTPS} off
|
|
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
|
|
</VirtualHost>
|
|
|
|
<VirtualHost *:443>
|
|
ServerName tudominio.com
|
|
DocumentRoot /var/www/html/migrador
|
|
|
|
SSLEngine on
|
|
SSLCertificateFile /path/to/your/certificate.crt
|
|
SSLCertificateKeyFile /path/to/your/private.key
|
|
|
|
<Directory /var/www/html/migrador>
|
|
AllowOverride All
|
|
Require all granted
|
|
</Directory>
|
|
</VirtualHost>
|
|
```
|
|
|
|
#### 3. Subir Archivos
|
|
```bash
|
|
# Crear directorio
|
|
sudo mkdir -p /var/www/html/migrador
|
|
|
|
# Subir archivos (usando SCP/SFTP)
|
|
scp -r bot/* usuario@servidor:/var/www/html/bot/
|
|
|
|
# Configurar permisos
|
|
sudo chown -R www-data:www-data /var/www/html/bot
|
|
sudo chmod -R 755 /var/www/html/bot
|
|
```
|
|
|
|
### 🔹 **Hosting Compartido (cPanel/Plesk)**
|
|
|
|
#### 1. Subir Archivos
|
|
- Accede a tu **File Manager** en cPanel
|
|
- Ve a la carpeta `public_html`
|
|
- Crea carpeta `migrador` (o sube directamente a raíz)
|
|
- Sube todos los archivos del proyecto
|
|
|
|
#### 2. Configurar Base de Datos
|
|
- Ve a **MySQL Databases** en cPanel
|
|
- Crea nueva base de datos: `tuusuario_whatsapp`
|
|
- Crea usuario y asigna privilegios
|
|
- Anota: host, usuario, contraseña, base de datos
|
|
|
|
#### 3. Editar Configuración
|
|
```php
|
|
// config/config.php
|
|
define('DB_HOST', 'localhost'); // O tu host específico
|
|
define('DB_NAME', 'tuusuario_whatsapp');
|
|
define('DB_USER', 'tuusuario_dbuser');
|
|
define('DB_PASS', 'tu_password_db');
|
|
```
|
|
|
|
### 🔹 **Servicios en la Nube**
|
|
|
|
#### **AWS EC2**
|
|
```bash
|
|
# 1. Conectar por SSH
|
|
ssh -i tu-clave.pem ec2-user@tu-ip-publica
|
|
|
|
# 2. Instalar LAMP stack
|
|
sudo yum update -y
|
|
sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2
|
|
|
|
# 3. Configurar y seguir pasos de VPS
|
|
```
|
|
|
|
#### **DigitalOcean Droplet**
|
|
```bash
|
|
# 1. Crear droplet con LAMP stack preinstalado
|
|
# 2. Conectar por SSH
|
|
# 3. Subir archivos a /var/www/html/
|
|
```
|
|
|
|
#### **Google Cloud Platform**
|
|
```bash
|
|
# 1. Crear VM con Ubuntu
|
|
# 2. Instalar LAMP stack
|
|
# 3. Configurar firewall para puertos 80/443
|
|
```
|
|
|
|
## 🔧 Configuración Específica del Sistema
|
|
|
|
### 1. Editar config/config.php
|
|
```php
|
|
<?php
|
|
// === CONFIGURACIÓN DE PRODUCCIÓN ===
|
|
|
|
// Base de datos de producción
|
|
define('DB_HOST', 'tu-servidor-mysql');
|
|
define('DB_NAME', 'whatsapp_production');
|
|
define('DB_USER', 'tu_usuario_db');
|
|
define('DB_PASS', 'password_super_seguro');
|
|
|
|
// URL de producción
|
|
define('APP_URL', 'https://tudominio.com/migrador');
|
|
|
|
// Deshabilitar errores en producción
|
|
error_reporting(0);
|
|
ini_set('display_errors', 0);
|
|
ini_set('log_errors', 1);
|
|
|
|
// Configuración de seguridad
|
|
define('SECURE_MODE', true);
|
|
?>
|
|
```
|
|
|
|
### 2. Crear .htaccess (Apache)
|
|
```apache
|
|
# .htaccess en raíz del proyecto
|
|
RewriteEngine On
|
|
|
|
# Forzar HTTPS
|
|
RewriteCond %{HTTPS} off
|
|
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
|
|
|
|
# Proteger archivos sensibles
|
|
<Files "config.php">
|
|
Require all denied
|
|
</Files>
|
|
|
|
<Files "*.sql">
|
|
Require all denied
|
|
</Files>
|
|
|
|
# Cache headers
|
|
<IfModule mod_expires.c>
|
|
ExpiresActive on
|
|
ExpiresByType text/css "access plus 1 year"
|
|
ExpiresByType application/javascript "access plus 1 year"
|
|
ExpiresByType image/png "access plus 1 year"
|
|
ExpiresByType image/jpg "access plus 1 year"
|
|
</IfModule>
|
|
```
|
|
|
|
### 3. Configurar SSL (Let's Encrypt)
|
|
```bash
|
|
# Instalar Certbot
|
|
sudo apt install certbot python3-certbot-apache
|
|
|
|
# Obtener certificado
|
|
sudo certbot --apache -d tudominio.com
|
|
|
|
# Auto-renovación
|
|
sudo crontab -e
|
|
# Agregar: 0 12 * * * /usr/bin/certbot renew --quiet
|
|
```
|
|
|
|
## 🔗 Configuración de WhatsApp Webhook
|
|
|
|
### 1. URL del Webhook
|
|
```
|
|
https://tudominio.com/bot/api/webhook.php
|
|
```
|
|
|
|
### 2. Configurar en Facebook Developers
|
|
1. Ve a [developers.facebook.com](https://developers.facebook.com)
|
|
2. Selecciona tu app de WhatsApp Business
|
|
3. Ve a **WhatsApp > Configuration**
|
|
4. En **Webhooks**:
|
|
- **Callback URL**: `https://tudominio.com/migrador/api/webhook.php`
|
|
- **Verify Token**: `mi_token_secreto_123` (o cambia en config.php)
|
|
- **Webhook fields**: ✅ `conversations`
|
|
|
|
### 3. Verificar Webhook
|
|
```bash
|
|
# Probar webhook manualmente
|
|
curl -X GET "https://tudominio.com/migrador/api/webhook.php?hub.mode=subscribe&hub.challenge=CHALLENGE_ACCEPTED&hub.verify_token=mi_token_secreto_123"
|
|
```
|
|
|
|
## ⚙️ Configuración Post-Instalación
|
|
|
|
### 1. Ejecutar Instalador
|
|
```
|
|
https://tudominio.com/migrador/install.php
|
|
```
|
|
|
|
### 2. Verificar Sistema
|
|
```
|
|
https://tudominio.com/migrador/test.php
|
|
```
|
|
|
|
### 3. Configurar Panel
|
|
```
|
|
https://tudominio.com/migrador/index.php
|
|
```
|
|
|
|
## 🔒 Seguridad en Producción
|
|
|
|
### 1. Configuraciones PHP
|
|
```ini
|
|
# php.ini ajustes
|
|
expose_php = Off
|
|
display_errors = Off
|
|
log_errors = On
|
|
allow_url_fopen = Off
|
|
```
|
|
|
|
### 2. Permisos de Archivos
|
|
```bash
|
|
# Archivos: 644
|
|
sudo find /var/www/html/migrador -type f -exec chmod 644 {} \;
|
|
|
|
# Directorios: 755
|
|
sudo find /var/www/html/migrador -type d -exec chmod 755 {} \;
|
|
|
|
# Config solo lectura
|
|
sudo chmod 600 /var/www/html/migrador/config/config.php
|
|
```
|
|
|
|
### 3. Backup Automático
|
|
```bash
|
|
#!/bin/bash
|
|
# backup.sh
|
|
DATE=$(date +%Y%m%d_%H%M%S)
|
|
mysqldump -u usuario -p password whatsapp_db > /backups/whatsapp_$DATE.sql
|
|
tar -czf /backups/files_$DATE.tar.gz /var/www/html/migrador
|
|
```
|
|
|
|
## 📊 Monitoreo y Logs
|
|
|
|
### 1. Logs de Apache
|
|
```bash
|
|
tail -f /var/log/apache2/error.log
|
|
tail -f /var/log/apache2/access.log
|
|
```
|
|
|
|
### 2. Logs de PHP
|
|
```bash
|
|
tail -f /var/log/php_errors.log
|
|
```
|
|
|
|
### 3. Logs del Sistema
|
|
```bash
|
|
# Ver logs desde el panel
|
|
https://tudominio.com/migrador/index.php#logs
|
|
```
|
|
|
|
## 🚀 Optimizaciones de Rendimiento
|
|
|
|
### 1. Cache de PHP (OPcache)
|
|
```ini
|
|
# php.ini
|
|
opcache.enable=1
|
|
opcache.memory_consumption=128
|
|
opcache.max_accelerated_files=1000
|
|
```
|
|
|
|
### 2. Compresión GZIP
|
|
```apache
|
|
# En .htaccess
|
|
<IfModule mod_deflate.c>
|
|
AddOutputFilterByType DEFLATE text/plain
|
|
AddOutputFilterByType DEFLATE text/html
|
|
AddOutputFilterByType DEFLATE text/css
|
|
AddOutputFilterByType DEFLATE application/javascript
|
|
</IfModule>
|
|
```
|
|
|
|
### 3. Optimización MySQL
|
|
```sql
|
|
-- my.cnf
|
|
[mysqld]
|
|
innodb_buffer_pool_size = 256M
|
|
query_cache_type = 1
|
|
query_cache_size = 64M
|
|
```
|
|
|
|
## 📞 URLs de Producción
|
|
|
|
Una vez configurado:
|
|
|
|
- **🏠 Panel**: https://tudominio.com/migrador/index.php
|
|
- **🔗 API**: https://tudominio.com/migrador/api/
|
|
- **📱 Webhook**: https://tudominio.com/migrador/api/webhook.php
|
|
- **📊 Stats**: https://tudominio.com/migrador/api/get_stats.php
|
|
|
|
## ⚠️ Troubleshooting
|
|
|
|
### Error 500
|
|
- Revisar logs de Apache/PHP
|
|
- Verificar permisos de archivos
|
|
- Comprobar configuración de base de datos
|
|
|
|
### Webhook no funciona
|
|
- Verificar SSL válido
|
|
- Comprobar URL pública
|
|
- Revisar token de verificación
|
|
|
|
### Base de datos no conecta
|
|
- Verificar credenciales
|
|
- Comprobar host/puerto
|
|
- Revisar permisos de usuario MySQL
|
|
|
|
## 📝 Checklist Final
|
|
|
|
- [ ] ✅ Servidor con PHP 8.0+ y MySQL
|
|
- [ ] ✅ SSL/HTTPS configurado
|
|
- [ ] ✅ Archivos subidos con permisos correctos
|
|
- [ ] ✅ Base de datos creada y configurada
|
|
- [ ] ✅ config.php editado con datos reales
|
|
- [ ] ✅ Instalador ejecutado sin errores
|
|
- [ ] ✅ Webhook configurado en Facebook
|
|
- [ ] ✅ Sistema probado y funcionando
|
|
- [ ] ✅ Backup automático configurado
|
|
|
|
¡Tu sistema WhatsApp Bot Manager estará listo para producción! 🎉 |