Blender (2.80) is installed on AWS in directory /home/ec2-user.
php is run on the same server from /var/www/html/wed
I have access through cli:
wed]$ ls /home/ec2-user
Lists contents of /home/ec2-user.
And access through php:
<?php<br />
$output = shell_exec('ls /home/ec2-user');
echo "<pre>$output</pre>";
?>
Lists contents of /home/ec2-user.
I can run Blender through cli:
wed]$ /home/ec2-user/blender280/blender -b -noaudio proj007/font-sample.blend --python proj007/font-samples.py
Runs the blender script (proj007/font-samples.py) and outputs 663 png files to /var/www/html/wed/fonts.
But not through php:
<?php
$output = shell_exec('/home/ec2-user/blender280/blender -b -noaudio proj007/font-sample.blend --python proj007/font-samples.py');
echo "<pre>$output</pre>";
?>
Nothing.
Commands are copied and pasted so there is no typo.
Permissions for home, ec2-user, and blender280 are set to allow read and execute.
Is this possibly anApache problem?
It turns out that I needed php-fpm. It also turns out that I could not get php-fpm to work on AWS using Amazon Linux. Switched everything to AWS using Ubuntu (about a day and a half project) and things are working great.
Related
I'm trying run command from my index.php:
$output = shell_exec('docker images');
and then output results,
or run new container the same way:
$output = shell_exec('docker run hello-world');
It seems that I could not run ANY docker cmd via php.
How do it properly?
I did the following to get this working:
Created a php file called index.php on /var/www/html/ with this content:
<?php
echo '<pre>';
$content = system('sudo docker images', $ret);
echo '</pre>';
?>
Edited sudoers file with visudo, adding the following line at the end:
www-data ALL=NOPASSWD: /usr/bin/docker
Checked http://localhost/index.php and it worked!
You can even build and run containers with this, hope it works for you.
You can do this:
vi rd.php
Put this content in rd.php file
<?php
$output = shell_exec('RET=`docker run hello-world`;echo $RET');
echo $output;
Now you can run
php rd.php
You can view the result :
Hello from Docker. This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (Assuming it was not already locally available.) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash For more examples and ideas, visit: http://docs.docker.com/userguide/
That's all !
I hope this help you
Unfortunately I do not have access to the droplet via console, only by Vesta panel and I need to set up cron job.
However, I can not find the right path to PHP. Now that command line looks that and it does not work:
/usr/local/vesta/bin/php5 -c /home/admin/web/ -q /home/admin/web/mysite.com/public_html/crop_scripts/cron.php
Please tell me what options instead of "/usr/local/vesta/bin/php5" I can try?
what does this code show when you access it through your web server (assuming exec call is allowed)
<?php
$output = array();
exec('which php',$output);
var_dump($output);
I'm trying to list running services on a windows server via php. Therefore I'm using shell_exec with winexe.
My script:
$cmd = "winexe --interactive=0 --user='***' --password='***' //192.168.***.** \"net start\"";
$output = shell_exec($cmd);
echo $output;
Unfortunately on execution the page loads forever with no result. The command works on the command-line (Debian).
Anyone an idea?
Thanks in advance.
Save $cmd with correct format into a new bash file. Set cmd value for call this file. Remember set execution perms to this file.
Check if your apache user has perms for exec winexe
===
Try to launch
cat </dev/null | winexe --interactive=0 --ostype=1 --user=...
I'm new in using Linux, I'm trying to write a PHP code which can run .exe linux compatible file, I've made a short shell script
hello bash script:
#!/bin/bash
./program.exe file.mp4 // file.mp4 is an an input for .exe
echo "Hello World!"
shell.php:
<?php
$output = exec ("./hello ");
echo "<pre>$output</pre>";
?>
Now when I run shell.php using web browser it shows Hello World! but the .exe doesn't run, however when I run php using terminal command php shell.php, It works fine.
I think I'm having problems with permissions but I'm new with Linux and I don't know how to solve this.
Update:
I ignored the shell script and I used
<?php
$output = shell_exec ("cd /var/www/ && ./program.exe file.mp4 2>& " );
?>
also I granted access to program.exe
chmod 777 program.exe
the error I receive in the browser :could not open debug.bin!
use the absolute path to hello executable exec("sh path/to/the/file")
I'm using something similar to call an app compiled with mono on a remote ubuntu webserver and return it's output to the calling script.
For any of this to work properly wine needs to be already installed.
On Ubuntu systems try:
sudo apt-get -y install wine
You then need to know the owner of the web server process. If you are running the apache web server try the following:
cat /etc/apache2/envvars | grep "RUN"
The output will look something like this:
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
Now that you have the name of the process owner, which in this case is www-data you should ensure the file is owned the user and its group:
sudo chown www-data /var/www/program.exe
sudo chgrp www-data /var/www/program.exe
Finally, we can invoke the application from inside our PHP script by passsing it as a parameter to 'wine' and using its full file path.
<?php
$output = shell_exec("wine /var/www/program.exe file.mp4" );
?>
Any output from the above shell command sent to the command line will be saved in the PHP script variable $output.
It looks like you are trying to do some output redirection with your use of program.exe file.mp4 2>& so I've left that off of the example for clairity.
Try using the absolute path, such as exec("sh /path/to/file")
Generally, php is run as www or apache, so make sure that the execute access permission is granted to all user.
I try to run the wkhtmltopdf (0.11.0 rc1) with php (5.4.2) on apache (2.4.2).
When I try to launch wkhtmltopdf-i386 --use-xserver http://www.google.com google.pdf 2>&1, I can find my pdf. Here my php code
<?php
$cmd= '/usr/bin/wkhtmltopdf-i386 http://www.google.com google.pdf 2>&1';
$ret = shell_exec($cmd);
echo $ret;
?>
It works with apache and as command line php test.php.
Because my target page contains many images and some "heavy" js charts. I have got a Segmentation Fault with the wkhtmltopdf command when I try to turn it into pdf.
The only way to make it work is to use xvfb as X11 emulator. The code looks like this :
<?php
$cmd= '/usr/bin/xvfb-run /usr/bin/wkhtmltopdf-i386 --use-xserver http://www.google.com google.pdf 2>&1';
$ret = shell_exec($cmd);
echo $ret;
?>
This script works with the command line php test.php but it doesn't work with apache. If I take a look into the apache's process with htop, I can see that there are two process (with php test.php) :
xvfb
wkhtmltopdf
When I launch with apache I have only xvfb process. It finish by a timeout from apache because it's waiting the wkhtmltopdf process.
I can make it works with apache (2.2.21) and php (5.3.10).
Is there something that I'm missing ? Maybe something in the apache's config-files ?
I was having the same problem. I was using the exec function, but the same applies to shell_exec. The function execution was disabled in php.ini.
SOLUTION: Remove the shell_exec string from the disable_functions at php.ini file.
I am not sure why your second version is not callable from Apache (must not be using the same shell, since shell_exec uses a shell?), but as a work-around could you (from Apache PHP) shell_exec("php test.php"); and get your intended result?
Perhaps also try one of the other process execution functions such as pcntl_exec.
it's mostly because of ownership and permissions, try
su www-data (for debian)
php test.php
you'll probably see the error.