Upload 9 files
Browse files- Dockerfile +2 -0
- db.php +88 -17
- error-debug.php +84 -0
- start-hf.sh +39 -5
- test-php.php +55 -0
- wp-config-hf.php +7 -4
Dockerfile
CHANGED
@@ -92,6 +92,8 @@ RUN set -eux; \
|
|
92 |
# Create WordPress configuration for SQLite
|
93 |
COPY wp-config-hf.php /var/www/html/wp-config.php
|
94 |
COPY db.php /var/www/html/wp-content/db.php
|
|
|
|
|
95 |
|
96 |
# Create .htaccess for pretty permalinks
|
97 |
RUN { \
|
|
|
92 |
# Create WordPress configuration for SQLite
|
93 |
COPY wp-config-hf.php /var/www/html/wp-config.php
|
94 |
COPY db.php /var/www/html/wp-content/db.php
|
95 |
+
COPY error-debug.php /var/www/html/debug.php
|
96 |
+
COPY test-php.php /var/www/html/test.php
|
97 |
|
98 |
# Create .htaccess for pretty permalinks
|
99 |
RUN { \
|
db.php
CHANGED
@@ -26,18 +26,49 @@ if (!file_exists($db_dir)) {
|
|
26 |
}
|
27 |
|
28 |
/**
|
29 |
-
* Custom database class for SQLite
|
30 |
*/
|
31 |
class SQLite_DB {
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
public function __construct() {
|
|
|
|
|
|
|
38 |
$this->connect();
|
39 |
}
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
private function connect() {
|
42 |
try {
|
43 |
$this->pdo = new PDO('sqlite:' . DB_FILE);
|
@@ -50,6 +81,10 @@ class SQLite_DB {
|
|
50 |
}
|
51 |
|
52 |
public function query($sql) {
|
|
|
|
|
|
|
|
|
53 |
try {
|
54 |
// Convert MySQL syntax to SQLite
|
55 |
$sql = $this->mysql_to_sqlite($sql);
|
@@ -58,9 +93,16 @@ class SQLite_DB {
|
|
58 |
$result = $stmt->execute();
|
59 |
|
60 |
if ($result) {
|
61 |
-
$this->
|
62 |
$this->num_rows = $stmt->rowCount();
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
}
|
65 |
|
66 |
return false;
|
@@ -86,11 +128,11 @@ class SQLite_DB {
|
|
86 |
}
|
87 |
|
88 |
public function get_results($sql, $output = OBJECT) {
|
89 |
-
$
|
90 |
-
if (!$
|
91 |
|
92 |
$results = [];
|
93 |
-
while ($row = $
|
94 |
if ($output === OBJECT) {
|
95 |
$results[] = (object) $row;
|
96 |
} else {
|
@@ -102,10 +144,10 @@ class SQLite_DB {
|
|
102 |
}
|
103 |
|
104 |
public function get_row($sql, $output = OBJECT) {
|
105 |
-
$
|
106 |
-
if (!$
|
107 |
|
108 |
-
$row = $
|
109 |
if (!$row) return null;
|
110 |
|
111 |
if ($output === OBJECT) {
|
@@ -116,15 +158,15 @@ class SQLite_DB {
|
|
116 |
}
|
117 |
|
118 |
public function get_var($sql) {
|
119 |
-
$
|
120 |
-
if (!$
|
121 |
|
122 |
-
$row = $
|
123 |
return $row ? $row[0] : null;
|
124 |
}
|
125 |
|
126 |
public function insert_id() {
|
127 |
-
return $this->
|
128 |
}
|
129 |
|
130 |
public function last_error() {
|
@@ -134,6 +176,35 @@ class SQLite_DB {
|
|
134 |
public function num_rows() {
|
135 |
return $this->num_rows;
|
136 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
}
|
138 |
|
139 |
// Initialize SQLite database connection
|
|
|
26 |
}
|
27 |
|
28 |
/**
|
29 |
+
* Custom database class for SQLite - WordPress wpdb compatible
|
30 |
*/
|
31 |
class SQLite_DB {
|
32 |
+
public $pdo;
|
33 |
+
public $last_error = '';
|
34 |
+
public $insert_id = 0;
|
35 |
+
public $num_rows = 0;
|
36 |
+
public $last_query = '';
|
37 |
+
public $last_result = null;
|
38 |
+
public $prefix = 'wp_';
|
39 |
+
|
40 |
+
// WordPress compatibility properties
|
41 |
+
public $posts;
|
42 |
+
public $users;
|
43 |
+
public $options;
|
44 |
+
public $postmeta;
|
45 |
+
public $usermeta;
|
46 |
+
public $terms;
|
47 |
+
public $term_taxonomy;
|
48 |
+
public $term_relationships;
|
49 |
+
public $comments;
|
50 |
+
public $commentmeta;
|
51 |
|
52 |
public function __construct() {
|
53 |
+
global $table_prefix;
|
54 |
+
$this->prefix = isset($table_prefix) ? $table_prefix : 'wp_';
|
55 |
+
$this->set_table_names();
|
56 |
$this->connect();
|
57 |
}
|
58 |
|
59 |
+
private function set_table_names() {
|
60 |
+
$this->posts = $this->prefix . 'posts';
|
61 |
+
$this->users = $this->prefix . 'users';
|
62 |
+
$this->options = $this->prefix . 'options';
|
63 |
+
$this->postmeta = $this->prefix . 'postmeta';
|
64 |
+
$this->usermeta = $this->prefix . 'usermeta';
|
65 |
+
$this->terms = $this->prefix . 'terms';
|
66 |
+
$this->term_taxonomy = $this->prefix . 'term_taxonomy';
|
67 |
+
$this->term_relationships = $this->prefix . 'term_relationships';
|
68 |
+
$this->comments = $this->prefix . 'comments';
|
69 |
+
$this->commentmeta = $this->prefix . 'commentmeta';
|
70 |
+
}
|
71 |
+
|
72 |
private function connect() {
|
73 |
try {
|
74 |
$this->pdo = new PDO('sqlite:' . DB_FILE);
|
|
|
81 |
}
|
82 |
|
83 |
public function query($sql) {
|
84 |
+
$this->last_query = $sql;
|
85 |
+
$this->last_error = '';
|
86 |
+
$this->last_result = null;
|
87 |
+
|
88 |
try {
|
89 |
// Convert MySQL syntax to SQLite
|
90 |
$sql = $this->mysql_to_sqlite($sql);
|
|
|
93 |
$result = $stmt->execute();
|
94 |
|
95 |
if ($result) {
|
96 |
+
$this->insert_id = $this->pdo->lastInsertId();
|
97 |
$this->num_rows = $stmt->rowCount();
|
98 |
+
$this->last_result = $stmt;
|
99 |
+
|
100 |
+
// For SELECT queries, return the number of rows
|
101 |
+
if (stripos(trim($sql), 'SELECT') === 0) {
|
102 |
+
return $this->num_rows;
|
103 |
+
}
|
104 |
+
// For INSERT, UPDATE, DELETE, return true
|
105 |
+
return true;
|
106 |
}
|
107 |
|
108 |
return false;
|
|
|
128 |
}
|
129 |
|
130 |
public function get_results($sql, $output = OBJECT) {
|
131 |
+
$this->query($sql);
|
132 |
+
if (!$this->last_result) return null;
|
133 |
|
134 |
$results = [];
|
135 |
+
while ($row = $this->last_result->fetch(PDO::FETCH_ASSOC)) {
|
136 |
if ($output === OBJECT) {
|
137 |
$results[] = (object) $row;
|
138 |
} else {
|
|
|
144 |
}
|
145 |
|
146 |
public function get_row($sql, $output = OBJECT) {
|
147 |
+
$this->query($sql);
|
148 |
+
if (!$this->last_result) return null;
|
149 |
|
150 |
+
$row = $this->last_result->fetch(PDO::FETCH_ASSOC);
|
151 |
if (!$row) return null;
|
152 |
|
153 |
if ($output === OBJECT) {
|
|
|
158 |
}
|
159 |
|
160 |
public function get_var($sql) {
|
161 |
+
$this->query($sql);
|
162 |
+
if (!$this->last_result) return null;
|
163 |
|
164 |
+
$row = $this->last_result->fetch(PDO::FETCH_NUM);
|
165 |
return $row ? $row[0] : null;
|
166 |
}
|
167 |
|
168 |
public function insert_id() {
|
169 |
+
return $this->insert_id;
|
170 |
}
|
171 |
|
172 |
public function last_error() {
|
|
|
176 |
public function num_rows() {
|
177 |
return $this->num_rows;
|
178 |
}
|
179 |
+
|
180 |
+
// WordPress compatibility methods
|
181 |
+
public function prepare($query, ...$args) {
|
182 |
+
if (empty($args)) {
|
183 |
+
return $query;
|
184 |
+
}
|
185 |
+
|
186 |
+
$query = str_replace("'%s'", '%s', $query);
|
187 |
+
$query = str_replace('"%s"', '%s', $query);
|
188 |
+
$query = str_replace('%s', "'%s'", $query);
|
189 |
+
$query = str_replace("'%d'", '%d', $query);
|
190 |
+
$query = str_replace('"%d"', '%d', $query);
|
191 |
+
|
192 |
+
return vsprintf($query, $args);
|
193 |
+
}
|
194 |
+
|
195 |
+
public function get_charset_collate() {
|
196 |
+
return '';
|
197 |
+
}
|
198 |
+
|
199 |
+
public function esc_like($text) {
|
200 |
+
return addcslashes($text, '\\%_');
|
201 |
+
}
|
202 |
+
|
203 |
+
public function print_error($str = '') {
|
204 |
+
if ($this->last_error) {
|
205 |
+
echo '<div id="error"><p class="wpdberror"><strong>WordPress database error:</strong> [' . $this->last_error . ']<br /><code>' . $this->last_query . '</code></p></div>';
|
206 |
+
}
|
207 |
+
}
|
208 |
}
|
209 |
|
210 |
// Initialize SQLite database connection
|
error-debug.php
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Simple error debugging page for WordPress
|
4 |
+
*/
|
5 |
+
|
6 |
+
// Enable error reporting
|
7 |
+
ini_set('display_errors', 1);
|
8 |
+
ini_set('display_startup_errors', 1);
|
9 |
+
error_reporting(E_ALL);
|
10 |
+
|
11 |
+
echo "<h1>WordPress Debug Information</h1>";
|
12 |
+
|
13 |
+
// Check PHP version
|
14 |
+
echo "<h2>PHP Version</h2>";
|
15 |
+
echo "<p>" . phpversion() . "</p>";
|
16 |
+
|
17 |
+
// Check SQLite extension
|
18 |
+
echo "<h2>SQLite Support</h2>";
|
19 |
+
if (extension_loaded('pdo_sqlite')) {
|
20 |
+
echo "<p style='color: green;'>β PDO SQLite extension is loaded</p>";
|
21 |
+
} else {
|
22 |
+
echo "<p style='color: red;'>β PDO SQLite extension is NOT loaded</p>";
|
23 |
+
}
|
24 |
+
|
25 |
+
// Check file permissions
|
26 |
+
echo "<h2>File Permissions</h2>";
|
27 |
+
$paths = [
|
28 |
+
'/var/www/html',
|
29 |
+
'/var/www/html/wp-content',
|
30 |
+
'/var/www/html/wp-content/database',
|
31 |
+
'/var/www/html/wp-content/db.php'
|
32 |
+
];
|
33 |
+
|
34 |
+
foreach ($paths as $path) {
|
35 |
+
if (file_exists($path)) {
|
36 |
+
$perms = substr(sprintf('%o', fileperms($path)), -4);
|
37 |
+
echo "<p>$path: $perms</p>";
|
38 |
+
} else {
|
39 |
+
echo "<p style='color: red;'>$path: NOT FOUND</p>";
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
// Check database file
|
44 |
+
echo "<h2>Database Status</h2>";
|
45 |
+
$db_file = '/var/www/html/wp-content/database/wordpress.db';
|
46 |
+
if (file_exists($db_file)) {
|
47 |
+
echo "<p style='color: green;'>β Database file exists</p>";
|
48 |
+
echo "<p>Size: " . filesize($db_file) . " bytes</p>";
|
49 |
+
} else {
|
50 |
+
echo "<p style='color: red;'>β Database file does not exist</p>";
|
51 |
+
}
|
52 |
+
|
53 |
+
// Test SQLite connection
|
54 |
+
echo "<h2>SQLite Connection Test</h2>";
|
55 |
+
try {
|
56 |
+
$pdo = new PDO('sqlite:' . $db_file);
|
57 |
+
echo "<p style='color: green;'>β SQLite connection successful</p>";
|
58 |
+
} catch (Exception $e) {
|
59 |
+
echo "<p style='color: red;'>β SQLite connection failed: " . $e->getMessage() . "</p>";
|
60 |
+
}
|
61 |
+
|
62 |
+
// Check WordPress files
|
63 |
+
echo "<h2>WordPress Files</h2>";
|
64 |
+
$wp_files = [
|
65 |
+
'/var/www/html/wp-config.php',
|
66 |
+
'/var/www/html/wp-settings.php',
|
67 |
+
'/var/www/html/wp-load.php'
|
68 |
+
];
|
69 |
+
|
70 |
+
foreach ($wp_files as $file) {
|
71 |
+
if (file_exists($file)) {
|
72 |
+
echo "<p style='color: green;'>β $file exists</p>";
|
73 |
+
} else {
|
74 |
+
echo "<p style='color: red;'>β $file NOT FOUND</p>";
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
echo "<h2>Environment Variables</h2>";
|
79 |
+
echo "<p>HTTP_HOST: " . ($_SERVER['HTTP_HOST'] ?? 'not set') . "</p>";
|
80 |
+
echo "<p>SERVER_NAME: " . ($_SERVER['SERVER_NAME'] ?? 'not set') . "</p>";
|
81 |
+
echo "<p>REQUEST_URI: " . ($_SERVER['REQUEST_URI'] ?? 'not set') . "</p>";
|
82 |
+
|
83 |
+
echo "<hr><p><a href='/'>Try WordPress again</a></p>";
|
84 |
+
?>
|
start-hf.sh
CHANGED
@@ -110,6 +110,29 @@ if [ ! -f "/var/www/html/wp-config.php" ]; then
|
|
110 |
cp /var/www/html/wp-config-hf.php /var/www/html/wp-config.php
|
111 |
fi
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
# Start Apache in background
|
114 |
echo "Starting Apache web server on port 7860..."
|
115 |
apache2-foreground &
|
@@ -127,9 +150,20 @@ else
|
|
127 |
fi
|
128 |
|
129 |
# Keep the container running
|
130 |
-
echo "WordPress is ready!
|
131 |
-
echo "
|
132 |
-
echo "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
-
#
|
135 |
-
|
|
|
110 |
cp /var/www/html/wp-config-hf.php /var/www/html/wp-config.php
|
111 |
fi
|
112 |
|
113 |
+
# Verify SQLite database integration
|
114 |
+
echo "Verifying SQLite database integration..."
|
115 |
+
if [ -f "/var/www/html/wp-content/db.php" ]; then
|
116 |
+
echo "β SQLite db.php found in wp-content"
|
117 |
+
else
|
118 |
+
echo "β SQLite db.php not found, copying..."
|
119 |
+
cp /var/www/html/db.php /var/www/html/wp-content/db.php 2>/dev/null || true
|
120 |
+
chmod 644 /var/www/html/wp-content/db.php 2>/dev/null || true
|
121 |
+
fi
|
122 |
+
|
123 |
+
# Verify WordPress configuration
|
124 |
+
echo "Verifying WordPress configuration..."
|
125 |
+
if [ -f "/var/www/html/wp-config.php" ]; then
|
126 |
+
echo "β wp-config.php found"
|
127 |
+
else
|
128 |
+
echo "β wp-config.php not found"
|
129 |
+
fi
|
130 |
+
|
131 |
+
# Test PHP syntax
|
132 |
+
echo "Testing PHP configuration..."
|
133 |
+
php -l /var/www/html/wp-config.php || echo "Warning: wp-config.php has syntax errors"
|
134 |
+
php -l /var/www/html/wp-content/db.php || echo "Warning: db.php has syntax errors"
|
135 |
+
|
136 |
# Start Apache in background
|
137 |
echo "Starting Apache web server on port 7860..."
|
138 |
apache2-foreground &
|
|
|
150 |
fi
|
151 |
|
152 |
# Keep the container running
|
153 |
+
echo "WordPress is ready! Visit your Hugging Face Space to see it in action."
|
154 |
+
echo "Demo login: demo / demo123"
|
155 |
+
echo ""
|
156 |
+
echo "=== Debugging Information ==="
|
157 |
+
echo "If WordPress shows errors, try these debug pages:"
|
158 |
+
echo "β’ /test.php - Basic PHP and SQLite test"
|
159 |
+
echo "β’ /debug.php - Detailed system information"
|
160 |
+
echo "β’ Check Space logs for detailed error messages"
|
161 |
+
echo ""
|
162 |
+
echo "WordPress files:"
|
163 |
+
echo "β’ wp-config.php: $([ -f /var/www/html/wp-config.php ] && echo 'β' || echo 'β')"
|
164 |
+
echo "β’ wp-content/db.php: $([ -f /var/www/html/wp-content/db.php ] && echo 'β' || echo 'β')"
|
165 |
+
echo "β’ Database dir: $([ -d /var/www/html/wp-content/database ] && echo 'β' || echo 'β')"
|
166 |
+
echo ""
|
167 |
|
168 |
+
# Keep the container running
|
169 |
+
tail -f /var/log/apache2/access.log
|
test-php.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Simple PHP test file
|
4 |
+
*/
|
5 |
+
|
6 |
+
echo "<h1>PHP Test Page</h1>";
|
7 |
+
echo "<p>PHP Version: " . phpversion() . "</p>";
|
8 |
+
echo "<p>Current Time: " . date('Y-m-d H:i:s') . "</p>";
|
9 |
+
|
10 |
+
// Test SQLite
|
11 |
+
if (extension_loaded('pdo_sqlite')) {
|
12 |
+
echo "<p style='color: green;'>β SQLite PDO extension is available</p>";
|
13 |
+
|
14 |
+
try {
|
15 |
+
$db_file = '/var/www/html/wp-content/database/wordpress.db';
|
16 |
+
$pdo = new PDO('sqlite:' . $db_file);
|
17 |
+
echo "<p style='color: green;'>β SQLite connection successful</p>";
|
18 |
+
|
19 |
+
// Test a simple query
|
20 |
+
$result = $pdo->query("SELECT name FROM sqlite_master WHERE type='table'");
|
21 |
+
$tables = $result->fetchAll(PDO::FETCH_COLUMN);
|
22 |
+
|
23 |
+
if (count($tables) > 0) {
|
24 |
+
echo "<p>Database tables found: " . implode(', ', $tables) . "</p>";
|
25 |
+
} else {
|
26 |
+
echo "<p>No tables found in database (this is normal for a fresh install)</p>";
|
27 |
+
}
|
28 |
+
|
29 |
+
} catch (Exception $e) {
|
30 |
+
echo "<p style='color: red;'>β SQLite connection failed: " . $e->getMessage() . "</p>";
|
31 |
+
}
|
32 |
+
} else {
|
33 |
+
echo "<p style='color: red;'>β SQLite PDO extension is NOT available</p>";
|
34 |
+
}
|
35 |
+
|
36 |
+
// Test file permissions
|
37 |
+
echo "<h2>File Permissions</h2>";
|
38 |
+
$files = [
|
39 |
+
'/var/www/html/wp-config.php',
|
40 |
+
'/var/www/html/wp-content/db.php',
|
41 |
+
'/var/www/html/wp-content/database'
|
42 |
+
];
|
43 |
+
|
44 |
+
foreach ($files as $file) {
|
45 |
+
if (file_exists($file)) {
|
46 |
+
$perms = substr(sprintf('%o', fileperms($file)), -4);
|
47 |
+
echo "<p>$file: $perms</p>";
|
48 |
+
} else {
|
49 |
+
echo "<p style='color: red;'>$file: NOT FOUND</p>";
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
echo "<hr>";
|
54 |
+
echo "<p><a href='/'>Try WordPress</a> | <a href='/debug.php'>Debug Info</a></p>";
|
55 |
+
?>
|
wp-config-hf.php
CHANGED
@@ -35,11 +35,14 @@ define('NONCE_SALT', 'hf-spaces-nonce-salt-' . md5(__FILE__));
|
|
35 |
$table_prefix = 'wp_';
|
36 |
|
37 |
/**
|
38 |
-
* WordPress debugging mode - enabled for
|
39 |
*/
|
40 |
-
define('WP_DEBUG',
|
41 |
-
define('WP_DEBUG_LOG',
|
42 |
-
define('WP_DEBUG_DISPLAY',
|
|
|
|
|
|
|
43 |
|
44 |
/**
|
45 |
* WordPress URLs and paths for HF Spaces
|
|
|
35 |
$table_prefix = 'wp_';
|
36 |
|
37 |
/**
|
38 |
+
* WordPress debugging mode - enabled for troubleshooting
|
39 |
*/
|
40 |
+
define('WP_DEBUG', true);
|
41 |
+
define('WP_DEBUG_LOG', true);
|
42 |
+
define('WP_DEBUG_DISPLAY', true);
|
43 |
+
define('SCRIPT_DEBUG', true);
|
44 |
+
ini_set('display_errors', 1);
|
45 |
+
ini_set('log_errors', 1);
|
46 |
|
47 |
/**
|
48 |
* WordPress URLs and paths for HF Spaces
|