T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/lavocat.quebec/private_html/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.quebec/private_html/scripts/deploy-apache.sh
#!/bin/bash

# Production Deployment Script for lavocat.quebec (Apache + Node.js + MySQL)
# This script prepares and deploys the application to production

set -e  # Exit on any error

echo "🚀 Starting production deployment for lavocat.quebec (Apache + MySQL)..."

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Configuration
DOMAIN="lavocat.quebec"
PROJECT_NAME="liberte-meme-en-cellule"
DEPLOY_DIR="/home/gositeme/domains/lavocat.quebec/public_html"
BACKUP_DIR="/home/gositeme/backups/lavocat.quebec"
APACHE_SITE_CONFIG="/etc/apache2/sites-available/lavocat.quebec.conf"

# Function to print colored output
print_status() {
    echo -e "${BLUE}[INFO]${NC} $1"
}

print_success() {
    echo -e "${GREEN}[SUCCESS]${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}[WARNING]${NC} $1"
}

print_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

# Check if running as root
if [[ $EUID -eq 0 ]]; then
   print_error "This script should not be run as root"
   exit 1
fi

# Check if Apache is installed
if ! command -v apache2 &> /dev/null; then
    print_error "Apache is not installed. Please install Apache first."
    exit 1
fi

# Check if Node.js is installed
if ! command -v node &> /dev/null; then
    print_error "Node.js is not installed. Please install Node.js first."
    exit 1
fi

# Create backup
print_status "Creating backup of current deployment..."
if [ -d "$DEPLOY_DIR" ]; then
    BACKUP_NAME="backup-$(date +%Y%m%d-%H%M%S)"
    sudo mkdir -p "$BACKUP_DIR"
    sudo cp -r "$DEPLOY_DIR" "$BACKUP_DIR/$BACKUP_NAME"
    print_success "Backup created: $BACKUP_DIR/$BACKUP_NAME"
else
    print_warning "No existing deployment found, skipping backup"
fi

# Create deployment directory
print_status "Creating deployment directory..."
sudo mkdir -p "$DEPLOY_DIR"
sudo chown $USER:$USER "$DEPLOY_DIR"

# Copy project files
print_status "Copying project files..."
cp -r . "$DEPLOY_DIR/"
cd "$DEPLOY_DIR"

# Install dependencies
print_status "Installing production dependencies..."
npm ci --only=production

# Generate Prisma client
print_status "Generating Prisma client..."
npx prisma generate

# Run database migrations
print_status "Running database migrations..."
npx prisma migrate deploy

# Build the application
print_status "Building the application..."
npm run build:production

# Create production environment file
print_status "Setting up production environment..."
if [ ! -f ".env.production" ]; then
    print_error "Production environment file not found!"
    print_status "Please create .env.production with your production settings"
    exit 1
fi

# Create systemd service file
print_status "Creating systemd service..."
sudo tee /etc/systemd/system/lavocat-quebec.service > /dev/null <<EOF
[Unit]
Description=Lavocat Quebec Next.js Application
After=network.target mysql.service

[Service]
Type=simple
User=$USER
WorkingDirectory=$DEPLOY_DIR
Environment=NODE_ENV=production
Environment=PORT=3000
Environment=HTTPS_PORT=3443
ExecStart=/usr/bin/node --max-old-space-size=4096 --expose-gc server-production.js
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
EOF

# Create Apache virtual host configuration
print_status "Creating Apache virtual host configuration..."
sudo tee "$APACHE_SITE_CONFIG" > /dev/null <<EOF
<VirtualHost *:80>
    ServerName lavocat.quebec
    ServerAlias www.lavocat.quebec
    DocumentRoot $DEPLOY_DIR/public
    
    # Redirect to HTTPS
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>

<VirtualHost *:443>
    ServerName lavocat.quebec
    ServerAlias www.lavocat.quebec
    DocumentRoot $DEPLOY_DIR/public
    
    # SSL Configuration (Let's Encrypt handled by DirectAdmin)
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/lavocat.quebec/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/lavocat.quebec/privkey.pem
    
    # Security headers
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    Header always set X-Frame-Options DENY
    Header always set X-Content-Type-Options nosniff
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    
    # Proxy to Node.js application
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:3000/
    ProxyPassReverse / http://127.0.0.1:3000/
    
    # WebSocket support
    ProxyPass /_ws ws://127.0.0.1:3443/_ws
    ProxyPassReverse /_ws ws://127.0.0.1:3443/_ws
    
    # Static files
    Alias /_next/static $DEPLOY_DIR/.next/static
    <Directory "$DEPLOY_DIR/.next/static">
        Require all granted
        ExpiresActive On
        ExpiresDefault "access plus 1 year"
        Header set Cache-Control "public, immutable"
    </Directory>
    
    # Uploads
    Alias /uploads $DEPLOY_DIR/public/uploads
    <Directory "$DEPLOY_DIR/public/uploads">
        Require all granted
        ExpiresActive On
        ExpiresDefault "access plus 1 year"
        Header set Cache-Control "public"
    </Directory>
    
    # Public files
    Alias /public $DEPLOY_DIR/public
    <Directory "$DEPLOY_DIR/public">
        Require all granted
        ExpiresActive On
        ExpiresDefault "access plus 1 month"
    </Directory>
    
    # Enable compression
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/xml
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE application/x-javascript
    </IfModule>
    
    # Error logs
    ErrorLog \${APACHE_LOG_DIR}/lavocat.quebec_error.log
    CustomLog \${APACHE_LOG_DIR}/lavocat.quebec_access.log combined
</VirtualHost>
EOF

# Enable required Apache modules
print_status "Enabling Apache modules..."
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_wstunnel
sudo a2enmod rewrite
sudo a2enmod headers
sudo a2enmod ssl
sudo a2enmod deflate

# Enable the site
print_status "Enabling Apache site..."
sudo a2ensite lavocat.quebec

# Test Apache configuration
print_status "Testing Apache configuration..."
sudo apache2ctl configtest

# Reload Apache
print_status "Reloading Apache..."
sudo systemctl reload apache2

# Enable and start the service
print_status "Starting the application service..."
sudo systemctl daemon-reload
sudo systemctl enable lavocat-quebec
sudo systemctl start lavocat-quebec

# Wait for service to start
sleep 5

# Check service status
if sudo systemctl is-active --quiet lavocat-quebec; then
    print_success "Service is running successfully!"
else
    print_error "Service failed to start!"
    sudo systemctl status lavocat-quebec
    exit 1
fi

# Create log directory
print_status "Setting up logging..."
sudo mkdir -p /home/gositeme/logs/lavocat-quebec
sudo chown $USER:$USER /home/gositeme/logs/lavocat-quebec

# Create logrotate configuration
sudo tee /etc/logrotate.d/lavocat-quebec > /dev/null <<EOF
/var/log/lavocat-quebec/*.log {
    daily
    missingok
    rotate 52
    compress
    delaycompress
    notifempty
    create 644 $USER $USER
    postrotate
        systemctl reload lavocat-quebec
    endscript
}
EOF

print_success "Deployment completed successfully!"
print_status "Your application is now running at: https://lavocat.quebec"
print_status "Service status: sudo systemctl status lavocat-quebec"
print_status "View logs: sudo journalctl -u lavocat-quebec -f"
print_status "Apache logs: sudo tail -f /var/log/apache2/lavocat.quebec_*.log" 

CasperSecurity Mini