在使用Laravel的过程中,偶尔会进行重构类名等等,但在这种情况下,会出现一个莫名其妙的错误:“laravel failed to open stream: Undefined error: 0”。总结下来,有几条命令值得尝试:
composer dumpautoload
php artisan clear-compiled
php artisan config:cache
php artisan optimize
执行命令 php artisan cache:clear 并赋予 /storage 文件夹读写权限: chmod -R 777 storage;
若在执行 php artisan cache:clear 时出现错误:Uncaught UnexpectedValueException: The stream or file “/storage/logs/laravel.log” could not be opened: failed to open stream: Permission denied in /vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:87,需要赋予 /storage/log 读写权限: chmod -R 777 storage/logs;
此时再执行 php artisan cache:clear,若继续出错:[ErrorException] file_put_contents(/bootstrap/cache/services.php): failed to open stream: Permission denied,需要赋予 bootstrap/cache 读写权限:chmod -R 777 bootstrap/cache;
再执行 php artisan cache:clear,若仍然出错:[PDOException] SQLSTATE[HY000] [1045] Access denied for user ‘xxx’@’127.0.0.1’ (using password: YES),则需要查看 laravel 的数据库配置是否正确。