Execute gphoto2 on lighty/lighttpd on raspbian - php

I try to execute this command with the PHP command exec:
exec ("gphoto2 --capture-image-and-download --filename ".$path, $output, $returnVal);
I use a valid filename and when I execute the command with the parameters of the variables in bash, it works. However, with php it doesn't. I don't get a reply of the exec command.
I'm using raspbian with lighty and the php5 module. That works with other samples fine.
I tryed shell_exec without success, too.
Can someone help me?

Related

Run MTProxy remotely by PHP exec on Windows server

I installed PM2 and node.js on the Windows server to run JSMTProxy-master script.
The command for the run proxy is: (pm2 start "JSMTProxy-master\mtproxy.js" -i max) and it executed successfully in the CMD window with no problem.
Now I want to execute this command by PHP and exec.
I tried this:
exec ('pm2 start "JSMTProxy-master\mtproxy.js" -i max');
Or this: (just showed up cmd.exe in taskmgr)
exec ('c:\WINDOWS\system32\cmd.exe /c START "pm2 start c:\mypath\JSMTProxy-master\mtproxy.js -i max"');
Or this:
exec ('c:\WINDOWS\system32\cmd.exe /c START "JSMTProxy-master\mtp-run.bat"');
These don't work and nothing happens. no error, no process showed up in taskmgr.
How is it supposed to be to run by exec?
Note. I have PHP installed and working perfectly.
After trying different ways many times, Finally i found the problem.
"PM2" doesn't execute under PHP exexc. It has to be with full path of exe files.
I changed my command as below and it worked:
shell_exec('C:\Users\Administrator\AppData\Roaming\npm\pm2.cmd start "C:\mypath\JSMTProxy-master\mtproxy.js" -i max')

How to exec a command installed with `npm` command in PHP using `exec()`?

In PHP running on Ubuntu, I can run exec('npm -v') and the output is good,
but I can't run exec('gitbook xxxx').
gitbook is a npm package I installed by
npm install gitbook -g
I can run gitbook xxxx in the Ubuntu terminal, how can I run it from my PHP code?
If you run php by nginx or apache (for example, visit url example.com/index.php), sometime you need to export the PATH
exec("export PATH=/usr/local/bin && gitbook build);
after I added export PATH, everything works fine.
I tried once like this on UNIX-based OS:
You can run shell commands via the exec() function:
// make an php file to execute shell script
exec("node yourscript.js &", $output);
Well output here become array of each line of output along with process id. You can kill process by processid also.
exec("kill " . $processid);
This how I was did. Other then this you can use node supervisor. Hope it will help you. Try your also with node command.

php shell_exec return null

I want run php ../cat1/index.php gr_s2/3/gr-n40 1200 command by php.
The shell_exec return NULL as result but when I try that command on cmd, output was shown correctly.
What happen in php and shell_exec ?!
Note: The command with different parameters (Like: php ../cat1/index.php gr_s2/3/gr-n40 800) works correctly in both (php and cmd).
There is a note in php manual page of shell_execute:
Note: This function can return NULL both when an error occurs or the
program produces no output. It is not possible to detect execution
failures using this function. exec() should be used when access to the
program exit code is required.
Source: http://php.net/manual/en/function.shell-exec.php
So your code running with error. Try with exec.
If you want, insert your code (or blocks) to be checked.
This is fixed by adding user used by web-server to sudoer and run the php command with
sudo php ..........
To start run this command sudo visudo
Add the following line at the end of sudoer file opened
www-data ALL=NOPASSWD: /usr/bin/php
But if you whant to execute all commad from php add this line instead of the above www-data ALL=NOPASSWD: ALL which is not recommended
and the run your commands with sudo php /path/to/you/file.php
For my case I was running ubuntu 14.04
Have fun please

s3cmd sync not working from php system() while from shell it is

Im trying to run a .sh script that contains "s3cmd sync.." command and it is not working.
When running the same sh from shell prompt it works perfect.
It seems that the execute permissions for s3cmd are insufficient when running from php system / shell_exec commands.
note : ( when running another .sh script from system() function that uses mysqladmin util , it works fine.)
Any ideas?
Thanks

PHP execute asyncronous php script in shell command doesn't work on bitnami LAMP AWS

on my local machine I execute the following:
exec('sudo nohup '.PHP_BINDIR.'/php '.ROOT.'/index.php controller=imports action=import id=12 > /dev/null 2>&1 &');
where "ROOT" is a constant with the complete path.
Everything works fine and the script is executed asyncronously with no problems.
When I run the same script on production environment (a bitnami LAMP stack running on AWS) instead: if I run it directly from the terminal it works, when I run it from php it doesn't.
I have nothing in the apache error_log and if I run it with shell_exec the returned value is NULL.
If I try to execute a different script from php (like exec('whoami')) it works, so I don't think is a permissions thing.
I also tried replacing php command with php-cli, nothing changes.
Hope someone can help.
Thanks in advance.

Categories