php exec not working along with wapiti - php

I have a python script (wap.py) from which I am calling wapiti asynchronously using Popen. Command for it in wap.py:
p = Popen("python wapiti domainName", shell = True)
When I am running wap.py, it is executing completely fine.
But when I am running it using php exec, it doesn't work.
Command from php file : exec("python wap.py")

Look at the php.ini to see if there's anything set for disable_functions. If you're using PHP CLI for the script, you can execute the following command in the shell:
php -i | grep disable_functions
Also make sure wap.py has execute permissions.

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')

PHP exec on local script

Hello i have a PHP script, and its added to cron, it is possible to execute from this script shell command (with exec() or something) without enabling it on php.ini? I don't want to enable exec on my site
It's called PHP CLI, check here
Usually when you install php, there's option to install php_cli too.
So long you can run php on shell prompt, then it can work.
Open bash (or other shell), try this:
php -v
If the version printed, then it's working.
Then you can
php -f phpfile
or put
#!/usr/bin/php
At the beginning of your php file as a line, and chmod +x file.php, and then
./file.php
#or
/path/to/file.php
to run it.
(Note /usr/bin/php is the usual place of php executable, it might change, eg in unix is ually /bin/php. Use whereis php to check its place.)

Running Linux DAEMON PHP files, does not execute exec, but does when ran from console

I have a php script that works perfectly when ran form command line; including the exec().
The exec I do are calling some .sh scripts.
These .sh script are of type bash
So I call them:
exec('/bin/bash /home/user/soft/bin/mybash.sh > /dev/null');
It works great when I run my php from command line I see all the instructions; works also when use with an alias. but when I it via a daemon:
sudo -u myuser php -f /home/user/bin/serverwait.php eveything that should be done in the .sh are not being done. but the rest of the file is doing what it is suppose to do (it checks for open ports and write to a log file)
I tried looking at my php.ini for cli and all seems right.

Memecached not found when using exec() in php

I'm using CentOS, and I am able to execute php via CLI from the terminal, but when I run the exact same command via exec(), and it appears that the Memcached class doesn't exist.
so this works:
~$ php script.php args
But this doesn't:
exec('php script.php args');
Anyone have any ideas why it behaves differently in these cases?
PS: I've tried specifying the ini file like this:
exec('php -c /etc/php.ini script.php args');
This was fixed by reinstalling memecache... I'm not sure why or how that worked.

How can I run php -a (interactive shell) from inside a php script?

I'm trying to create a shortcut script for setting some environment variables and the include path before running php -a. So it looks like this:
#!/usr/bin/env php
<?php
putenv("ENVVAR=value");
passthru("php -a -d include_path=<path>");
This mostly works, but the php shell doesn't correctly output its prompt.
I.e. normal output from php -a:
$ php -a
Interactive shell
php > echo "hi\n";
hi
php >
Output from this script:
$ ./myscript.php
Interactive shell
echo "hi\n";
hi
Additionally, there is no support for walking through the history (or even right or left along what's already been typed) with arrow keys.
Is there a way to get this to work correctly?
I'm using Mac OS X, PHP 5.4.27. I have already tried redirecting stderr to stdout, in case that was somehow the cause (it wasn't.)
Rather than writing it in PHP, why not do it as a shell script.
#!/bin/bash
export ENVVAR=value
php -a -d include-path=whatever
I'm using bash, and it works fine under Ubuntu 12.04. I'm not sure what shell is available on OSX.

Categories