vendor/tp目录下没有thinkphp文件是因为TP6核心包名已改为topthink/think,正确命令是composer create-project topthink/think project-name;安装后需用php think run启动,注意autoload和public路径配置。

composer create-project 装出来的 tp6 为什么 vendor/tp 目录下没有 thinkphp 文件?
因为 thinkphp/framework 是旧版(5.x)的包名,TP6 的核心包已改为 topthink/think。用错包名会导致拉取空壳或旧版骨架。
- 正确命令是:
composer create-project topthink/think project-name - 如果指定了 PHP 版本(如 8.1+),建议加
--ignore-platform-reqs避免因扩展缺失中断安装 - 国内网络慢时,先执行
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/换源
安装后访问提示 “The requested URL was not found on this server”
TP6 默认不带 public/index.php 的 Web 服务器路由配置,直接用 php -S 启动是最简验证方式。
- 进项目根目录,运行:
php think run(等价于php -S 127.0.0.1:8000 -t public/) - 别用
php -S直接指定index.php—— TP6 的入口文件依赖public/为 Web 根,否则__DIR__计算会错位 - Apache 用户必须启用
mod_rewrite,且确保public/.htaccess未被忽略(有些主机默认禁用 .htaccess)
vendor/autoload.php 找不到或报 Class 'thinkContainer' not found
本质是自动加载没生效,常见于手动移动了 vendor 或修改了 composer.json 后没重装 autoload。
- 删掉
vendor/和composer.lock,重新跑composer install - 确认
composer.json中"autoload"段有"psr-4": {"think\": "vendor/topthink/think/src/"}这类映射(新版 TP6 已内置,但若自己改过就可能丢失) - 不要在
public/index.php里硬写require __DIR__.'/../vendor/autoload.php'的绝对路径——万一项目挪位置就挂,应保持相对引用
php think migrate 报错 “Class 'thinkmigrationCommand' not found”
TP6 默认不带迁移命令,think-migration 是独立扩展,需手动引入且版本必须匹配框架主版本。
立即学习“PHP免费学习笔记(深入)”;
- 装对版本:
composer require topthink/think-migration:^3.0(对应 TP6.0–6.1);TP6.2+ 推荐用^4.0 - 装完要注册命令:在
app/command.php里加一行thinkmigrationCommand::class - 迁移文件生成后,
php think migrate:run前务必检查config/migrate.php里的数据库连接是否指向真实环境,别用默认的sqlite空配置硬跑











