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