Upload 4 files
Browse files- README-HF-SPACES.md +186 -0
- db.php +145 -0
- start-hf.sh +133 -0
- wp-config-hf.php +100 -0
README-HF-SPACES.md
ADDED
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# WordPress on Hugging Face Spaces
|
2 |
+
|
3 |
+
这是一个专门为 Hugging Face Spaces 优化的 WordPress Docker 部署方案。
|
4 |
+
|
5 |
+
## 🚀 特性
|
6 |
+
|
7 |
+
- **WordPress 6.8.1** - 最新稳定版本
|
8 |
+
- **PHP 8.3** - 高性能 PHP 版本
|
9 |
+
- **SQLite 数据库** - 无需外部数据库服务
|
10 |
+
- **Apache Web 服务器** - 稳定可靠
|
11 |
+
- **端口 7860** - 符合 HF Spaces 要求
|
12 |
+
- **预配置设置** - 开箱即用
|
13 |
+
- **演示内容** - 包含示例文章和用户
|
14 |
+
|
15 |
+
## 📋 部署到 Hugging Face Spaces
|
16 |
+
|
17 |
+
### 方法 1: 直接上传文件
|
18 |
+
|
19 |
+
1. 在 Hugging Face 创建新的 Space
|
20 |
+
2. 选择 "Docker" 作为 SDK
|
21 |
+
3. 上传以下文件到你的 Space:
|
22 |
+
```
|
23 |
+
Dockerfile.hf-spaces → Dockerfile
|
24 |
+
wp-config-hf.php
|
25 |
+
db.php
|
26 |
+
start-hf.sh
|
27 |
+
README-HF-SPACES.md → README.md
|
28 |
+
```
|
29 |
+
|
30 |
+
### 方法 2: Git 推送
|
31 |
+
|
32 |
+
1. 克隆你的 HF Space 仓库:
|
33 |
+
```bash
|
34 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
|
35 |
+
cd YOUR_SPACE_NAME
|
36 |
+
```
|
37 |
+
|
38 |
+
2. 复制必要文件:
|
39 |
+
```bash
|
40 |
+
cp path/to/wordpress-master/Dockerfile.hf-spaces ./Dockerfile
|
41 |
+
cp path/to/wordpress-master/wp-config-hf.php .
|
42 |
+
cp path/to/wordpress-master/db.php .
|
43 |
+
cp path/to/wordpress-master/start-hf.sh .
|
44 |
+
cp path/to/wordpress-master/README-HF-SPACES.md ./README.md
|
45 |
+
```
|
46 |
+
|
47 |
+
3. 提交并推送:
|
48 |
+
```bash
|
49 |
+
git add .
|
50 |
+
git commit -m "Add WordPress for HF Spaces"
|
51 |
+
git push
|
52 |
+
```
|
53 |
+
|
54 |
+
## 🔧 配置说明
|
55 |
+
|
56 |
+
### Dockerfile 修改
|
57 |
+
|
58 |
+
- **端口配置**: 从 80 改为 7860
|
59 |
+
- **数据库**: 使用 SQLite 替代 MySQL
|
60 |
+
- **依赖**: 添加 SQLite 支持
|
61 |
+
- **权限**: 优化文件权限设置
|
62 |
+
|
63 |
+
### WordPress 配置
|
64 |
+
|
65 |
+
- **数据库**: SQLite 文件存储在 `wp-content/database/`
|
66 |
+
- **URL 检测**: 自动检测 HTTPS 和域名
|
67 |
+
- **安全**: 禁用文件编辑,启用强制 HTTPS
|
68 |
+
- **性能**: 优化内存限制和缓存设置
|
69 |
+
|
70 |
+
### 启动脚本
|
71 |
+
|
72 |
+
- **初始化**: 自动创建必要目录和数据库
|
73 |
+
- **权限**: 设置正确的文件权限
|
74 |
+
- **健康检查**: 提供状态页面
|
75 |
+
- **演示内容**: 可选的示例内容
|
76 |
+
|
77 |
+
## 🎯 访问信息
|
78 |
+
|
79 |
+
部署完成后,你可以通过以下方式访问:
|
80 |
+
|
81 |
+
- **主页**: `https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/`
|
82 |
+
- **管理面板**: `https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/wp-admin/`
|
83 |
+
- **健康检查**: `https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/health.html`
|
84 |
+
|
85 |
+
### 默认登录信息
|
86 |
+
|
87 |
+
- **用户名**: `demo`
|
88 |
+
- **密码**: `demo123`
|
89 |
+
- **邮箱**: `[email protected]`
|
90 |
+
|
91 |
+
> ⚠️ **安全提醒**: 首次登录后请立即更改默认密码!
|
92 |
+
|
93 |
+
## 📁 文件结构
|
94 |
+
|
95 |
+
```
|
96 |
+
/var/www/html/
|
97 |
+
├── wp-config.php # WordPress 配置
|
98 |
+
├── wp-content/
|
99 |
+
│ ├── database/ # SQLite 数据库文件
|
100 |
+
│ ├── plugins/ # 插件目录
|
101 |
+
│ ├── themes/ # 主题目录
|
102 |
+
│ ├── uploads/ # 上传文件
|
103 |
+
│ └── db.php # SQLite 集成
|
104 |
+
├── .htaccess # URL 重写规则
|
105 |
+
└── health.html # 健康检查页面
|
106 |
+
```
|
107 |
+
|
108 |
+
## ⚠️ 限制和注意事项
|
109 |
+
|
110 |
+
### Hugging Face Spaces 限制
|
111 |
+
|
112 |
+
1. **存储**: 数据不会永久保存,重启后丢失
|
113 |
+
2. **资源**: CPU 和内存有限制
|
114 |
+
3. **网络**: 某些外部连接可能受限
|
115 |
+
4. **插件**: 某些需要特殊权限的插件可能无法使用
|
116 |
+
|
117 |
+
### 建议用途
|
118 |
+
|
119 |
+
- ✅ **演示和测试**: 展示 WordPress 功能
|
120 |
+
- ✅ **开发环境**: 临时开发和调试
|
121 |
+
- ✅ **教学用途**: WordPress 学习和培训
|
122 |
+
- ❌ **生产环境**: 不适合正式网站
|
123 |
+
- ❌ **数据存储**: 重要数据会丢失
|
124 |
+
|
125 |
+
## 🔧 自定义配置
|
126 |
+
|
127 |
+
### 修改端口 (如果需要)
|
128 |
+
|
129 |
+
在 `Dockerfile.hf-spaces` 中修改:
|
130 |
+
```dockerfile
|
131 |
+
# 将 7860 改为其他端口
|
132 |
+
sed -i 's/Listen 80/Listen YOUR_PORT/' /etc/apache2/ports.conf
|
133 |
+
EXPOSE YOUR_PORT
|
134 |
+
```
|
135 |
+
|
136 |
+
### 添加插件或主题
|
137 |
+
|
138 |
+
在 `Dockerfile.hf-spaces` 中添加:
|
139 |
+
```dockerfile
|
140 |
+
# 下载并安装插件
|
141 |
+
RUN wget -O plugin.zip "PLUGIN_DOWNLOAD_URL" && \
|
142 |
+
unzip plugin.zip -d /var/www/html/wp-content/plugins/ && \
|
143 |
+
rm plugin.zip
|
144 |
+
```
|
145 |
+
|
146 |
+
### 修改 PHP 设置
|
147 |
+
|
148 |
+
在 `Dockerfile.hf-spaces` 中调整:
|
149 |
+
```dockerfile
|
150 |
+
RUN { \
|
151 |
+
echo 'memory_limit = 512M'; \
|
152 |
+
echo 'upload_max_filesize = 64M'; \
|
153 |
+
echo 'post_max_size = 64M'; \
|
154 |
+
} > /usr/local/etc/php/conf.d/custom.ini
|
155 |
+
```
|
156 |
+
|
157 |
+
## 🐛 故障排除
|
158 |
+
|
159 |
+
### 常见问题
|
160 |
+
|
161 |
+
1. **无法访问**: 检查端口是否为 7860
|
162 |
+
2. **数据库错误**: 确保 SQLite 扩展已安装
|
163 |
+
3. **权限错误**: 检查文件权限设置
|
164 |
+
4. **插件问题**: 某些插件可能不兼容 SQLite
|
165 |
+
|
166 |
+
### 调试方法
|
167 |
+
|
168 |
+
1. 查看容器日志
|
169 |
+
2. 访问 `/health.html` 检查状态
|
170 |
+
3. 检查 `/wp-content/database/` 目录权限
|
171 |
+
4. 启用 WordPress 调试模式
|
172 |
+
|
173 |
+
## 📚 相关资源
|
174 |
+
|
175 |
+
- [WordPress 官方文档](https://wordpress.org/documentation/)
|
176 |
+
- [Hugging Face Spaces 文档](https://huggingface.co/docs/hub/spaces)
|
177 |
+
- [SQLite Database Integration 插件](https://wordpress.org/plugins/sqlite-database-integration/)
|
178 |
+
- [Docker 官方文档](https://docs.docker.com/)
|
179 |
+
|
180 |
+
## 🤝 贡献
|
181 |
+
|
182 |
+
欢迎���交 Issue 和 Pull Request 来改进这个项目!
|
183 |
+
|
184 |
+
## 📄 许可证
|
185 |
+
|
186 |
+
本项目遵循 WordPress 的 GPL v2 许可证。
|
db.php
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* SQLite integration for WordPress
|
4 |
+
* This file enables WordPress to use SQLite database instead of MySQL
|
5 |
+
*/
|
6 |
+
|
7 |
+
// Prevent direct access
|
8 |
+
if (!defined('ABSPATH')) {
|
9 |
+
exit;
|
10 |
+
}
|
11 |
+
|
12 |
+
// Check if SQLite extension is available
|
13 |
+
if (!extension_loaded('pdo_sqlite')) {
|
14 |
+
wp_die('SQLite PDO extension is not available. Please install php-sqlite3.');
|
15 |
+
}
|
16 |
+
|
17 |
+
// Define SQLite database path
|
18 |
+
if (!defined('DB_FILE')) {
|
19 |
+
define('DB_FILE', ABSPATH . 'wp-content/database/wordpress.db');
|
20 |
+
}
|
21 |
+
|
22 |
+
// Create database directory if it doesn't exist
|
23 |
+
$db_dir = dirname(DB_FILE);
|
24 |
+
if (!file_exists($db_dir)) {
|
25 |
+
wp_mkdir_p($db_dir);
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Custom database class for SQLite
|
30 |
+
*/
|
31 |
+
class SQLite_DB {
|
32 |
+
private $pdo;
|
33 |
+
private $last_error = '';
|
34 |
+
private $last_insert_id = 0;
|
35 |
+
private $num_rows = 0;
|
36 |
+
|
37 |
+
public function __construct() {
|
38 |
+
$this->connect();
|
39 |
+
}
|
40 |
+
|
41 |
+
private function connect() {
|
42 |
+
try {
|
43 |
+
$this->pdo = new PDO('sqlite:' . DB_FILE);
|
44 |
+
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
45 |
+
$this->pdo->exec('PRAGMA foreign_keys = ON');
|
46 |
+
} catch (PDOException $e) {
|
47 |
+
$this->last_error = $e->getMessage();
|
48 |
+
wp_die('Database connection failed: ' . $this->last_error);
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
public function query($sql) {
|
53 |
+
try {
|
54 |
+
// Convert MySQL syntax to SQLite
|
55 |
+
$sql = $this->mysql_to_sqlite($sql);
|
56 |
+
|
57 |
+
$stmt = $this->pdo->prepare($sql);
|
58 |
+
$result = $stmt->execute();
|
59 |
+
|
60 |
+
if ($result) {
|
61 |
+
$this->last_insert_id = $this->pdo->lastInsertId();
|
62 |
+
$this->num_rows = $stmt->rowCount();
|
63 |
+
return $stmt;
|
64 |
+
}
|
65 |
+
|
66 |
+
return false;
|
67 |
+
} catch (PDOException $e) {
|
68 |
+
$this->last_error = $e->getMessage();
|
69 |
+
return false;
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
private function mysql_to_sqlite($sql) {
|
74 |
+
// Basic MySQL to SQLite conversion
|
75 |
+
$sql = str_replace('`', '"', $sql);
|
76 |
+
$sql = preg_replace('/AUTO_INCREMENT/i', 'AUTOINCREMENT', $sql);
|
77 |
+
$sql = preg_replace('/INT\(\d+\)/i', 'INTEGER', $sql);
|
78 |
+
$sql = preg_replace('/TINYINT\(\d+\)/i', 'INTEGER', $sql);
|
79 |
+
$sql = preg_replace('/BIGINT\(\d+\)/i', 'INTEGER', $sql);
|
80 |
+
$sql = preg_replace('/VARCHAR\((\d+)\)/i', 'TEXT', $sql);
|
81 |
+
$sql = preg_replace('/LONGTEXT/i', 'TEXT', $sql);
|
82 |
+
$sql = preg_replace('/DATETIME/i', 'TEXT', $sql);
|
83 |
+
$sql = preg_replace('/TIMESTAMP/i', 'TEXT', $sql);
|
84 |
+
|
85 |
+
return $sql;
|
86 |
+
}
|
87 |
+
|
88 |
+
public function get_results($sql, $output = OBJECT) {
|
89 |
+
$stmt = $this->query($sql);
|
90 |
+
if (!$stmt) return null;
|
91 |
+
|
92 |
+
$results = [];
|
93 |
+
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
94 |
+
if ($output === OBJECT) {
|
95 |
+
$results[] = (object) $row;
|
96 |
+
} else {
|
97 |
+
$results[] = $row;
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
return $results;
|
102 |
+
}
|
103 |
+
|
104 |
+
public function get_row($sql, $output = OBJECT) {
|
105 |
+
$stmt = $this->query($sql);
|
106 |
+
if (!$stmt) return null;
|
107 |
+
|
108 |
+
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
109 |
+
if (!$row) return null;
|
110 |
+
|
111 |
+
if ($output === OBJECT) {
|
112 |
+
return (object) $row;
|
113 |
+
}
|
114 |
+
|
115 |
+
return $row;
|
116 |
+
}
|
117 |
+
|
118 |
+
public function get_var($sql) {
|
119 |
+
$stmt = $this->query($sql);
|
120 |
+
if (!$stmt) return null;
|
121 |
+
|
122 |
+
$row = $stmt->fetch(PDO::FETCH_NUM);
|
123 |
+
return $row ? $row[0] : null;
|
124 |
+
}
|
125 |
+
|
126 |
+
public function insert_id() {
|
127 |
+
return $this->last_insert_id;
|
128 |
+
}
|
129 |
+
|
130 |
+
public function last_error() {
|
131 |
+
return $this->last_error;
|
132 |
+
}
|
133 |
+
|
134 |
+
public function num_rows() {
|
135 |
+
return $this->num_rows;
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
// Initialize SQLite database connection
|
140 |
+
$wpdb = new SQLite_DB();
|
141 |
+
|
142 |
+
// WordPress database compatibility
|
143 |
+
if (!isset($GLOBALS['wpdb'])) {
|
144 |
+
$GLOBALS['wpdb'] = $wpdb;
|
145 |
+
}
|
start-hf.sh
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
set -e
|
3 |
+
|
4 |
+
echo "Starting WordPress for Hugging Face Spaces..."
|
5 |
+
|
6 |
+
# Create necessary directories
|
7 |
+
mkdir -p /var/www/html/wp-content/database
|
8 |
+
mkdir -p /var/www/html/wp-content/uploads
|
9 |
+
mkdir -p /var/www/html/wp-content/cache
|
10 |
+
|
11 |
+
# Set proper permissions
|
12 |
+
chown -R www-data:www-data /var/www/html
|
13 |
+
chmod -R 755 /var/www/html
|
14 |
+
chmod 644 /var/www/html/.htaccess
|
15 |
+
|
16 |
+
# Initialize SQLite database if it doesn't exist
|
17 |
+
if [ ! -f "/var/www/html/wp-content/database/wordpress.db" ]; then
|
18 |
+
echo "Initializing WordPress database..."
|
19 |
+
|
20 |
+
# Create empty SQLite database
|
21 |
+
touch /var/www/html/wp-content/database/wordpress.db
|
22 |
+
chown www-data:www-data /var/www/html/wp-content/database/wordpress.db
|
23 |
+
chmod 644 /var/www/html/wp-content/database/wordpress.db
|
24 |
+
|
25 |
+
# Initialize WordPress tables using WP-CLI if available, or let WordPress handle it
|
26 |
+
echo "Database will be initialized on first visit"
|
27 |
+
fi
|
28 |
+
|
29 |
+
# Create a simple index.html for health check
|
30 |
+
cat > /var/www/html/health.html << 'EOF'
|
31 |
+
<!DOCTYPE html>
|
32 |
+
<html>
|
33 |
+
<head>
|
34 |
+
<title>WordPress on Hugging Face Spaces</title>
|
35 |
+
<meta charset="utf-8">
|
36 |
+
<style>
|
37 |
+
body { font-family: Arial, sans-serif; margin: 40px; background: #f1f1f1; }
|
38 |
+
.container { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
|
39 |
+
.status { color: #46b450; font-weight: bold; }
|
40 |
+
.info { background: #e7f3ff; padding: 15px; border-radius: 4px; margin: 20px 0; }
|
41 |
+
</style>
|
42 |
+
</head>
|
43 |
+
<body>
|
44 |
+
<div class="container">
|
45 |
+
<h1>🚀 WordPress on Hugging Face Spaces</h1>
|
46 |
+
<p class="status">✅ Service is running</p>
|
47 |
+
<div class="info">
|
48 |
+
<h3>📋 Setup Information:</h3>
|
49 |
+
<ul>
|
50 |
+
<li><strong>WordPress Version:</strong> 6.8.1</li>
|
51 |
+
<li><strong>PHP Version:</strong> 8.3</li>
|
52 |
+
<li><strong>Database:</strong> SQLite</li>
|
53 |
+
<li><strong>Web Server:</strong> Apache</li>
|
54 |
+
</ul>
|
55 |
+
</div>
|
56 |
+
<p><a href="/" style="background: #0073aa; color: white; padding: 10px 20px; text-decoration: none; border-radius: 4px;">🏠 Go to WordPress</a></p>
|
57 |
+
<p><a href="/wp-admin/" style="background: #46b450; color: white; padding: 10px 20px; text-decoration: none; border-radius: 4px;">⚙️ Admin Panel</a></p>
|
58 |
+
</div>
|
59 |
+
</body>
|
60 |
+
</html>
|
61 |
+
EOF
|
62 |
+
|
63 |
+
# Create demo content script
|
64 |
+
cat > /var/www/html/wp-content/demo-setup.php << 'EOF'
|
65 |
+
<?php
|
66 |
+
/**
|
67 |
+
* Demo content setup for WordPress on HF Spaces
|
68 |
+
*/
|
69 |
+
if (!defined('ABSPATH')) {
|
70 |
+
define('ABSPATH', dirname(__FILE__) . '/../');
|
71 |
+
}
|
72 |
+
|
73 |
+
require_once ABSPATH . 'wp-config.php';
|
74 |
+
require_once ABSPATH . 'wp-includes/wp-db.php';
|
75 |
+
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
76 |
+
|
77 |
+
// Create demo user if not exists
|
78 |
+
if (!username_exists('demo') && !email_exists('[email protected]')) {
|
79 |
+
$user_id = wp_create_user('demo', 'demo123', '[email protected]');
|
80 |
+
if (!is_wp_error($user_id)) {
|
81 |
+
$user = new WP_User($user_id);
|
82 |
+
$user->set_role('administrator');
|
83 |
+
echo "Demo user created: demo/demo123\n";
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
// Create demo post
|
88 |
+
$demo_post = array(
|
89 |
+
'post_title' => 'Welcome to WordPress on Hugging Face Spaces!',
|
90 |
+
'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>',
|
91 |
+
'post_status' => 'publish',
|
92 |
+
'post_author' => 1,
|
93 |
+
'post_type' => 'post'
|
94 |
+
);
|
95 |
+
|
96 |
+
if (!get_page_by_title('Welcome to WordPress on Hugging Face Spaces!')) {
|
97 |
+
wp_insert_post($demo_post);
|
98 |
+
echo "Demo post created\n";
|
99 |
+
}
|
100 |
+
|
101 |
+
echo "Demo setup completed\n";
|
102 |
+
?>
|
103 |
+
EOF
|
104 |
+
|
105 |
+
# Set up WordPress if not already configured
|
106 |
+
if [ ! -f "/var/www/html/wp-config.php" ]; then
|
107 |
+
echo "WordPress configuration not found, copying HF Spaces config..."
|
108 |
+
cp /var/www/html/wp-config-hf.php /var/www/html/wp-config.php
|
109 |
+
fi
|
110 |
+
|
111 |
+
# Start Apache in background
|
112 |
+
echo "Starting Apache web server on port 7860..."
|
113 |
+
apache2-foreground &
|
114 |
+
APACHE_PID=$!
|
115 |
+
|
116 |
+
# Wait for Apache to start
|
117 |
+
sleep 5
|
118 |
+
|
119 |
+
# Check if WordPress is accessible
|
120 |
+
echo "Checking WordPress accessibility..."
|
121 |
+
if curl -f http://localhost:7860/health.html > /dev/null 2>&1; then
|
122 |
+
echo "✅ WordPress is accessible at http://localhost:7860"
|
123 |
+
else
|
124 |
+
echo "⚠️ WordPress may not be fully ready yet"
|
125 |
+
fi
|
126 |
+
|
127 |
+
# Keep the container running
|
128 |
+
echo "WordPress is ready! Access it at https://your-space-name.hf.space"
|
129 |
+
echo "Admin panel: https://your-space-name.hf.space/wp-admin/"
|
130 |
+
echo "Demo credentials: demo/demo123"
|
131 |
+
|
132 |
+
# Wait for Apache process
|
133 |
+
wait $APACHE_PID
|
wp-config-hf.php
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WordPress configuration for Hugging Face Spaces deployment
|
4 |
+
* Uses SQLite database instead of MySQL
|
5 |
+
*/
|
6 |
+
|
7 |
+
// ** SQLite Database settings ** //
|
8 |
+
define('DB_NAME', 'wordpress');
|
9 |
+
define('DB_USER', 'root');
|
10 |
+
define('DB_PASSWORD', '');
|
11 |
+
define('DB_HOST', 'localhost');
|
12 |
+
define('DB_CHARSET', 'utf8');
|
13 |
+
define('DB_COLLATE', '');
|
14 |
+
|
15 |
+
// Force SQLite usage
|
16 |
+
define('DB_FILE', 'wp-content/database/wordpress.db');
|
17 |
+
define('USE_MYSQL', false);
|
18 |
+
|
19 |
+
/**#@+
|
20 |
+
* Authentication unique keys and salts for security
|
21 |
+
*/
|
22 |
+
define('AUTH_KEY', 'hf-spaces-auth-key-' . md5(__FILE__));
|
23 |
+
define('SECURE_AUTH_KEY', 'hf-spaces-secure-auth-key-' . md5(__FILE__));
|
24 |
+
define('LOGGED_IN_KEY', 'hf-spaces-logged-in-key-' . md5(__FILE__));
|
25 |
+
define('NONCE_KEY', 'hf-spaces-nonce-key-' . md5(__FILE__));
|
26 |
+
define('AUTH_SALT', 'hf-spaces-auth-salt-' . md5(__FILE__));
|
27 |
+
define('SECURE_AUTH_SALT', 'hf-spaces-secure-auth-salt-' . md5(__FILE__));
|
28 |
+
define('LOGGED_IN_SALT', 'hf-spaces-logged-in-salt-' . md5(__FILE__));
|
29 |
+
define('NONCE_SALT', 'hf-spaces-nonce-salt-' . md5(__FILE__));
|
30 |
+
/**#@-*/
|
31 |
+
|
32 |
+
/**
|
33 |
+
* WordPress database table prefix
|
34 |
+
*/
|
35 |
+
$table_prefix = 'wp_';
|
36 |
+
|
37 |
+
/**
|
38 |
+
* WordPress debugging mode - enabled for demo purposes
|
39 |
+
*/
|
40 |
+
define('WP_DEBUG', false);
|
41 |
+
define('WP_DEBUG_LOG', false);
|
42 |
+
define('WP_DEBUG_DISPLAY', false);
|
43 |
+
|
44 |
+
/**
|
45 |
+
* WordPress URLs and paths for HF Spaces
|
46 |
+
*/
|
47 |
+
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
|
48 |
+
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
|
49 |
+
|
50 |
+
// Handle HTTPS detection behind proxy
|
51 |
+
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
|
52 |
+
$_SERVER['HTTPS'] = 'on';
|
53 |
+
}
|
54 |
+
|
55 |
+
// Force HTTPS for admin and login
|
56 |
+
define('FORCE_SSL_ADMIN', true);
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Increase memory limit for better performance
|
60 |
+
*/
|
61 |
+
define('WP_MEMORY_LIMIT', '256M');
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Disable file editing from admin panel for security
|
65 |
+
*/
|
66 |
+
define('DISALLOW_FILE_EDIT', true);
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Auto-update settings
|
70 |
+
*/
|
71 |
+
define('WP_AUTO_UPDATE_CORE', true);
|
72 |
+
define('AUTOMATIC_UPDATER_DISABLED', false);
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Multisite settings (disabled for simplicity)
|
76 |
+
*/
|
77 |
+
define('WP_ALLOW_MULTISITE', false);
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Custom settings for demo environment
|
81 |
+
*/
|
82 |
+
define('WP_POST_REVISIONS', 3);
|
83 |
+
define('AUTOSAVE_INTERVAL', 300);
|
84 |
+
define('EMPTY_TRASH_DAYS', 7);
|
85 |
+
|
86 |
+
/**
|
87 |
+
* File permissions
|
88 |
+
*/
|
89 |
+
define('FS_CHMOD_DIR', (0755 & ~ umask()));
|
90 |
+
define('FS_CHMOD_FILE', (0644 & ~ umask()));
|
91 |
+
|
92 |
+
/* That's all, stop editing! Happy publishing. */
|
93 |
+
|
94 |
+
/** Absolute path to the WordPress directory. */
|
95 |
+
if (!defined('ABSPATH')) {
|
96 |
+
define('ABSPATH', __DIR__ . '/');
|
97 |
+
}
|
98 |
+
|
99 |
+
/** Sets up WordPress vars and included files. */
|
100 |
+
require_once ABSPATH . 'wp-settings.php';
|