On my debian i run xampp. I want to execute a python script using php shell_exec.
This is my php code:
shell_exec("/opt/lampp/htdocs/news/hello.py 2>1 &");
When i run it from the browser i get this error:
/usr/bin/python: /opt/lampp/lib/libz.so.1: no version information available (required by /usr/bin/python)
If i run it from the terminal window using this: php /opt/lampp/htdocs/page/index.php it works without any problems.
So any ideas how can i make it work from the browser?
Thanks
I'm guessing xampp comes with it's own libraries instead of using the system libraries, and that probably means it's setting LD_LIBRARY_PATH to it's local library directory.
This will also cause other programs started from php to use this libraries, which they may not be compatible with.
To veryfy that, try system("env");, that sould show you all the exported environment variables. If LD_LIBRARY_PATH is set, use:
shell_exec("LD_LIBRARY_PATH= /opt/lampp/htdocs/news/hello.py 2>1 &");
That unsets it before running the python script.
Related
I have updated windows today and now when I use the command line and type PHP nothing returns. tried various PHP commands, nothing, not even an error or response. blank.
I had the correct path in the environment variables. Tried to change to another PHP version and even tried removing the path from environment variables but still returns empty!
It doesn't even say that "PHP" is not recognized although I removed the environment variable!!
I have no clue how to solve this.
If you are not passing extra parameters when you call it from command line, that´s how it supposed to work.
Try running:
php --help (to see all options from command line)
Also, to make sure it is running try to do this:
php -v (to check version)
php -F filename.php
The last one should run your php file.
I had the same challenge.
Here's a solution:
Use a standard terminal window (instead of Powershell).
Try php -v again.
IF you get an error mentioning VCRUNTIME140.dll
THEN you need to install run-time components that are required to run C++ applications built using Visual Studio 2015 here: https://www.microsoft.com/en-us/download/details.aspx?id=48145
I have a very strange problem.
I'm trying to make a program that executes shell_exec() in PHP with NMAP.
The problem comes when I put shell_exec("nmap --version"), because it returns me version 4.11, but when I put it directly on shell, it returns me version 7.01.
When using shell_exec you should always use the full path to the executable.
I'm trying to run a ROS shell program on the server through php on Ubuntu 14.04. I have tried using system, exec, shell_exec but nothing happens and I don't get any output. The system call is the following:
echo shell_exec("/opt/ros/indigo/bin/rosrun gazebo_ros spawn_model -database Part_A -gazebo -model Part_A");
What are the limitations of using system or exec to run any shell command through php on a server?
I don't care as much about the output of the command as for its execution. I think the problem has to do with the fact that PHP doesn't have any PATH like shell does so it can't find any applications without specifying the exact location. How can I make PHP se the same PATH shell does?
The problem was that the apache user and the environment in which the bash commands are running are not set up correctly. I followed the instructions from this answer but instead of using "source" I used "." and instead of using the source.bash file I used the source.sh file. I also set all the environment variables that had to do with ros or gazebo using the putenv() function.
I'm building a website that needs some ressources from a software in windows. So, I need to run windows' shell from notepad++ using php. Are there any php scripts to execute commands from windows' shell?
You can use the PHP function exec() - do note that there are some bugs with it (If a script (with the exec command) is loaded more than once by the same user at the same time the server will freeze.)
A solution for this is found in the PHP manual:
<?php
session_write_close();
exec($cmd);
session_start();
?>
I'm setting up a big system relying on python 2.7 being run through php. The call is always something like:
exec('python test.py');
However no matter what I do PHP keeps using python 2.4 for executing my files. Because of the size of the system I can't change in the programming, but will have to make 'python' point directly to python2.7.
By searching around I have reached the conclusion that I should change the php env.
echo getenv("PYTHONPATH"); // NOTHING
echo getenv("PATH"); // /bin:/usr/bin
I can do so through putenv (for example: putenv("PATH=/usr/bin/python2.7:".$_ENV["PATH"]), but php keeps running python 2.4 no matter what I change it to.
Hope somebody out there got a simple solution :)
Could you not just do this instead:
exec('/usr/bin/python2.7/python test.py');
another option, you can set path to interpreter in 1st line of script test.py
#!/usr/local/bin/python2.7
but you need make test.py executable
chmod +x path_to_file/test.py
and run from php as
exec('path_to_file/test.py');
P.S. be attentive administrators sometimes disable exec function on servers for safety.
disable_functions="popen,exec,system,passthru,proc_open,shell_exec" ....
If you can't use full path, try an alias:
alias python='/usr/bin/python2.7'
python --version
Python 2.7.2