How to implement git automated deployment of php scripts
How to implement git automated deployment of php scripts: 1. Install git; 2. Clone the warehouse code; 3. Change linux permissions and modify the configuration; 4. Add the www user to sudoers; 5. Generate a key; 6 , fill in the webhook domain name and upload the php script.
The operating environment of this article: linux5.9.8 system, Git version 2.30.0, DELL G3 computer
git automated deployment php script How to implement?
git php deploys webhook automation script to achieve code synchronization
##This article will introduce the git php deployment webhook automated script to achieve code synchronization Git with webhook automated deployment is not a sophisticated technology, but there were many detours in the first deployment, mainly I am considered a novice in Linux. This article records the problems that are easy to make mistakes and the pitfalls encountered.
Preparation Deploy accessible web domain names and server-side php scripts in lnmp environment. Warehouse code cloud gitee
First create a warehouse on gitee code cloud
Use the ssh protocol to communicate with the warehouse locally For communication, my local computer is windows. I will not introduce how to generate the ssh public key here. I will introduce it below under Linux
yum install git
git initgit clone git@gitee.com:zhuyanbin/HiAdmin.git
Because our webhook notifies the server that it is an external access, the administrator user here defaults to the www user. Therefore, www must be given sufficient permissions.
vim /etc/passwd 添加下面的一行 www:x:1001:1001::/home/www:/bin/bash
cat /etc/group
chmod u+w /etc/sudoers
vim /etc/sudoers
www ALL=(ALL) NOPASSWD:/usr/bin/git
chmod u-w /etc/sudoers
Modify php-fpm. conf configuration sets the visitor, my here is www, which is the default configuration of php
4. Finally generate the key (this step must be the www user to generate the key, ps: in This place has been stuck for two days. I have been using the root administrator account to generate it. I tried Baidu for several days and tried various methods. Then I switched to the www user to generate the key and everything was ok)
mkdir -p /home/www/.ssh
chown -R www.www /home/www/.ssh
ssh-keygen -t rsa
cat /home/www/.ssh/id_rsa.pub
https://gitee.com/profile/sshkeys Supplement: There are two places for gitee to fill in the public key. One is the public key of the warehouse. If you fill in the public key of the warehouse, the server git permission will only have pull permissions, and the other is the public key of the account. Key, if you fill in the public key of your personal account, you will have pull, push and other permissions. The personal account public key I use directly here
5. Finally fill in the webhook domain name and run the php script
Fill in the webhook notification address domain name (The password setting is empty. There is no password verification in PHP later. If you consider security, please set the password later) Go to PHP script handler hook.php (execute linux command)
chdir("/home/wwwroot/default/HiAdmin"); exec("git pull origin master 2>&1", $out); foreach($out as $v) { echo iconv( 'GB2312','UTF-8', $v)."<br>"; }
Problems occur
1.php script does not execute Reason php. Many php functions in ini are not turned on by default, including executing linux script functions exec(), shell_exec(), etc.
Find php.ini, find the disable_functions line and delete the corresponding function, or comment out the entire line
2. Unable to execute git pull command
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
归根结底还是因为linux权限的问题,我遇到的是出现一下问题
到这里的原因是因为root生成git公钥密钥,而切换到www后生成公钥密钥后就成功了(上述第四小步生成公钥,一定使用www生成公钥密钥)
问题二
error: insufficient permission for adding an object to repository database .git/objects
fatal: failed to write object
fatal: unpack-objects failed
这个还是没有权限执行git命令,只需要执行以下
第一步:cd .git/objects 定位到git下的objects文件下 第二步: ls -al 查看git库的所有者(git用户 git组) 第三步: chown -R yourname:yourgrounp * 或者sudo chmod 777 -R .git/objects 提交
最后解决完以上问题,大功告成,上一张成功的截图
自己的后端语言是php,这里可以用多种方式去实现执行linux脚本,nodejs,python等等
推荐学习:《PHP视频教程》
The above is the detailed content of How to implement git automated deployment of php scripts. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

To delete a Git repository, follow these steps: Confirm the repository you want to delete. Local deletion of repository: Use the rm -rf command to delete its folder. Remotely delete a warehouse: Navigate to the warehouse settings, find the "Delete Warehouse" option, and confirm the operation.

Resolve: When Git download speed is slow, you can take the following steps: Check the network connection and try to switch the connection method. Optimize Git configuration: Increase the POST buffer size (git config --global http.postBuffer 524288000), and reduce the low-speed limit (git config --global http.lowSpeedLimit 1000). Use a Git proxy (such as git-proxy or git-lfs-proxy). Try using a different Git client (such as Sourcetree or Github Desktop). Check for fire protection

To download projects locally via Git, follow these steps: Install Git. Navigate to the project directory. cloning the remote repository using the following command: git clone https://github.com/username/repository-name.git

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

When developing an e-commerce website, I encountered a difficult problem: How to achieve efficient search functions in large amounts of product data? Traditional database searches are inefficient and have poor user experience. After some research, I discovered the search engine Typesense and solved this problem through its official PHP client typesense/typesense-php, which greatly improved the search performance.

Steps to update git code: Check out code: git clone https://github.com/username/repo.git Get the latest changes: git fetch merge changes: git merge origin/master push changes (optional): git push origin master
