| #!/bin/bash |
| set -e |
|
|
| echo "Starting WordPress for Hugging Face Spaces..." |
|
|
| |
| 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 |
|
|
| |
| 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 |
|
|
| |
| if [ ! -f "/var/www/html/wp-content/database/wordpress.db" ]; then |
| echo "Initializing WordPress database..." |
| |
| |
| touch /var/www/html/wp-content/database/wordpress.db |
| chmod 666 /var/www/html/wp-content/database/wordpress.db 2>/dev/null || true |
| |
| |
| echo "Database will be initialized on first visit" |
| fi |
|
|
| |
| 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; } |
| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>WordPress on Hugging Face Spaces</title> |
| <meta charset="utf-8"> |
| <style> |
| body { font-family: Arial, sans-serif; margin: 40px; background: |
| .container { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } |
| .status { color: |
| .info { background: |
| </style> |
| </head> |
| <body> |
| <div class="container"> |
| <h1>π WordPress on Hugging Face Spaces</h1> |
| <p class="status">β
Service is running</p> |
| <div class="info"> |
| <h3>π Setup Information:</h3> |
| <ul> |
| <li><strong>WordPress Version:</strong> 6.8.1</li> |
| <li><strong>PHP Version:</strong> 8.3</li> |
| <li><strong>Database:</strong> SQLite</li> |
| <li><strong>Web Server:</strong> Apache</li> |
| </ul> |
| </div> |
| <p><a href="/" style="background: #0073aa; color: white; padding: 10px 20px; text-decoration: none; border-radius: 4px;">π Go to WordPress</a></p> |
| <p><a href="/wp-admin/" style="background: #46b450; color: white; padding: 10px 20px; text-decoration: none; border-radius: 4px;">βοΈ Admin Panel</a></p> |
| </div> |
| </body> |
| </html> |
| EOF |
|
|
| |
| echo "Creating demo setup script..." |
| cat > /var/www/html/wp-content/demo-setup.php << 'EOF' || { echo "Warning: Could not create demo-setup.php"; } |
| <?php |
| /** |
| * Demo content setup for WordPress on HF Spaces |
| */ |
| if (!defined('ABSPATH')) { |
| define('ABSPATH', dirname(__FILE__) . '/../'); |
| } |
|
|
| require_once ABSPATH . 'wp-config.php'; |
| require_once ABSPATH . 'wp-includes/wp-db.php'; |
| require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
|
| // Create demo user if not exists |
| if (!username_exists('demo') && !email_exists('demo@example.com')) { |
| $user_id = wp_create_user('demo', 'demo123', 'demo@example.com'); |
| if (!is_wp_error($user_id)) { |
| $user = new WP_User($user_id); |
| $user->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' => '<h2>π Congratulations!</h2><p>You have successfully deployed WordPress on Hugging Face Spaces. This is a demo installation running on:</p><ul><li><strong>WordPress 6.8.1</strong></li><li><strong>PHP 8.3</strong></li><li><strong>SQLite Database</strong></li><li><strong>Apache Web Server</strong></li></ul><h3>π What you can do:</h3><ul><li>Create and edit posts</li><li>Install themes and plugins</li><li>Customize your site</li><li>Explore WordPress features</li></ul><p><em>Note: This is a demo environment. Data may not persist between deployments.</em></p>', |
| '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 |
|
|
| |
| 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 |
|
|
| |
| 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 |
|
|
| |
| 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 |
|
|
| |
| 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" |
|
|
| |
| echo "Starting Apache web server on port 7860..." |
| apache2-foreground & |
| APACHE_PID=$! |
|
|
| |
| sleep 5 |
|
|
| |
| 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 |
|
|
| |
| 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 "" |
|
|
| |
| tail -f /var/log/apache2/access.log |