I am trying to run a php file from shell script file or terminal in open-wrt platform. I have executed php files in crontab and those are running perfectly. i need to run a php file without putting it into crontab.I am trying it with the following command
chmod 777 /www/api/*
cd /www/api
php myphp.php
but it showing -ash: php: not found
I have also try it putting the following command on top of the script
#!/usr/bin/php
but it is not working. i could not figure out the problem!!!
You must install php-cli package, after you can run the script by
php-cli script.php
Related
I've been trying to run the php script:
shell_exec("bash /etc/example.sh")
from the browser but it does not work. This bash file creates a new one on the /etc directory.
I've also tried the functions exec() && system() but they don't work either. The weird thing happens when I run other Linux commands on these php function like:
shell_exec(rm -r /etc/fake);
they work fine, I have also tested my bash file on the linux command line and it works great.
I am sure this is not a permission issue, since I previously set the 777 permission on the file i am trying to execute.
shell_exec("bash /etc/example.sh")
I am using php7.0.33 and Debian 9, so I suppose this may be an issue with this PHP version 7.0.
Thank you for the help.
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.)
How can I launch a php script from Linux console?
For example, I have myscript.php file. I should be able to launch it like myscript from console (I can create and use any other scripts)
Also, I should be able to send parameters to it like myscript dosome [-n <count>]. Can I do this?
You could find it with very simple Google search.
So you should install PHP-CLI first. For example:
sudo apt-get install php5-cli
After that you should write some code to your php file:
nano example.php
and write
<?php phpinfo(); ?>
For run this script you should give permission:
sudo chmod 755 example.php
And can run it as:
./example.php
To run php script from shell with argumets you must create bash script, name it myscript and add this code (change php to your php installation dir)
"php" myscript.php $*
And add script folder to Linux PATH
$ export PATH=$PATH:/path/to/folder/
Then you can access the script with myscript arg1 -n 20. You can access arguments via $argv variable in php script
I can run facebook.php script from ssh below:
cd /var/www/
php facebook.php
But I want to run to script 1 line command because i want to use it on cron. Like this:
php /var/www/facebook.php
I tried other commands on ssh but dont worked. Only first command is worked for me
if /usr/bin/php /var/www/facebook.php is not working, it might a case of your php path is different then /usr/bin/php.
I am trying to execute a command from php script using php exe function.
The script calls .exe file located in program files whereas my xampp is intalled in E:
I m trying the following command C:\\Program Files\\GPStill\\pstill.exe its not working.But if i manually open cmd prompt and stand in c:\prgram files folder than run pstill.exe it works...
Any ideas ???
you need to escape the folders for example
<?php
$command 'C:\"Program Files"\"Internet Explorer"\iexplore.exe';
exec($command);
?>