# Atualizar sistema
sudo apt update && sudo apt upgrade -y
# Instalar dependências
sudo apt install -y mysql-server php8.1-fpm php8.1-mysql php8.1-cli nginx git curl
# Instalar Elixir/Erlang
sudo apt install -y erlang elixir# Criar banco de dados
sudo mysql -u root -pNo MySQL:
CREATE DATABASE chat_online CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'chat_user'@'localhost' IDENTIFIED BY 'sua_senha_segura';
GRANT ALL PRIVILEGES ON chat_online.* TO 'chat_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;# Importar schema
mysql -u chat_user -p chat_online < database/schema.sqlEdite /var/www/chat_online/php-api/config.php:
define('DB_HOST', 'localhost');
define('DB_NAME', 'chat_online');
define('DB_USER', 'chat_user');
define('DB_PASS', 'sua_senha_segura');cd /var/www/chat_online/elixir-chat
# Instalar dependências
mix deps.get
# Compilar
MIX_ENV=prod mix compile
# Gerar secret key
SECRET_KEY_BASE=$(mix phx.gen.secret)
echo "export SECRET_KEY_BASE=$SECRET_KEY_BASE" >> ~/.bashrcEdite config/prod.exs com as credenciais do MySQL.
sudo cp nginx.conf /etc/nginx/sites-available/chat_online
sudo ln -s /etc/nginx/sites-available/chat_online /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginxCrie /etc/systemd/system/chat_online.service:
[Unit]
Description=Chat Online Phoenix Server
After=network.target mysql.service
[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/chat_online/elixir-chat
Environment=MIX_ENV=prod
Environment=PORT=4000
Environment="SECRET_KEY_BASE=cole_aqui_o_secret_key_gerado"
ExecStart=/usr/local/bin/mix phx.server
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable chat_online
sudo systemctl start chat_online
sudo systemctl status chat_onlinesudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable- Acesse
http://seu-ipno navegador - Verifique logs:
sudo journalctl -u chat_online -f - Verifique Nginx:
sudo tail -f /var/log/nginx/error.log
- PHP 8.x
- MySQL
- Elixir 1.15+
- Node.js (opcional)
- Banco de dados:
mysql -u root -p < database/schema.sql-
Configurar PHP: Edite
php-api/config.phpcom suas credenciais. -
Configurar Phoenix: Edite
elixir-chat/config/dev.exscom suas credenciais. -
Iniciar servidores:
Terminal 1 (PHP):
cd php-api
php -S localhost:8000Terminal 2 (Phoenix):
cd elixir-chat
mix deps.get
mix phx.serverTerminal 3 (Frontend):
cd public
python3 -m http.server 8080Acesse: http://localhost:8080
# Verificar logs
sudo journalctl -u chat_online -n 50
# Verificar se porta está em uso
sudo netstat -tlnp | grep 4000
# Reiniciar serviço
sudo systemctl restart chat_online# Verificar PHP-FPM
sudo systemctl status php8.1-fpm
# Verificar logs Nginx
sudo tail -f /var/log/nginx/error.log- Verifique se Nginx está fazendo proxy corretamente
- Verifique se Phoenix está rodando na porta 4000
- Abra console do navegador (F12) para ver erros