Sunday, February 24, 2019

Laravel on nginx+php-fpm returns blank page



I'm having this issue with Laravel which is served by nginx + php-fpm, it's just returning a blank page. Neither nginx nor php nor laravel are logging any errors at all.




When running the index.php with the CLI, it will return the welcome page.



The laravel stack is untouched, all error reporting/displaying/logging is turned on.



Below is my nginx vhost:



server {
listen 801;
server_name _;


root /path/to/laravel/public;
index index.html index.html index.php;

charset utf-8;

gzip on;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6].";
gzip_vary on;

gzip_proxied expired no-cache no-store private auth;
gzip_comp_level 9;

fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_read_timeout 180;

# serve static files directly
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;

expires max;
}

location / {
index index.html index.htm index.php; #try static .html file first
##try_files $uri $uri/ /index.php; < try_files $uri $uri/ /index.php?q=$uri&$args;
}

# catch all

error_page 404 /index.php;

#set client_max_body_size
client_max_body_size 25m;
#set client_body_buffer_size
client_body_buffer_size 128k;

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}





My problem was that app/storage had the wrong permissions. So if you get the same errors as myself, blank page, try chmod 0777 the entire app/storage folder.




sudo chmod -R 0777 app/storage

Answer



OP stated that his working solution is sudo chmod -R 0777 app/storage.



While it solved the problem, it is never the solution. The proper way is set the group as www-data and give it write permission.



chown -R www-data app/storage
chmod -R 0770 app/storage



For details explanation about chmod 777 and permissions on a Linux webserver, see this answer: What permissions should my website files/folders have on a Linux webserver?


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...