直接原因是php artisan admin:install命令执行时php进程对storage、bootstrap/cache等目录无写权限;需执行chown -r www:www项目目录、chmod -r 775 storage bootstrap/cache,并确认nginx配置中location ~ .php$块包含fastcgi_param script_filename $document_root$fastcgi_script_name;,同时运行php artisan key:generate生成app_key。

laravel-admin install 报错 “Permission denied” 怎么办
直接原因是 php artisan admin:install 命令在写入数据库迁移文件、生成配置或创建 storage 目录时,PHP 进程(通常是 www 或 nginx 用户)对项目目录无写权限。LNMP 环境下尤其常见。
- 先确认当前用户组:运行
ps aux | grep nginx或ps aux | grep php-fpm,看 worker 进程以哪个用户身份运行(常见为www) - 执行
chown -R www:www your-laravel-project/(把整个项目目录归属改掉,不是只改storage) - 特别注意
bootstrap/cache目录:它常被忽略,但admin:install会尝试写packages.php,必须可写 - 别只 chmod 755 —— 对
storage和bootstrap/cache要用chmod -R 775,否则 PHP 写日志或缓存时仍失败
为什么改了 www:www 还报错?检查这几个路径
LNMP1.6 默认的 Nginx + PHP-FPM 组合下,即使改了目录属主,也可能因 open_basedir 限制或 SELinux(极少见)拦截写操作。优先排查以下三处:
-
storage/:必须存在且www可写;若不存在,手动mkdir -p storage/logs storage/framework/{cache,sessions,views} -
bootstrap/cache/:config.php和packages.php在这里生成,不可为空也不可只读 -
public/vendor/laravel-admin/:如果这个目录为空,说明php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider"没跑成功——它同样依赖写权限
lnmp vhost 配置里漏了 fastcgi_param,导致 install 权限校验失败
LNMP1.6 的默认虚拟主机配置中,fastcgi_param 缺少关键项,会导致 Laravel 的 is_writable() 判断始终返回 false,哪怕目录权限正确。
- 编辑你的站点配置:
/usr/local/nginx/conf/vhost/xxx.conf - 在
location ~ \.php$块内,确认包含这行:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - 缺这行时,
admin:install会误判当前路径为根目录(如/),而/显然不可写 - 改完后必须执行
lnmp nginx reload,不是restart
APP_KEY 未生成也会伪装成权限错误
看起来像权限问题,实际是 Laravel 启动阶段就卡住了:admin:install 依赖完整的 Laravel 初始化,而 APP_KEY 缺失会导致 Encrypter 构造失败,抛出异常并中断后续流程。
- 运行
php artisan key:generate,确保.env中已写入APP_KEY=base64:... - 如果提示
No application encryption key has been specified,就是这个原因 - 该错误有时不直接显示在终端,而是静默失败,最终表现为
admin:install无反应或报错位置飘忽
最易被忽略的是 bootstrap/cache 目录权限和 fastcgi_param SCRIPT_FILENAME 缺失——这两处不报明确错误,但会让所有写操作“假装失败”。动手前先确认这两点,比反复 chown 更有效。











