php - laravel deployed to linux, specifying the public folder as the website root directory, but its subfolders cannot be accessed
PHP中文网
PHP中文网 2017-06-05 11:08:16
0
8
2022

This machine uses a window environment, everything is normal, but it is deployed on a Linux system (with nginx). When accessed, the controller and methods can be executed normally, and the page can also be output, but the output page But the css file is missing. After checking, it is a 500 error. The request has been redirected to the public folder.
My directory structure is:

public/web/css/css.css

The domain name is:

aaa.com 

Directly accessing aaa.com will execute Public/index.php (because nginx is set up to redirect the request to the public folder), and the page can also be output normally, but the page requested:

url:aaa.com/web/css/css.css

It’s an error of 500. I can’t figure it out. Please give me some advice. Thank you all.


Now I found that part of the problem is nginx configuration problem, I copied the settings online:

server {
        listen       80;
        server_name  xxx;

        access_log  xxx  main;

        root       xxx;
        #root       xxx;
        index      index.php index.html index.htm;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        }

   }

Although you can access the homepage now, there is another problem now. My project has a front and backend. The frontend can be accessed, but the backend cannot be accessed. This is how I implement the frontend and backend. I use routing separation. The map method in RouteProvider.php configures two routing files:

    public function map(Router $router) {
        //加载前台路由文件
        $router->group([
            'namespace' => 'App\Http\WebControllers',
//             'prefix' => 'Web',//引入前缀
            //'middleware' => 'some_common_middleware',
                ], function ($router) {
            require app_path('Http/routes/routes.php');
        });
        //加载后台路由文件
        $router->group([
            'namespace' => 'App\Http\AdminControllers',
            'middleware' => 'App\Http\Middleware\LoginMenuMiddleware',
            'prefix' => 'Am',//引入前缀
                ], function ($router) {
            require app_path('Http/routes/admin_routes.php');
        });
    }
    
    

Now I cannot log in to the backend, that is, xxx.com/Am/Index/index will send a 500 error, and the ajax in the frontend cannot be executed.


Project structure directory:


Thank you everyone for your help. It's a pity that it can only be adopted by a great god in the end. The situation is like this. I will explain it here in case someone in the future has the same situation as me.
If the same thing happens to me In this case, please first check whether there are cache files in the bootstrap/cache directory of the server. If there are, please clear them and try again. It is indeed caused by the existence of cache.

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(8)
PHPzhong

Thank you for the invitation.

Personally, there are a few mistakes in deployment on Linux:

1. Case sensitive.

2. The folder development part under laravel uses soft connections.

3.index.php Under public, static resources should correspond to public.

If the problem is not solved, please post your project structure directory

Ty80

Thanks for the invitation!

You can only exclude them one by one like this

  1. Troubleshoot file cache issues

  2. Directory permission problem, modify the directory permissions to 755

黄舟

500 is an internal server error, indicating that there is an error in your code, not 404, Not found

洪涛

Users and groups must be set in the configuration of php-fpm

vim /etc/php-fpm.d/www.conf

Modify user group configuration

user = nginx
group = nginx

Set user group to nginx

chown -R nginx:nginx /path/to/your/webroot

The following directories of laravel require write permission

chmod -R 0775 bootstrap
chmod -R 0775 storage

The vhost configuration for laravel is as follows:

    root /www/path/to/public/;
    location / {
        index index.php;
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php/ last;
            break;
        }
    }

    # 解析PHP
    location ~ .+\.php($|/) {
        set $script $uri;
        set $path_info "/";
        if ($uri ~ "^(.+\.php)(/.+)") {
            set $script    ;
            set $path_info    ;
        }

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php?IF_REWRITE=1;
        include fastcgi_params;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param SCRIPT_FILENAME $document_root/$script;
        fastcgi_param SCRIPT_NAME $script;
        fastcgi_param HTTP_PROXY "";
    }
迷茫

500 error is very simple ~

If 500 is wrong, there will definitely be a prompt

The network panel in the browser may not be able to capture the results. You can open it directly in a new note to view the tips

Or check the files under this directory. Whenever an error occurs, a log will be generated

$ cd {项目目录}/storage/logs
巴扎黑

rewrite doesn’t work. . You need to first determine whether the file exists before rewriting

世界只因有你

It’s best to post the error returned by the framework

伊谢尔伦

Thank you everyone for your help. It is a pity that it can only be adopted by a great god in the end. The situation is like this, and I will explain it here in case someone else has the same situation as me.
If the same situation as me occurs, please first Check whether there are cache files in the bootstrap/cache directory of the server. If there are, please clear them and try again. It is indeed caused by the existence of cache.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template