- Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255
[xx@localhost api]$ composer dump-autoload
Generating optimized autoload files
Class Illuminate\Foundation\ComposerScripts is not autoloadable, can not call post-autoload-dump script
> @php artisan package:discover
Fatal error: Uncaught Error: Class 'Illuminate\Foundation\Application' not found in /data/www/default/dms/api/bootstrap/app.php:14
Stack trace:
#0 /data/www/default/dms/api/artisan(20): require_once()
#1 {main}
thrown in /data/www/default/dms/api/bootstrap/app.php on line 14
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255
解决方案:composer install
- Laravel 出现 No application encryption key has been specified.
1、.env.example 改名使用命令 copy 修改为 .env
2、使用命令 php artisan key:generate 获取密码,自动保存到 .env
3、将密码复制到config/app.php 中的key里面
4、重新运行,OK。
- Laravel 报错 file_put_contents(): failed to open stream 的解决方法
执行命令 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 的数据库配置是否正确
- Laravel nginx.conf 配置加上
server
{
listen 80 default_server;
#listen [::]:80 default_server ipv6only=on;
server_name _;
index index.html index.htm index.php;
root /home/wwwroot/default/laravel-Learning/public/;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log;
}
include vhost/*.conf;
}
- 部署 Laravel 项目, 配置了 vhost 仍报错 500,可能有一下两个原因:
⑴ 删除根目录下因为配置 vhost 生成的 .user.ini,官方 https://lnmp.org/faq/lnmp-vhost-add-howto.html#user.ini
LNMP 1.4上如果不想用防跨目录或者修改.user.ini的防跨目录的目录还需要将 /usr/local/nginx/conf/fastcgi.conf 里面的fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/"; 在该行行前添加 # 或删除改行,需要重启nginx。
⑵ 根目录运行 chmod -R 777 storage 和 chmod -R 777 bootstrap,给予这两个目录权限
- laravel 目录设置
[HOST=192.168.1.163]
open_basedir=/home/wwwroot/default/laravel-Learning:/proc/:/tmp/
[PATH=/home/wwwroot/default/laravel-Learning]
open_basedir=/home/wwwroot/default/laravel-Learning:/proc/:/tmp/
- 部署 laravel 定时任务
* * * * * /usr/local/php/bin/php /home/wwwroot/www.whatwhat.top/artisan schedule:run >> /dev/null 2>&1
第一部分是 php 所在目录 ;第二部分是项目根目录;最后schedule是laravel提供的命令行,每分钟调用一次命令 project\app\Console 中的命令来执行代码进行相应操作
- Linux下全局安装composer方法
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
composer config -g repo.packagist composer https://packagist.phpcomposer.com
输入composer验证: