简体   繁体   中英

php shell_exec and hg pull

I have written simple php script to help me update site contents when the commit is sent to bitbucket. I have following problem with it.

<?php
$repo_dir = '/var/www/vhosts/my_full_path';

$output = shell_exec('cd '.$repo_dir.' && hg --config auth.rc.prefix=https://bitbucket.org/XXXXX --config auth.rc.username=my_username --config auth.rc.password=my_pass pull -u https://bitbucket.org/XXXXXXX &');

echo $output;
?>

When I type it to web browser it doesn't work. The output of script is:

pulling from https://bitbucket.org/XXXXXXXXXXXXXX

but when I try to execute it under console on the server it works like a charm:

php myscript.php

generates following output:

pulling from https://bitbucket.org/XXXX
searching for changes
adding changesets
adding manifests
adding file changes
added 2 changesets with 2 changes to 1 files
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

See the oupt is full and correct! in concole I'm using root user in web browser data-www? Is there any difference in this case?

I have found the solution. I hope it helps someone.

There were two problems:

  • Permissions to my repo dir
  • Authentication for user www-data for this repo

The problem occured because web browser doesn't flush warnings and abort messages while executing command shell_exec. If you want to test your script, you have to lgoin to console by SSH (as root for example) then execute script / command as apache user:

sudo -u www-data php /path-to-your-script/script.php

In console you will see all problems which following user generates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM