外观
Laravel
约 401 字大约 1 分钟
2025-06-20
创建项目
laravel new example-app启动项目
php artisan serve路由
#查看已设置路由列表
php artisan route:list
#清除路由缓存
php artisan route:clear
#缓存路由
php artisan route:cache缓存
#清除配置缓存
php artisan config:clear
#缓存配置
php artisan config:cache
#清除视图缓存
php artisan view:clear
#缓存视图
php artisan view:cache
#清除缓存
php artisan cache:clear优化类加载
php artisan optimize数据
# 数据迁移和更新
php artisan migrate
# 数据填充
php artisan db:seed
php artisan db:seed --class=UserSeeder上线流程
- 创建项目,或者克隆项目
- 从.env.example复制一份,重命名为.env
- 配置项目信息、数据库信息、redis信息等
- 安装依赖
composer install --no-dev --optimize-autoloader- 生成key
php artisan key:generate- 设置权限
chmod -R 777 storage
chmod -R 777 bootstrap/cache- 如果使用了前端框架,需要编译前端代码
npm install
npm run build # 或者 vite build- 数据库迁移
php artisan migrate --force- 创建存储目录的符号链接
php artisan storage:link- 进入维护模式(如有需要)
php artisan down- 完成部署后退出维护模式
php artisan up- 添加 Cron 任务(如果有)
* * * * * cd /path/to/your/project && php artisan schedule:run >> /dev/null 2>&1解决提示 key was too long
https://stackoverflow.com/questions/42244541/laravel-migration-error-syntax-error-or-access-violation-1071-specified-key-wa
跨环境设置视图编译路径
修改config/view.php配置
return [
'compiled' => env(
'VIEW_COMPILED_PATH',
realpath(storage_path('framework/views'))
),
// ...
];检查存储目录权限
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage在 .env 文件中添加视图编译路径
#VIEW_COMPILED_PATH=/absolute/path/to/your/storage/framework/views