PHP: shell_exec Permissions on Windows Server - php

I have the following Problem: If i execute a Shell-Paramter via Shell (cmd.exe) on my Windows Server 2012 it execute perfectly. But if i do the same via PHP (shell_exec) it execute , but with no access to a Template-file.
aerender ERROR: No render settings template was found with the given name.
here is the code
PHP:
<?php
chdir('C:\\Program Files\\Adobe\\Adobe After Effects CC 2015\\Support Files\\');
shell_exec('aerender -project C:\server\htdocs\ae\final3\final.aep
-comp "clouds- rotation-low" -RStemplate "E2Z640blur"
-OMtemplate "E2Z640" -output C:\server\htdocs\cache\clouds-rotation-low.avi')
?>

Yeah, this happens because when PHP opens up the cmd it doesn't load the PATH variables by standard, I think there is a way around that or you can just use an absolute path for aerender
ie. C:\aerender\aerender

Ok, now it works! I just changed the apache2 service in Windows to run as Administrator

Related

Why does this PHP script with a shell_exec call run from the command line in Windows 10, but not the browser/localhost?

I'm using XAMPP on Windows 10, and trying to run a simple PHP script that uses the shell_exec function to call a simple R script in the same directory. Here's the PHP index.php file:
<?php
echo shell_exec('Rscript test.R');
And here's the test.R file:
print("Hello, World!")
From the command line (i.e., Git for Windows), when I run php index.php in the folder, I get the following output:
[1] "Hello, World!"
However, when I run index.php from the web browser via XAMPP and localhost, I don't see anything on the page. At first, I thought it might be a permissions issue, so I gave Full control access to all users on the folder, but it didn't seem to change anything.
Any ideas on how to get this working from the browser? Thank you.
Found the answer to the problem I was having. Apparently, even though Rscript is part of my Windows 10 PATH variable, when I try to execute an R script via shell_exec in PHP, I have to have the whole path to the Rscript executable (I guess because the PHP script / Apache server doesn't know about the path variable).
I changed the shell_exec function call as follows, and it worked:
echo shell_exec('"C:\Program Files\R\R-4.1.0\bin\Rscript" test.R');
Here's a link to the SO post that helped me figure this out:
shell_exec does not execute from browser requests

command working in cmd but not through php shell_exec

I have a command in cmd which looks like below
C:\wamp\www\editor\DocTo-master\exe\docto -f C:\wamp\www\editor\uploaded\uploaded_files_21_original\AffidavitinDIR-4.docx -O "C:\wamp\www\editor\uploaded\uploaded_files_21_original\pdf\21.pdf" -T wdFormatPDF
When I run this in cmd, it works absolutely fine and gives output(doc to pdf) as expected.
However when I put the same command in php shell_exec like
shell_exec('C:\wamp\www\editor\DocTo-master\exe\docto -f C:\wamp\www\editor\uploaded\uploaded_files_21_original\AffidavitinDIR-4.docx -O "C:\wamp\www\editor\uploaded\uploaded_files_21_original\pdf\21.pdf" -T wdFormatPDF');
I dont get the desired output with the above code in php.
Any help will be appreciated
Seems like most of the problems have to do with permissions or redirection.
Your current user credentials allow you to create files in that directory but does the webserver username?
Redirect stderr to stdout to get error information.
Is the quoting right?
Look in the webserver error logs.
I am the author of docto.
This is most probably a permissions issue in that php is not necessarily given the correct permissions to run word on your server.
I am running this myself on a Windows 2012 server running Word 2010, it works fine. DocTo is installed on a subdirectory above the Webserver root.
PHP is running as NTSystem Authority
Also I am using exec rather than shell_exec not sure if that makes any differnce
For fix this problem you must create Desktop folder in these paths:
C:\Windows\SysWOW64\config\systemprofile\Desktop
C:\Windows\System32\config\systemprofile\Desktop
Then go to (Control Panel\Administrative Tools\Services) and right click on your apache service. go to "Log On" tab and enable "Allow service to interact with desktop" option.
Then reset your apache service.
http://pmlearning.info

PHP shell_exec cannot find environment variable

I have added this line PATH DEFAULT=${PATH}:~/bin/ to the ~/.pam_environment
This allows me to call ffmpeg from command line without path which is obviously in ~/bin/ dir so everything works fine as long as im ussing command line.
But if try to run the exact same command from php all i get is sh: ffmpeg: not found
And the code is
shell_exec("ffmpeg 2>&1");
So from my very little experiance with linux (in this case Ubuntu to be specific) i guess apache has no access to pam_environment or ~/bin
What can i do to make this work?
look at the output of phpinfo(), it has a section with all environment variables it sees. then look at your webserver configuration, maybe it's sanitizing the environment, or maybe the init script which starts your webserver does it.
and is the account the webserver is running under using PAM at all?

ubuntu cant execute exec(test.sh) in php

In my php code:
exec(test.sh);
and test.sh has code:
echo "Hi this is test?" | espeak --stdout > demo.wav
But nothing happen. No error, No output.
If i try to execute test.sh from terminal that it will work perfectly. So why it not run on my php.
Can someone help me?
How do you run your PHP script? With php-cli (in shell mode)? HTTP (Apache, ...)?
It could be a path problem. Could you give us the path of your test.sh, the path of your php script or the URI which is called to run the PHP if you use apache or other HTTP server?
the apache user will need write access to the current working directory (presumably the same directory that contains your php script and test.sh).

popen() gives error: no such file or directory

I am using php version 5.2.17. I have a site build in php and testing it under IIS 5.1 on localhost (windows).
I want to run a lengthy PHP script in background, thereby allowing the user to continue using the site (navigation).
I am trying using popen like this:
$cmd='c:\\php\\php.exe c:\\inetpub\\wwwroot\\download.php';
pclose(popen('start /B '.$cmd, 'r'));
This gives error:
PHP Warning: popen(c:\php\php.exe C:\inetpub\wwwroot\download.php,r) [function.popen]: No such file or directory.
Any clues are highly appreciated.
Try to first execute cmd and then call php over cmd like explained here: http://bytes.com/topic/php/answers/751763-popen-windows
SOLVED: i changed the file security of Download.php in IIS and set the user to IWAM(launch IIS Process account).
Thanks for ull experts who showed concern.

Categories