部署laravel项目遇到的问题

nginx配置问题

在/etc/nginx/site-avaliable/defaut配置文件中,更改

1
2
3
4
5
6
7
8
9
10
server_name xxx;
root xxx/public;
index xxx index.php;
#在location ~ ./php$添加
# # With php7.0-fpm:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;

后,访问项目是404, 接着查了一下,发现index.php 要放在第一位。

但是更改后,还是404。继续找问题,发现:

1
2
3
location / {
try_files $uri $uri/ =404;
}

更改为:

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

好了,没报404了,但是报了500。继续找问题,看一下是不是项目权限没配置好

1
sudo chmod -R 777 /path/to/your/program/public

还是不行,最后:

1
sudo chown -R www-data:www-data xxx

最后成功访问到laravel写的接口。