Use PHP to build SVN remote hooks and automatically update SVN code with the EXEC command

Source: Internet
Author: User
This operation requires permission to execute the sudo command to PHP, which can be referenced in the following settings:
Apache/nginx under Php/ruby execute sudo permissions for system commands

With SVN's hook function, we can perform some operations automatically while we perform SVN operations, and the more common actions are:
1. Update the code to the latest version at the same time in the test environment or in the online environment when you update and submit it locally
2, when updating SVN, if there are database-related operations, you can also send SQL to the remote Hook program execution related sql

This example is a fragment used by our project team to automate the process of updating code to online, or to perform export packaging, when the code is tested on-line and then submitted to the online SVN.

!--? php//first switch to the program deployment directory $path = dirname (__file__); exec ("CD {$path}"); Exec ("Sudo/usr/bin/svn up", $    Output);p Rint_r ($output);     

You need to add Apache to the Sudoer group

To do this, modify the sudo configuration file, direct key such as the Visudo command to edit the configuration file:

1. Note Defaults requiretty
Defaults requiretty modified to #Defaults Requiretty, indicating that no control terminal is required.
Otherwise Sudo:sorry will appear, you must has a TTY to run sudo

2. Add line Defaults VISIBLEPW
Otherwise sudo:no tty present and no Askpass program specified

3. Give Apache users the ability to perform SVN
For example, add line: Apache All= (All) nopasswd:/USR/BIN/SVN
Note: nopasswd can make it possible for the command to execute without interactively entering the password of the Apache user

The last step, Automatically access remote link "http://www.4wei.cn/yoursvnfile.php"

  • When you add a commit svn to an SVN hook

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.