Some problem records of laravel+nginx error 500 after configuration have been solved

1, Check the ngxin configuration. Here is my nginx configuration

Here paste the source code for your reference:

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; 
        #} 
        # Remove index action 
        #if ($request_uri ~* index/?$)  
        #{ 
        #    rewrite ^/(.*)/index/?$ /$1 permanent; 
        #} 
        # url rewriting according to laravel rules    
        #if (!-e $request_filename)     
        #{ 
        #    rewrite ^/(.*)$ /index.php?/$1 last; 
        #    break; 
        #} 
        #error_page   500 502 503 504  /50x.html; 
        #location = /50x.html { 
        #    root   html; 
        #} 
    } 
}

2, Let's look at the fastcgi.conf and fastcgi_params files. Add a line at the bottom of the fastcgi.conf file

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/:/var/www/buxingjie/";

3, Empower storage and bootstrap/cache to two folders under the root directory of the project

chmod -R 777 storage

4, Check whether the PHP extensions required by laravel have been installed

Check that it is installed:

php -m | grep 'json'

You can also output phpinfo() in the index.php file in the root directory of the project to view it

If nginx configuration is OK, write exit('cs') in the index.php file; CS should be displayed on the browser;

5, Let me tell you something

ngxin+laravel has been configured, browser access error report 500, which hasn't been solved all afternoon, search various ways, without any prompt, PHP error report has also been opened, nginx error report has also been checked

Later, I gave up and began to study the source code. I followed the contents in index.php step by step to see the source code ($request = Illuminate\Http\Request::capture() from here, mainly because it didn't continue to execute here), printed breakpoint tests, and found that json expansion was not installed, and php.ini was not configured

Installation expansion( How to install PHP extension reference this link ), configuring php.ini solves the problem, so sometimes when you don't have ideas, you can follow the code step by step, maybe better.

Keywords: Programming PHP Nginx Laravel JSON

Added by a6000000 on Wed, 29 Apr 2020 17:13:02 +0300