Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP exec on a Windows with IIS configuration

so I have read about 10 answers and everyone seems to suggest ideas which for some reason don't work.

i am trying to execute a simple command line which is "svn update" but it is not working and it returns NULL

so i have tried trial and error the way and for now this is what i can say;

i have tried several commands like

<?php
exec ("cmd /c ping 127.0.0.1 -n 1 > results.txt ");
?>

and

<?php
exec ("cmd /c chdir > results.txt ");
?>

and both work.. infact chdir says the exact position where the php file executing the line is stored on the pc..

so the problem now is, why do some commands like this:

<?php
exec ("cmd /c dir > results.txt ");
?>

don't work? this results and empty value even though inside the folder i have several files and directories.

and why if i use the command prompt to move into the folder where the php file is store and type svn update it works and doing

<?php
exec ("cmd /c svn update > results.txt ");
?>

return a NULL?

any help is really appreciated.

it feels like i have some restrictions dued to the configuration setup because when i try in local using apache i can get most of the commands to work (shell_exec, system, exec, even without the cmd /c)

like image 319
mstation Avatar asked Feb 06 '14 20:02

mstation


1 Answers

Ok.

i have managed to solve the issue..

this is what i did:

first check exactly what username is running for the specific website.. to do so do:

<?php 
$out = array();
exec('cmd /c whoami 2>&1',$out,$exitcode);
echo "<br />EXEC: ( exitcode : $exitcode )";
echo "<hr /><pre>";
print_r($out);
echo "</pre>";
?>

this will return the computername followed by the username..

now on the computer running the webserver run

control userpasswords2

and give administrator powers to the username whoami said

this will allow you to finally run any command you want using exec or system_exec


on the other hand continuing with my SVN command i found out that I had another problem which is that when you run it, it will look for the config file which is under the administrator account and will give an error saying:

svn: E125001: Can't determine the user's config path

to solve this issue you simply have to specify in the command the config_dir by doing this:

exec('cmd /c svn update --config-dir C:\Users\Administrator\AppData\Roaming\Subversion C:\\inetpub\\vhosts\\websitename\\httpdocs\\folder 2>&1',$out,$exitcode);

hope this helps others which are having problems like the ones i had!

like image 101
mstation Avatar answered Sep 30 '22 08:09

mstation