美文网首页
shell自动拉取php项目

shell自动拉取php项目

作者: 阿当运维 | 来源:发表于2020-11-04 14:11 被阅读0次
    #!/bin/bash
    
    #自动更新php项目
    #项目的根目录
    PHP_PROJECTDIR=/tmp/php_ceshi
    #项目名称,通过脚本参数传递,更加灵活
    PHP_NAME=$1
    #nginx里定义的root发布目录
    NGINX_WEBDIR=/usr/share/php_project
    #备份目录
    PHP_BACKUPDIR=/data/backup
    DATE=$(date +%F_%T)
    
    if [ ! -d $PHP_PROJECTDIR ];then
        mkdir -p $PHP_PROJECTDIR
    fi
    cd $PHP_PROJECTDIR
    if [ ! -d $PHP_NAME ];then
        git clone https://github.com/Niceone9/php-demo.git
    else
        cd $PHP_NAME
        git pull
    fi
    
    if [ $? -ne 0 ];then
        echo "git拉取失败..."
        exit
    fi
    
    if [ ! -d $NGINX_WEBDIR  ];then
        mkdir -p $NGINX_WEBDIR
    fi
    
    #备份
    mv $NGINX_WEBDIR/$PHP_NAME  $PHP_BACKUPDIR/${PHP_NAME}_${DATE}
    #部署
    cp -rf $PHP_PROJECTDIR/$PHP_NAME $NGINX_WEBDIR/$PHP_NAME
    
    nginx -t 
    if [ $? -ne 0 ];then
        echo "nginx conf 测试失败"
        exit
    fi
    nginx -s reload
    if [ $? -ne 0 ];then
        echo " nginx 重启失败"
        exit
    else
        echo "重启 成功"
    fi
    

    nginx-虚拟主机配置文件

    [root@server-3 ~]# cat /etc/nginx/conf.d/phpinfo.conf 
    server {
        listen 88;
        server_name 192.168.1.102;
        index index.html index.htm index.php;
        error_log phpinfo_error.log;
        location / {
            root /usr/share/php_project/php-demo;
            index index.php;
        }
            location ~ \.php$ {
            root /usr/share/php_project/php-demo;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
    }
    

    结果:


    image.png
    image.png
    image.png

    相关文章

      网友评论

          本文标题:shell自动拉取php项目

          本文链接:https://www.haomeiwen.com/subject/eprgvktx.html