3.9 KiB
3.9 KiB
Deployment Guide for Postaci
This guide outlines how to deploy the Postaci application on a Ubuntu server.
Prerequisites
- Ubuntu server (preferably 20.04 LTS or newer)
- Root or sudo access
- Domain name (optional but recommended for production)
Manual Deployment Steps
1. Server Setup
Connect to your server:
ssh root@your-server-ip
Update the system:
apt update && apt upgrade -y
Install required packages:
# Add NodeJS repository
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
# Install dependencies
apt install -y nodejs postgresql postgresql-contrib nginx git
2. Database Setup
Start and enable PostgreSQL:
systemctl start postgresql
systemctl enable postgresql
Create database and user:
sudo -u postgres psql -c "CREATE USER postaci WITH PASSWORD 'your_secure_password';"
sudo -u postgres psql -c "CREATE DATABASE postaci OWNER postaci;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE postaci TO postaci;"
3. Application Setup
Clone the repository:
git clone https://gitea.oezdag.io/m3mo/POSTERAPP_V1.git /opt/postaci
cd /opt/postaci
Install dependencies:
npm install
cd validation-service && npm install && cd ..
Set up environment variables:
# Create production env file
cat > .env.production << EOF
# Next Auth
NEXTAUTH_SECRET=$(openssl rand -base64 32)
NEXTAUTH_URL=http://your-server-ip
# Database
DATABASE_URL="postgresql://postaci:your_secure_password@localhost:5432/postaci"
# API Services
API_URL="http://localhost:8000/api"
EOF
Initialize the database:
npx prisma generate
npx prisma migrate deploy
Build the Next.js application:
npm run build
4. Service Setup
Create a service for the validation service:
cat > /etc/systemd/system/validation-service.service << EOF
[Unit]
Description=Address Validation Service for Postaci
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/postaci/validation-service
ExecStart=/usr/bin/node server.js
Restart=on-failure
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
EOF
Create a service for the Next.js application:
cat > /etc/systemd/system/nextjs.service << EOF
[Unit]
Description=Next.js Application for Postaci
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/postaci
ExecStart=/usr/bin/npm start
Restart=on-failure
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
EOF
Start and enable the services:
systemctl enable validation-service
systemctl start validation-service
systemctl enable nextjs
systemctl start nextjs
5. Nginx Setup
Create an Nginx configuration:
cat > /etc/nginx/sites-available/postaci << EOF
server {
listen 80;
server_name your-server-ip; # Replace with your domain if available
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
}
EOF
Enable the configuration:
ln -s /etc/nginx/sites-available/postaci /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
systemctl restart nginx
6. Firewall Setup
Configure the firewall:
ufw allow 22
ufw allow 80
ufw allow 443
ufw enable
Troubleshooting
Check Service Status
systemctl status nextjs
systemctl status validation-service
View Logs
journalctl -u nextjs -f
journalctl -u validation-service -f
Nginx Logs
tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.log
Security Recommendations
- Set up SSL/TLS with Let's Encrypt
- Create a non-root user for running the application
- Regularly update dependencies with
npm audit fix
- Configure server firewall properly
- Set up regular backups of the database