Webmin cron job - php

I have been tried for few hours and nearly 1 day to try with this but I failed to make it
I want to run the cron file every 10 minutes and I searched for so many tutorials but I don't know why it is not working. Anyone here who experienced in Webmin scheduled cron job can give me any suggestions?

Have you got PHP-CLI installed on your webmin server? If not, you can install it using:
sudo apt-get install php7.0-cli
sudo apt-get install php5-cli
Either of the commands will work, however it depends on the PHP version you are currently using.
Once installed it will allow you to run PHP command through the command line. Your CRON Job should look simlar to this:
php /var/www/example.com/public_html/crons.php
I haven't had time to test the code, however it should work.

Another solution worked for me was adding complete URL of the file preceding by the 'GET' keyword instead of running it as a php script.
Example:
GET 'https://www.example.com/crons.php'

Related

How to upgrade to PHP 7.0 on macOS Sierra?

I tried to update my PHP version on my mac but I am facing some issues
When i use cURL it freezes and it will never complete the download on the terminal:
This is the cURL command that I am running is: curl -s https://php-osx.liip.ch/install.sh | bash -s 7.2
I tried to download a package manually but I can't extract it or even know how to install it.
You can use home-brew for installation / https://medium.com/#romaninsh/install-php-7-2-on-macos-high-sierra-with-homebrew-bdc4d1b04ea6 , I find it quite better then managing with Mac OS build in PHP
I don't have enough details so I will go in blind guess here.
First judging by screenshot it is stuck on downloading. For how long it was frozen? Maybe you didn't wait enough.
When you downloading the source what you need to do is:
Assuming you downloaded package with name php-7.2.6.tar.gz from PHP Official website.
Execute command tar xzf php-7.2.6.tar.gz from command line. (assuming you are in the same directory as file). It will unpack it in directory called php-7.2.6.
Enter the directory with command cd php-7.2.6.
Enter in terminal ./configure. It will take a while, so make sure to get some coffee.
After ./configure finished, execute command make. This will take a while as well, so you might get a sandwich.
Once command finished executing the last step will be executing command make install. It will be quicker than others, don't worry. After that you will be able to execute php command.
Optional Run make test to make sure everything is fine.
PHP has been installed, HOORAY!
Hope that helped, have a nice day. And if I answered your question, please mark it 'Answered`.

Running the exec() function inside a cron job can't find command

I'm using cron to run a php script at regular intervals:
*/5 * * * * php /path/to/my/script.php
Inside the php script I have an exec command that runs node:
$command_str = 'node my_node_script.js';
exec($command_str, $output_arr, $error_res);
Everything works great on the command line, but not via cron. So I logged the output and I get the following error:
sh: node: command not found
Why is this happening, and how can I fix it?
I figured this out thanks to a comment by John C.
What I did was use which node from the command line to find out where node is installed (in my case it was usr/local/bin/node), and then update the exec() call to use this absolute path:
$command_str = '/usr/local/bin/node my_node_script.js';
exec($command_str, $output_arr, $error_res);
I hope it helps if you run into this challenge.
To avoid conflicts with other packages, Debian dev team has decided to use /usr/bin/nodejs as the path for node.js. If you're using Ubuntu or Debian, you should install node-legacy package to call nodejs using node command:
sudo apt-get install nodejs-legacy
For modern nodejs versions, you should call nodejs command instead or the full path of your nodejs installation:
/usr/bin/nodejs my_script.js
or
/home/user/.nvm/vx.xx.xx/bin/node my_script.js

PHP CLI does not allow run two script at same time

PHP (5.6.11-1 on Debian Strech/sid) does not allows me to run two instaces of cli.
I've tried to execute following script two times. First script runs normally.
Second one is locked until first one is killed.
#!/usr/bin/env php
<?php
$i = 0;
while (++$i) {
var_dump($i);
sleep(1);
}
Do you know what may be reason of that strange behaviour?
Edit: Issue does not occur on other machines. (?)
Edit: Is there something in configuration files of php, that could do that?
Issue was caused by something wrong in configuration (still does not know what was it be).
aptitude purge php5 php5-cli
aptitude install php5 php5-cli
Configuration purging helped.

Run php file via command line on an ubuntu linux server

I am trying to run a php file on a ubuntu linux server but get a 'command not found' error when i run "php file_name.php"
Searching online, i found an article that suggested I run "sudo aptitude install php5-cli" which I did and restarted apache afterwards but I still get this error.
How do I fix this?
Try this once,
Go to terminal.
whereis php
It will show where is php installed.
Export that path to environment variable using following command
export PATH=$PATH;/path/to/php's/bin directory
Then execute required file..
As follows,
php file_to_execute.php
first make sure that you've installed following packs:
php5
php5-cli
php-pear
like this:
sudo apt-get install php5 php5-cli php-pear
then make sure to configure php safely befor using it.
also make your php file executable ( chmod 700 )
Try the following step :
Open your cmd/console or press ctr+alt+t.
php5 /your/path/to/php_file_name.

How to write a auto executable script in php?

From the basic of php i know that php needs to have some action/request to execute so i am little confused about how to do it. I know it can be done but don't know how.
I want to write a php script which will run in server every 6 hours and update the database info from an api.
More Info:
The server i am currently working is in linux. But i want to know how i can do it in both linux and windows.
UPDATE:
Cron does not find my script. I don't know where is the problem is. I have used this command in my cpanel
0 */6 * * * php public_html/path_to_dir/file_to_run.php
I have setup the cron so cPanel send me email. The email i am getting is showing some error.
/bin/sh: 0: command not found
Looking forward to your help.
You need to have something run the script on a timer. This is typically going to be cron (on UNIX based systems such as Linux, OS X, BSD, etc) or Windows Task Schedular (on Windows).
You can use crontab to schedule a process in Unix.
I assume that you're using a Linux based S.O.
Install the php5-cli package as
root with apt-get install php5-cli
(or your pkg manager).
Write and test your script
with the PHP CLI, php
filename.php.
Login as selected
user and set up a crontab using
crontab -e
Write the crontab line: * */6 * * * php /full-path/filename.php
/var/log/messages should log the crontab activities.

Categories