PHP calls SVN command to update website Method

Source: Internet
Author: User
This article mainly introduces how to update a website by calling SVN commands in PHP. This article focuses on a small technique. If you do not use this technique to call SVN commands, errors may occur. For more information, see

This article mainly introduces how to update a website by calling SVN commands in PHP. This article focuses on a small technique. If you do not use this technique to call SVN commands, errors may occur. For more information, see

I want to write a program that can execute SVN upgrade through the web page. The result is not as simple as I think. Some tips should be noted.
Run SVN checkout with an Apache user account so that Apache has the SVN link power before executing SVN update through the web page.

The Code is as follows:


Su-s/bin/bash www-data
Cd/var/www
Svn checkout


Before using PHP to execute shell commands to add export LANG = C.UTF-8 environment declaration, otherwise SVN update will encounter Chinese errors, Ubuntu Apache is LANG = C by default
Next we need to add the -- accept theirs-full parameter to SVN. When a conflict occurs, the file version of SVN Server is used as the main parameter.
Add 2> & 1 to allow PHP to obtain all information containing the error.

The Code is as follows:


<? Php
Putenv ('lang = C.UTF-8 ');
$ Result = shell_exec ('svn update -- accept theirs-full/var/www/my_site 2> & 1 ');
Echo nl2br ($ result );

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.