I want to run Laravel6 with nginx and php7.3 on Amazon Linux2.

Error message Only when

/laravel-path/publicis the document root, it becomes 404 for some reason.

If i look at the log, i am going to see 50x.html for some reason.

2019/12/02 00:43:52 [error] 4280 # 0: * 50 open () "/var/www/laravel-book-review/public/50x.html" failed (2: No such file or directory), client: **. **. ***. ***, server: _, request: "GET/HTTP/1.1", upstream: "fastcgi: // unix:/run/php -fpm/www.sock ", host:" **. ***. ***. ** "
Install command
$sudo amazon-linux-extras install -y php7.3
$sudo yum install -y php-mbstring php-dom php-zip
$sudo amazon-linux-extras install -y nginx1

laravel clones from GitHub repository and installs vendor withcomposer install.

Applicable source code


There is a lot of information that it is better not to make extra settings on Amazon Linux2, so it will only change the document root without doing anything extra.

# Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    server {
        listen 80 default_server;
        listen [::]: 80 default_server;
        server_name _;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        error_page 404 /404.html;
            location = /40x.html {
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
  • Check index.php withphinfo ()written in other than the laravel directory->php-fpm is working normally
  • Add directive setting for php file
location ~ \ .php ${
        fastcgi_split_path_info ^ (. + \. php) (/.+) $;
        fastcgi_pass unix: /var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
  • Add try_files
       try_files $uri $uri//index.php?$query_string;

I feel addicted to what I can do, so if you have noticed something, thank you.

Reference information

Move laravel with nginx

Building an environment with AWS EC2 + nginx + PHP7 + Laravel5

Supplemental information (FW/tool version etc.)


  • Answer # 1

    * This is speculation

      Only when the

    /laravel-path/public is the document root, it will be 404 for some reason.
      Looking at the log, I'm going to see 50x.html for some reason, and this is also a situation where I don't know why.

    Because I got an error, I tried to display 50x.html but it was 404 because I couldn't find it
    Isn't it anyway, how about setting 50x.html and checking whether it is 404 or any other error?

  • Answer # 2


    The essence of the problem was Laravel.

    The setting of nginx was OK as it is, but it is a top page that accesses DB, so there is no connection to DB instorage/logs/laravel-logdid.

    I missed here, so it took me a while, but if there is a similar person,

    chmod 0777 -R storage

    If you give the write permission in, you can easily understand the cause of the problem.