PHP教程

智慧园区5.0项目部署文档【服务器版】

文 / 管理员 来源 / 原创 阅读 / 1189 3年前

前言

项目安装前,请先记住运行需要的版本

PHP>=7.4

Mysql >= 5.7


运行环境部署

1、首先搭建LNMP项目运行环境

参考文档:https://lnmp.org/install.html

2、添加虚拟主机

参考文档:https://lnmp.org/faq/lnmp-vhost-add-howto.html


虚拟主机添加完成之后,配置vhost参数  cd /usr/local/nginx/conf/vhost/

版本一:双域名版本

server {
    listen 80;
    #listen [::]:80;
    server_name api.xxxx.com;
    index index.html index.htm index.php default.html default.htm default.php;
    root  /wwwroot/www.xxxx.com/local-update/public;

    include rewrite/laravel.conf;
    #error_page   404   /404.html;

    # Deny access to PHP files in specific directory
    #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

    include enable-php.conf;

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
        expires      12h;
    }

    location ~ /.well-known {
        allow all;
    }

    location ~ /\.
    {
        deny all;
    }

    access_log  /home/wwwlogs/www.xxxx.com.log;
}
server {
    listen 80;
    server_name www.xxxx.com xxxx.com ;
    root /wwwroot/www.xxxxxx.com/front_dist;
    index index.html;

    location / {
            try_files $uri $uri/ /index.html;
    }

    charset utf-8;
    access_log  /home/wwwlogs/vue_access.log;
    error_log  /home/wwwlogs/vue_error.log;
}

版本二:单域名版

server
    {   
        listen 8080;
        #listen [::]:80;
        server_name localhost;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /opt/minhe/new_admin/public;

        
        include rewrite/laravel.conf;
        #error_page   404   /404.html;
        
        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
        
        include enable-php-pathinfo.conf;
        
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {   
            expires      30d;
        }
        
        location ~ .*\.(js|css)?$
        {   
            expires      12h;
        }
        
        location ~ /.well-known {
            allow all;
        }
        
        location ~ /\.
        {   
            deny all;
        }
        
        access_log  /home/wwwlogs/minhe.hqhuitong.com.log;
        error_log  /home/wwwlogs/minhe.hqhuitong.com.log;
    }
server {
    listen 80;
    server_name www.mhzhcyy.com mhzhcyy.com;
    rewrite ^(.*) https://www.mhzhcyy.com$1 permanent;
}
server {
    listen 443 ssl;
    server_name         www.mhzhcyy.com;
    ssl_certificate     /usr/local/nginx/conf/vhost/cert/mhzhcyy.com_bundle.crt;
    ssl_certificate_key /usr/local/nginx/conf/vhost/cert/mhzhcyy.com.key;
    ssl_session_cache   shared:SSL:1m;
    ssl_session_timeout 5m;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    root /opt/minhe/dist;

    index index.html;

    location /index.html {
        try_files $uri $uri/ /index.html;
    }
    location / {
        try_files $uri $uri/ /index.html;
    }
    location /api {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location ~ ^/(storage|import|default|template|region_polyline) {
            root /opt/minhe/new_admin/public;
    }
    charset utf-8;
}


项目部署

1、设置Git全局及公钥部署

参考文档:http://blog.qdxcy.cn/git/26.html


2、在项目运行目录,拉取最新的项目代码

服务器端代码,如 git clone  ssh://xxxxxxx/local-update.git

前端Vue代码, 如 git clone ssh://xxxxxxx/new_vue.git

拉取完最新代码之后,切换相应的分支 git checkout xxxx


3、部署服务端代码

①首先安装项目依赖 composer install

②复制项目配置文件(切换至项目目录)  cp .env.example  .env  , 然后修改相关配置(如数据库,短信等)

③依次执行下面的命令

        1. php artisan migrate    跑迁移

        2. php artisan storage:link  创建上传文件文件夹

        3. php artisan init:rule     初始化角色权限

        4. php artisan init:user    初始化用户

        5. php artisan init:message_notice    初始化消息

        5. php artisan init:message           新版-初始化消息

        6. php artisan init:options         初始化系统字典

        7. php artisan db:seed  初始化默认数据

        8. 模块化部署-初始化模块数据,单独执行以下命令行

            php artisan module:seed Property

            php artisan module:seed Industry

            php artisan module:seed Prevent

            php artisan module:seed Important

番外:上面执行创建上传文件的软连接,有可能不成功,请执行下面的代码
// 已当前文件夹publi为例
// 先在文件中创建文件 /storage/app
mkdir ../storage/app/public
// 再次创建软连接 
ln -s ../storage/app/public  ./storage

④ 访问域名 http://api.xxxx.com  , 出现 Lumen (7.2.2) (Laravel Components ^7.0) 即表示安装成功

image.png

⑤创建自动部署文件 vim auto_update.sh

#!/bin/bash
export.UTF-8

cd /wwwroot/www.xxxxxx.com/local-update
rm -rf /wwwroot/www.xxxxxx.com/local-update/storage/framework/cache
unset GIT_DIR
echo "正在同步代码:"

sudo git fetch --all
sudo git reset --hard origin/develop
sudo chown -R www:www /wwwroot/www.xxxxxx.com/local-update

# 处理数据表变动
migrate=`find /wwwroot/www.xxxxxx.com/local-update/database/migrations/ -name '*.php' -mmin -1 | wc -l`
if [ "$migrate" == "1" ];then
        echo "正在处理表变动"
        ./artisan migrate
fi
echo "更新成功!!!"

退出编辑,保存一下,然后对改文件赋权 chmod 755 auto_update.sh

代码运行(切换至项目目录): ./auto_update.sh


4、部署前端Vue项目

①依次检查依赖版本,尽量使版本不要太低

node -v , npm -v , cnpm -v

cnpm安装淘宝镜像:npm install -g cnpm -registry=https://registry.npm.taobao.org


②切换至运行目录,执行 cnpm install 

③修改文件内容 config/index.js 和config/prod.env.js 两个文件内容

④创建自动部署文件 vim auto_vue.sh

#!/bin/bash

basePath="/wwwroot/www.xxxxxx.com/new_vue/"
echo "正在开始自动部署"

cd $basePath
git fetch --all
git reset --hard origin/develop

npm run build

rm -rf /wwwroot/www.xxxxxx.com/front_dist
mv ./dist /wwwroot/www.xxxxxx.com/front_dist
chown -R www:www /wwwroot/www.xxxxxx.com/front_dist

退出编辑,保存一下,然后对改文件赋权 chmod 755 auto_vue.sh

代码运行(切换至项目目录): ./auto_vue.sh


定时任务:

php artisan schedule:run      跑定时

crontab -l      服务器查看定时任务

crontab -e    编辑定时任务

* * * * * cd /wwwroot/dwerp_bate && php artisan schedule:run >> /dev/null 2>&1


客户服务器增加定时数据库备份任务

具体参考链接:Linux下实现数据库每天自动备份


公用node_modules文件,创建软连接

ln -s ../node_modules  ./node_modules


评论

共0条评论
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~

站点声明:本站转载作品版权归原作者及来源网站所有,原创内容作品版权归作者所有,任何内容转载、商业用途等均须联系原作者并注明来源。

© 2020-2030 qdxcy.cn 版权所有京ICP备13045222号
相关侵权、举报、投诉及建议等,请发E-mail:2323946929@qq.com

友情链接: YzmCMS官方网站 YzmCMS官方论坛