环境要求: - PHP >= 7.4 - PDO 扩展 - Composer - Web 服务器(如 Apache 或 Nginx) 下载 ThinkPHP: 1. 访问 ThinkPHP 官方网站 https://thinkphp.cn 或 GitHub 仓库 https://github.com/top-think/think 2. 可以通过 Composer 安装,使用以下命令: composer create-project topthink/think tp 3. 如果你想下载最新的源码,可以直接从 GitHub 下载或通过 Composer 安装。 配置 Web 服务器: 推荐使用 Nginx 或 Apache 作为 Web 服务器。以下是两者的配置示例: Apache 配置: 1. 将项目目录设置为网站根目录。 2. 在网站根目录下创建一个 .htaccess 文件,内容如下: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /index.php/$1 [QSA,PT,L] Nginx 配置: 1. 在 Nginx 配置文件中设置 root 和 location 参数,类似如下: server { listen 80; server_name yourdomain.com; root /path/to/your/project/public; index index.php; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; } } } 配置数据库: 1. 进入项目目录,找到 `config/database.php` 文件。 2. 配置你的数据库连接参数,例如: 'type' => 'mysql', // 数据库类型 'hostname' => '127.0.0.1', // 数据库地址 'database' => 'test', // 数据库名 'username' => 'root', // 用户名 'password' => 'root', // 密码 'hostport' => '3306', // 端口 'charset' => 'utf8', // 编码 3. 根据你的数据库配置调整连接参数。 访问网站: 1. 配置完成后,启动 Web 服务器。 2. 打开浏览器,访问 http://yourdomain.com 或 http://localhost,应该能看到 ThinkPHP 默认的欢迎页面。 3. 如果一切正常,你就可以开始开发你的应用程序了。 常见问题: - 如果在访问时遇到 404 错误,请检查 .htaccess 或 Nginx 配置是否正确。 - 如果数据库连接出错,请确认数据库配置是否正确,数据库服务是否正常运行。 - 如果页面显示白屏或空白,检查 PHP 错误日志,查看是否有报错信息。 获取帮助: 1. ThinkPHP 官方文档:https://thinkphp.cn/docs 2. GitHub 仓库:https://github.com/top-think/think 3. ThinkPHP 社区:https://forum.thinkphp.cn