#!/bin/bash set -e echo "Starting WordPress for Hugging Face Spaces..." # Ensure directories exist (they should already be created in Dockerfile) test -d /var/www/html/wp-content/database || mkdir -p /var/www/html/wp-content/database test -d /var/www/html/wp-content/uploads || mkdir -p /var/www/html/wp-content/uploads test -d /var/www/html/wp-content/cache || mkdir -p /var/www/html/wp-content/cache # Ensure proper permissions (fallback) chmod 777 /var/www/html 2>/dev/null || true chmod 777 /var/www/html/wp-content/uploads 2>/dev/null || true chmod 777 /var/www/html/wp-content/database 2>/dev/null || true chmod 777 /var/www/html/wp-content/cache 2>/dev/null || true # Initialize SQLite database if it doesn't exist if [ ! -f "/var/www/html/wp-content/database/wordpress.db" ]; then echo "Initializing WordPress database..." # Create empty SQLite database with proper permissions touch /var/www/html/wp-content/database/wordpress.db chmod 666 /var/www/html/wp-content/database/wordpress.db 2>/dev/null || true # Initialize WordPress tables - let WordPress handle it on first visit echo "Database will be initialized on first visit" fi # Create a simple health check file echo "Creating health check file..." cat > /var/www/html/health.html << 'EOF' || { echo "Warning: Could not create health.html"; touch /var/www/html/health.html 2>/dev/null || true; } WordPress on Hugging Face Spaces

🚀 WordPress on Hugging Face Spaces

✅ Service is running

📋 Setup Information:

🏠 Go to WordPress

⚙️ Admin Panel

EOF # Create demo content script echo "Creating demo setup script..." cat > /var/www/html/wp-content/demo-setup.php << 'EOF' || { echo "Warning: Could not create demo-setup.php"; } set_role('administrator'); echo "Demo user created: demo/demo123\n"; } } // Create demo post $demo_post = array( 'post_title' => 'Welcome to WordPress on Hugging Face Spaces!', 'post_content' => '

🎉 Congratulations!

You have successfully deployed WordPress on Hugging Face Spaces. This is a demo installation running on:

🚀 What you can do:

Note: This is a demo environment. Data may not persist between deployments.

', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'post' ); if (!get_page_by_title('Welcome to WordPress on Hugging Face Spaces!')) { wp_insert_post($demo_post); echo "Demo post created\n"; } echo "Demo setup completed\n"; ?> EOF # Set up WordPress if not already configured if [ ! -f "/var/www/html/wp-config.php" ]; then echo "WordPress configuration not found, copying HF Spaces config..." cp /var/www/html/wp-config-hf.php /var/www/html/wp-config.php fi # Verify SQLite database integration echo "Verifying SQLite database integration..." if [ -f "/var/www/html/wp-content/db.php" ]; then echo "✓ SQLite db.php found in wp-content" else echo "✗ SQLite db.php not found, copying..." cp /var/www/html/db.php /var/www/html/wp-content/db.php 2>/dev/null || true chmod 644 /var/www/html/wp-content/db.php 2>/dev/null || true fi # Verify WordPress configuration echo "Verifying WordPress configuration..." if [ -f "/var/www/html/wp-config.php" ]; then echo "✓ wp-config.php found" else echo "✗ wp-config.php not found" fi # Test PHP syntax echo "Testing PHP configuration..." php -l /var/www/html/wp-config.php || echo "Warning: wp-config.php has syntax errors" php -l /var/www/html/wp-content/db.php || echo "Warning: db.php has syntax errors" # Start Apache in background echo "Starting Apache web server on port 7860..." apache2-foreground & APACHE_PID=$! # Wait for Apache to start sleep 5 # Check if WordPress is accessible echo "Checking WordPress accessibility..." if curl -f http://localhost:7860/health.html > /dev/null 2>&1; then echo "✅ WordPress is accessible at http://localhost:7860" else echo "⚠️ WordPress may not be fully ready yet" fi # Keep the container running echo "WordPress is ready! Visit your Hugging Face Space to see it in action." echo "Demo login: demo / demo123" echo "" echo "=== Debugging Information ===" echo "If WordPress shows errors, try these debug pages:" echo "• /test.php - Basic PHP and SQLite test" echo "• /debug.php - Detailed system information" echo "• Check Space logs for detailed error messages" echo "" echo "WordPress files:" echo "• wp-config.php: $([ -f /var/www/html/wp-config.php ] && echo '✓' || echo '✗')" echo "• wp-content/db.php: $([ -f /var/www/html/wp-content/db.php ] && echo '✓' || echo '✗')" echo "• Database dir: $([ -d /var/www/html/wp-content/database ] && echo '✓' || echo '✗')" echo "" # Keep the container running tail -f /var/log/apache2/access.log