一、检查ngxin配置,以下是我的nginx配置
这里粘贴下源码供大家参考:
代码语言:javascript复制user www www;
worker_processes 4;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 65;
upstream web {
server unix:/run/php-fpm/www.sock weight=100 max_fails=10 fail_timeout=30;
}
server {
listen 80;
server_name 31.297.228.158;
root /var/www/buxingjie/public/;
index index.php index.html index.htm;
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log debug;
location ~ .php$ {
fastcgi_pass web;
fastcgi_split_path_info ^(. .php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
include fastcgi.conf;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
#if (!-d $request_filename)
#{
# rewrite ^/(. )/$ /$1 permanent;
#}
# 去除index action
#if ($request_uri ~* index/?$)
#{
# rewrite ^/(.*)/index/?$ /$1 permanent;
#}
# 根据laravel规则进行url重写
#if (!-e $request_filename)
#{
# rewrite ^/(.*)$ /index.php?/$1 last;
# break;
#}
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root html;
#}
}
}
二、我们看下fastcgi.conf和fastcgi_params文件,fastcgi.conf文件底部增加一行
代码语言:javascript复制fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/:/var/www/buxingjie/";
三、对项目根目录下两个文件夹赋权storage和bootstrap/cache
chmod -R 777 storage
四、检查laravel需要的PHP拓展是否都已经安装
检查是否已经安装:
php -m | grep 'json'
也可以在项目根目录下index.php文件中输出phpinfo()进行查看
假如nginx配置没问题,index.php文件中写入exit('cs');应该会在浏览器上显示出cs;
五、告诫一下大家的话
ngxin laravel已经配置好,浏览器访问报错500,搞了一下午一直没有解决,搜索各种方式,没有任何提示,PHP报错也开了,nginx报错也查了
后来放弃了,开始研究源码,跟着index.php里面内容一步步看源码($request = IlluminateHttpRequest::capture()从这里开始,主要是这里没继续执行),打印断点测试,然后发现是json拓展没有安装,php.ini里面没有配置
安装拓展(如何安装PHP拓展参考这个链接),配置php.ini,就解决了问题,所以有时候没思路时,可以跟着代码一步步走一走,或许会更好。