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.
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.)
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
I installed SuiteCRM and while trying to run the code below for for the Scheduler...
php.exe -f cron.php
I get the error:
Call to undefined function mysqli_connect()
Can anyone help?
Have you checked the mysqli PHP extension is installed? try viewing the phpinfo, either from a php phpifno(); or from the command line php -i.
If this wasn't installed it would effect the whole installation rather than just the scheduler.
Looks like your command line PHP ( PHP CLI ) refers to seperte location than your PHP.
Get path of php.ini for your command line and then uncomment this line.
extension=mysqli
The cron.php is run from the scheduler, but sometimes I have to run the code to make sure is working properly.
php cron.php all -F -vvv
where
the “all” command will execute all the tasks
The “-F” option forces all the tasks to be executed.
The “-vvv” option sets the output verbosity level to maximum.
If I need to edit my web server user's crontab file, I use this command:
sudo crontab -e -u username
If I need to find out the username the cron job is running on, I use the browser
domain.com/get_current_user.php
assuming I already created the get_current_user.php file.
I have 1 file php: C:\\Xml2InDesign\\InDesignTagConverter.php
I exe it by:
$sjis_cmd="php \"C:\\Xml2InDesign\\InDesignTagConverter.php\";
exec($sjis_cmd, $output);
It not working. What do i must setting?
I run from cmd:
php "C:\Xml2InDesign\InDesignTagConverter.php" "c:\work\link2\\tmp\\5699\\direction.xml" "c:\work\link2\\tmp\\5699\\tables"
Show error: 'php' is not recognized...
Find your php.exe path and run command from there.
Like if your php.exe is in C:\PHP5\php.exe , then you can execute like this
C:\PHP5\php.exe "C:\\Xml2InDesign\\InDesignTagConverter.php\"
Refer this link
OR
if you want to run it through php code then use exec command
The PHP CLI as its called ( php for the Command Line Interface ) is called php.exe It lives in c:\wamp\bin\php\php5.x.y\php.exe ( where x and y are the version numbers of php that you have installed )
If you want to create php scrips to run from the command line that great its easy and very useful.
Create yourself a batch file like this, lets call it phppath.cmd :
PATH=%PATH%;c:\wamp\bin\php\php5.x.y php -v
Save this into one of your folders that is already on your PATH, so you can run it from anywhere.
Now from a command window, cd into your source folder and run >phppath.
Then run
php your_script.php