环境配置
本文档介绍 mdView 文档系统的开发环境配置要求和步骤。
系统要求
PHP 配置要求
在 php.ini 中确保以下配置:
; 必需配置
short_open_tag = On
session.save_path = "/path/to/session"
session.gc_maxlifetime = 1440
; 推荐配置
memory_limit = 128M
max_execution_time = 30
post_max_size = 8M
upload_max_filesize = 2M
安装步骤
1. 安装 PHP
Windows
从 php.net 下载 PHP Windows 版本:
C:\phpC:\php 添加到系统环境变量 PATHphp.ini-development 为 php.inimacOS
使用 Homebrew 安装:
brew install php
Ubuntu/Debian
sudo apt update
sudo apt install php php-cli php-json php-session
2. 验证安装
php --version
应输出类似:
PHP 8.2.13 (cli) (built: Nov 28 2023 08:27:24) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.13, Copyright (c) Zend Technologies
3. 配置 Web 服务器
Apache 配置
<VirtualHost *:80>
ServerName docs.example.com
DocumentRoot "/path/to/mdView"
<Directory "/path/to/mdView">
AllowOverride All
Require all granted
</Directory>
# 确保 PHP 处理 .php 文件
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
</VirtualHost>
Nginx 配置
server {
listen 80;
server_name docs.example.com;
root /path/to/mdView;
index index.php;
# 静态文件缓存
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
# 路由重写
location / {
try_files $uri $uri/ /index.php?$args;
}
# PHP 处理
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
开发环境
启动开发服务器
# 进入项目目录
cd mdView
# 启动 PHP 内置服务器
php -S localhost:8080 -t .
# 访问 http://localhost:8080
调试模式
设置环境变量启用调试模式:
# Linux/macOS
export MDVIEW_DEBUG=true
# Windows
set MDVIEW_DEBUG=true
目录权限
确保以下目录和文件可写:
# Linux/macOS
chmod -R 755 data/
chown -R www-data:www-data data/
data/mdview.db 是 SQLite 数据库文件,Web 服务器进程必须对其有读写权限。
依赖说明
mdView 默认使用 SQLite 作为数据库,无需额外安装 MySQL/PostgreSQL。PHP 的 pdo_sqlite 扩展通常已内置。
如需使用其他数据库,创建 config.php 配置文件即可:
SQLite 模式下,所有数据存储在 data/mdview.db 单个文件中,备份和迁移只需复制此文件。
详细配置参见 数据库系统文档。
IDE 推荐
推荐编辑器
推荐插件
常见问题
Q: PHP 找不到怎么办?
确保 PHP 已添加到系统 PATH:
# 检查 PATH
echo $PATH
# 添加 PHP 到 PATH(Linux/macOS)
export PATH="/usr/local/php/bin:$PATH"
Q: 权限错误怎么办?
确保 data/ 目录有写入权限:
chmod -R 775 data/
Q: 页面显示空白怎么办?
检查 PHP 错误日志:
# 查看错误日志
tail -f /var/log/apache2/error.log
# 或
tail -f /var/log/nginx/error.log