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
Related
I am trying to do simple web service in PHP (I use Laravel) to restart and shutdown my raspberry pi.
I tried in my PHP service call something like this:
exec("putty -ssh pi#192.168.0.12 -pw myPassword -m D:\workspace\CPS\public\ssh\restart.txt");
In my restart.txt I have simple command sudo shutdown -r now
but when I call my web service in Advanced Rest Client Application (Chrome addon), my request is processing and never ending. In command line this works properly.
I thought that the problem is with running PuTTy directly in PHP and I do some changes and create .bat file with the following content:
echo off
putty -ssh pi#%1 -pw %2 -m %3
I start this batch script like this:
exec("D:\workspace\CPS\public\ssh\restart.bat 192.168.0.12 myPassword D:\workspace\CPS\public\ssh\restart.txt");
...but result is the same. I changed my web service to GET method and call service in the browser like page but nothing change.
I haven't any error/exception in log files and in console. I also checked the system log but nothing found.
Am I doing something wrong or missed something? It is possible or there is a better way to achieve this?
Currently I run it on Windows 7 and XAMPP. I will do second version for Linux in future and decide in code which command should I run depends on current environment.
Update
I forgot to wrote, all required users have permissions to execute files in my (...)/ssh directory
Try to use:
echo system("D:\workspace\CPS\public\ssh\restart.bat 192.168.0.12 myPassword D:\workspace\CPS\public\ssh\restart.txt");
to get output. May be you find something error.
And you need to check safe_mode options in your php.ini file (like disable_functions and safe_mode_exec_dir).
And try to use FULL path to your putty.exe file. Webserver work's in another directory, than your bat file.
i am using arch linux. i want to execute the php file which changes the ip of the system. i did
ifconfig eth0 192.168.163.137
in the terminal and it works fine. the same i tried doing with
shell_exec('ifconfig eth0 192.168.163.137');
in a php file and tried opening the page from a remotely located web browser from another pc connected via router. teh page displays nothing and the code also doesnt execute. i guess its the problem with the user executing it.apache is executing it. so i want it to be run by the root.can anyone please guide me to the execution of my code. i even installed sudo and just put
shell_exec('sudo ifconfig......');
it too doesnt execute...please help...thanku..:)
Sudo normally requires an interactive shell to enter your password. That's obviously not going to happen in a PHP script. If you're sure you know what you're doing and you've got your security issues covered, try allowing the Apache user to run sudo without a password, but only for certain commands.
For example, adding the following line in your sudoers file will allow Apache to run sudo without a password, only for the ifconfig command.
apache ALL=NOPASSWD: /sbin/ifconfig
Adjust the path and add any arguments to suit your needs.
Caution:
There might still be complications due to the way PHP calls shell commands.
Remember that it's very risky to allow the web server to run commands as root!
Probably a better alternative:
Write a shell script with the suid bit to make it run as root no matter who calls it.
shell_exec
This function is disabled when PHP is running in safe mode.
Documentation : http://php.net/manual/en/function.shell-exec.php
So, maybe try tweaking your php.ini file?
Write the commands to a queue and have cron pick them up, validate them (only allow known good requests), and run them, then mark that queue complete with the date and result.
Your end-user can then click/wait for update using ajax.
I'm building a PHP web application that will run on my machine, and one of its purposes is to call HandBrakeCLI with an exec() or similar call. If I run the command
HandBrakeCLI -i path_to_dvd_drive -o output_file --preset preset_name
from a shell, it works fine. However, when I put the exact same command in an exec() php function (or similar), it doesn't work, and doesn't return anything, aside from a return status of 0. No errors, nothing else.
Is this just a simple permissions issue that I'm not seeing, due to the lack of errors being spit out? Or am I missing something else?
For debugging, try running the command from the console but as the user PHP runs as. Here are some pointers how to find out which user that is.
Then use sudo to run the command as the Apache user. You will probably get more helpful information from that.
try to exec your script using absolute path (type which HandBrakeCLI in terminal to find it) and append 2>&1 to the end of command, like:
exec('HandBrakeCLI -i path_to_dvd_drive -o output_file --preset preset_name 2>&1')
this way if command outputs anything to stderr you will see it.
is handbrake in the path of whatever shell PHP is invoking when it does the exec()? Does whatever account PHP/webserver is running under have access to the directory where handbrak.exe is, and have permission to execute handbrake.exe? Does the webserver account have permissions to access the dvd drive, etc...
Many things to check, and without better diagnostic information, this is about the best you'll be able to get here.
I want to do SVN update easier - with calling PHP script.
I created PHP script:
$cmd = "svn update https://___/svn/website /var/www/html/website/ 2>&1";
exec($cmd, $out);
As the user running the script is apache (not root), I get some permission errors.
If I change the owner of every directory to apache (or chrown everything to 777) I have another problem. Because I use https protocol user apache should permanently accept certificate of the svn server. I tried to do "su - apache" and accept certificate but OS says that "apache" is not valid user. I also dont know how could I accept certificate with exec() function.
Any idea? How can I make svn update-ing easier?
Is the error telling you that the user isn't a valid svn user? If apache is the user running httpd, you should be able to su to it. This is the script I use:
/usr/bin/svn --config-dir=/home/user/.subversion --username=svnuser --password=svnpass update
once the password is saved you can remove it from the command. Again, make sure the user/pass above is a valid SVN user.
Lately I've actually migrated to using Hudson for svn updates as you can schedule it as well as run manually and do a bunch of other tasks, plus you can view the svn logs for each commit as well as any console errors.
Why not use php svn functions instead of (insecure) exec?
http://www.php.net/manual/en/function.svn-auth-set-parameter.php has good examples for authentification options.
Use getent apache on the shell. This will return the shell of apache. Most likely, it is /bin/nologin or /bin/false. Change this to /bin/bash. You'll also need to specify the home directory and create it on the file system.
UPDATE: getent apache will actually return the entry in the /etc/passwd file for the apache user. The last token in this string is the shell.
I have a multithreaded cli downloader for ubuntu called Aria2c.
I've been trying to get a php script to run aria2c and download a file using shell_exec, but i can't seem to get it to work. Ultimately I plan to have an input box on a page where I can enter a link and aria would download it.
Here's the code I've come up with (for now im inputting the link manually):
<?php $dl = shell_exec('aria2c -d /home/user/ www.downloadlink.com'); ?>
Note that the aria2c command I specified works well in the shell; and the directory I'm attempting to download to is set to '777'.
I'm baffled as to why it's not working, any ideas?
PS: I prefer to use aria rather than the alternatives because it is multithreaded and it supports cookies.
Check if PHP is running in safe_mode. shell_exec won't work if safe_mode is on.
EDIT: aria2c was not referenced with a full path. Referencing it like this: shell_exec('/path/to/aria2c -d /home/user/ www.downloadlink.com') works.
I'll make the assumption that you are running PHP through a web server. In such case, it's very unlikely that the web server has permission to write into your user's home directory: Apache runs as daemon with the credentials of a limited user. Also, the PATH env variable in Apache is not necessarily the same as your user's PATH. Last but not least, you don't check the return value or the script output.
Try something like this:
<?php
exec('/path/to/aria2c -d /tmp www.downloadlink.com', $output, $return_var);
var_dump($output, $return_var);
?>
You can get the full path for aria2c with:
which aria2c