项目放到服务器上时的注意事项

Some precsutions while putting projects on the server

Posted by Lv Hui on June 10, 2018

代码上传到服务器时,涉及到权限,配置等的设置

框架文件权限设置

1
2
chmod -R 777 boostrap
chmod -R 777 storage

修改nginx默认web路径

修改配置文件,所在路径为/etc/nginx/nginx.conf,修改serve下的root

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
server {
        listen       80 default_server; 
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            index index.php index.html index.htm;
        }

        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;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

修改配置之后重启nginx

1
nginx -s reload

github拉取部署时注意事项

我们在上传代码时都会在.gitignore里记录让git忽略上传的文件,如依赖文件vendor文件以及配置文件.env等,所以如果在服务器上直接拉取代码记得执行重新执行composer install

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 拷贝远端文件
git clone https://github.com/laravel/laravel.git
# 进入到项目文件执行生成vendor文件解决依赖问题
composer install
# 更新compser
composer update
# 建立.env文件
cp .env.example .env
# env.example中默认没有app key,所以我们在.env中生成新的app key
php artisan key:generate
# 修改.env中的配置项
vim .env
# 执行数据迁移
php artisan migrate
# 执行数据填充
php artisan db:seed

数据库中非数据填充生成的数据任然需要手动进行拷贝