一次部署Laravel框架后的总结
一、下载框架
通过 Composer 创建项目:composer create-project --prefer-dist laravel/laravel blog
二、配置
通过Composer安装的Laravel框架会缺少vender依赖目录,此时执行:
composer install
或者 composer update
三、检查有无.env文件
若无.env文件,在项目目录下执行:cp .env.example .env
然后如果访问首页时报错:No application encryption key has been specified
在框架根目录下,执行:php artisan key:generate
四、根据框架手册修改Nginx配置文件
server {
listen 80;
server_name example.com;
root /example.com/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
五、使用宝塔面板时,需要修改的项