PHP project version control and release process

不言
Release: 2023-03-22 22:48:01
Original
4717 people have browsed it

This article will share with you about the PHP project version control and release process. Friends in need can take a look




# 1. [Local==> GIT warehouse==> Test server] When the submission to the GIT warehouse is completed, GIT triggers the test server hook script to automatically PULL the update code:

  1. Test server

    1. Execution principle

    2. PHP script:/home/git/hook/

      www.xxx.com.php, Note: Need to be in Delete the system in disable_function in php.ini (that is, enable the script execution permission)

    3. When git push is triggered, the warehouse POST is triggered to call the PHP script. The URL of the PHP script:

      http://XXX.XXX.COM/hook/www.xxx.com.php

    4. ##The PHP script then delays the execution of the SHELL script. The SHELL script Implement pulling code from the warehouse

    5. View the current remote url and protocol: git remote -v
    6. Copy the git of the project in oschina SSH address: git@git.oschina.net:echobar/test.git
    7. Change to ssh protocol and address: git remote set-url origin git@git.oschina.net: echobar/test.git
    8. git pull
    9. Create a home directory for the www user (the public key and GIT owner are all set to www, otherwise It may cause insufficient permissions to automatically execute the SHELL script)
    10. Generate public key
    11. View the public key: cat ~/.ssh/id_rsa. pub
    12. Copy it to the public key settings of git.oschina.net
    13. mkdir /home/www && chown -R www: www /home/www
    14. sudo -u www ssh-keygen -t rsa -C "15516026@qq.com"
    15. yum - y insall git
    16. cd /home
    17. sudo -u www git clone git@git.oschina.net:echobar/test.git
    18. Install git and clone the project with www user
    19. Configure the public key
    20. Test Manually pull the code

    21. Write a hook script to pull the GIT code
    22. ##
    $params = $_GET + $_POST + $_SERVER;

    if (isset($params['HTTP_USER_AGENT']) && $params['HTTP_USER_AGENT'] == 'git-oschina-hook') {

    sleep(10);

    $cmd = "/home/git/hook/www.xxx.com.sh";

    system($cmd, $ rs);

    }

    ##SHELL script:/home/git/hook/

    www.xxx.com.sh
    1. , note : Don’t forget to execute permissions chmod a+x *.sh

      #!/bin/bash

    2. cd /home/www.xxx.com && git pull

    #log

    echo "`date +%Y%m%d_%H%M%S`,Pull code success[Master]" >> "/home/git /hook/log/pull_www.xxx.com_`date +%Y%m`.log"

    GIT warehouse hosting code:

    https://git.oschina.net
    1. Create a private project www.xxx.com
      1. Set the webhook address to the php script URL of the above test server:

        http://XXX.XXX.COM/hook/www.xxx.com.php
      2. Add the public key to the project or personal user settings (recommended for individuals In user settings, all projects can use the same public key globally)

      3. local
    2. git clone
    3. https://git.oschina.net/echobar/www.xxx.com.git
      1. Note .gitignore, set to exclude files and directories that do not need to be synchronized

      2. Add/modify files

      3. git add .

      4. git commit -m test

      5. git pull

      6. git rebase master

      7. git push

      8. sudo -Hu www git config --global user.name "echobar"

      9. sudo -Hu www git config --global user.email "15516026@qq.com" # Please contact oschina for email Consistent with

      10. git configuration

      11. git submits local code to the warehouse

      12. View on oschina Whether the project file is updated successfully

      13. Check whether the test server code is updated. If it is updated, it means the configuration is successful; if it sometimes succeeds and sometimes fails, it may be a delay problem in the hook call and needs to be modified. PHP script delay time, or manually execute the following code to pull: http://xxx.xxx.com/hook/www.xxx.com.php?HTTP_USER_AGENT=git-oschina-hook

    ## 2. [Test server ==> Official server] Write a remote synchronization script and execute it manually when publishing. Synchronization method: RSYNC+SSH

      ##ssh
      1. yum -y install ssh
      2. test server Generate public key: ssh-keygen
      3. Copy the public key from the test server to the official service: ssh-copy-id -i ~/.ssh/id_rsa.pub Target server IP (remote input is required) Server password)
      rsync
    1. ##yum -y install rsync
      1. Create synchronization script: touch /home/rsync_
      www.xxx.com_from_test_to_prod.sh
    2. , Note: --exclude-from exclude files list, pay attention to exclude files that do not need to be synchronized

      #!/bin/sh
    # backup

    ssh root@10.10.10.10 "/bin/sh /root/scripts/ backup_html.sh"

    # rsync

    rsync -rlptDvz --exclude-from=exclude_www.xxx.com -e ssh /home/www.xxx.com/ root@

    10.10 .10.10

    :/home/wwwdata/www.xxx.com

    Perform synchronization from test server to official server (rsync+ssh)
      /home/rsync_
    1. www.xxx.com_from_test_to_prod.sh


    Note: The yellow parts above are the codes required to publish locally to the test server and publish the test server to the official server

    .

The above is the detailed content of PHP project version control and release process. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!