#!/bin/bash

# Set environment variables
export APP_ENV=production
export APP_DEBUG=false

# Define the application directory
APP_DIR="/path/to/your/php-ecommerce"

# Navigate to the application directory
cd $APP_DIR

# Pull the latest changes from the repository
git pull origin main

# Install PHP dependencies
composer install --no-dev --optimize-autoloader

# Install JavaScript dependencies
npm install --production

# Build assets
npm run build

# Run database migrations
php artisan migrate --force

# Clear cache
php artisan cache:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Restart the web server (if applicable)
# sudo systemctl restart apache2
# or
# sudo systemctl restart nginx

echo "Deployment completed successfully!"