Spaces:
Sleeping
Sleeping
File size: 2,314 Bytes
10dc6f2 25a11b1 10dc6f2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #!/bin/bash
set -e
echo "=== EventFlow HF Spaces Startup ==="
cd /var/www
# Generate key if not set
if [ -z "$APP_KEY" ]; then
echo "Generating application key..."
php artisan key:generate --force
fi
# Create storage directories
mkdir -p storage/app/public storage/framework/cache storage/framework/sessions storage/framework/views storage/logs
chmod -R 777 storage bootstrap/cache
# Create storage symlink
rm -f public/storage
php artisan storage:link --force 2>/dev/null || true
# Ensure SQLite database exists
echo "Setting up SQLite database..."
touch database/database.sqlite
chmod 666 database/database.sqlite
# Run migrations
echo "Running migrations..."
php artisan migrate --force 2>&1 || echo "Migration warning"
# Seed database
echo "Seeding database..."
php artisan db:seed --force 2>&1 || echo "Seed warning (data may exist)"
# Cache for performance
echo "Caching config, routes, views..."
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Configure Apache to listen on port 7860 (HF Spaces default)
PORT=${PORT:-7860}
echo "Configuring Apache on port $PORT..."
sed -i "s/Listen 80$/Listen 0.0.0.0:$PORT/" /etc/apache2/ports.conf
sed -i "s/<VirtualHost \*:80>/<VirtualHost *:$PORT>/" /etc/apache2/sites-available/000-default.conf
# Fix ServerName warning
echo "ServerName localhost" >> /etc/apache2/apache2.conf
# Guarantee Laravel routing
a2enmod rewrite headers -q || true
echo "<Directory /var/www/public>" >> /etc/apache2/apache2.conf
echo " Options Indexes FollowSymLinks" >> /etc/apache2/apache2.conf
echo " AllowOverride All" >> /etc/apache2/apache2.conf
echo " Require all granted" >> /etc/apache2/apache2.conf
echo "</Directory>" >> /etc/apache2/apache2.conf
# Fix permissions
chmod -R 777 storage bootstrap/cache
# Tail Laravel logs
touch storage/logs/laravel.log
chmod 777 storage/logs/laravel.log
tail -n 0 -f storage/logs/laravel.log &
# Load Apache env
source /etc/apache2/envvars 2>/dev/null || true
# Fix MPM conflicts
rm -f /etc/apache2/mods-enabled/mpm_event.conf /etc/apache2/mods-enabled/mpm_event.load
rm -f /etc/apache2/mods-enabled/mpm_worker.conf /etc/apache2/mods-enabled/mpm_worker.load
a2enmod mpm_prefork -q || true
echo "=== EventFlow Ready on port $PORT ==="
# Start Apache in foreground
exec apache2-foreground
|