cron job is not working - php

Hi I am using justhost web server and trying to set a cron job but it is not producing any output . I am using this command in the cpanel
php -q /home6/username7/public_html/folder/app/cron.php
the name display on cpanel file browser is like home6 . any help will be appreciated . and how to check is this command is right or wrong.thanks in advance

Did you try with this :
Command to run for a PHP5 cron job:
/usr/local/php5/bin/php5 /home/username/public_html/cron.php
Command to run for a PHP4 cron job:
/usr/bin/php /home/username/public_html/cron.php

you should try this. ( give path to php command )
/usr/bin/php -q /home/username/public_html/yourfilename.php
Run a PHP file in a cron job using CPanel

Related

Can I use wget to run a local file as a cron job using relative path above public_html?

I'm trying to setup a script to run in a cron job, and I want it to run once a day. I'm new to cron jobs, and the ones I have seen so far are only using absolute paths like:
http://example.com/path/to/file.
This is the command I want to do in cpanel:
/usr/bin/wget -O - -q -t 1 /home/account/invest/controllers/cron_controller.php
Would this work? Or is another command better than wget?
The best command is php /home/account/invest/controllers/cron_controller.php.

Cron Job command not working

I have a simple script in my server and I need a cron job to make it run every minute. I am using cPanel to set it. What should I enter in the cron job "command" field? I am newbie with cron job commands, I have tried many different options:
/home/enkaizen/public_html/soporte/wp-content/scripts/index.php
/usr/local/bin/php /home/enkaizene/public_html/soporte/wp-content/scripts/index.php
/usr/local/bin/php -q /home/enkaizene/public_html/soporte/wp-content/scripts/index.php
/usr/bin/php /home/enkaizene/public_html/soporte/wp-content/scripts/index.php
/usr/bin/php -q /home/enkaizene/public_html/soporte/wp-content/scripts/index.php
But none seem to be working. I know my script is correct because when I run it manually it does what it is suppose to do.
For in case it helps, my host is https://www.frenzysolutions.com
Any ideas what can I be doing wrong?
To run php from cron try the f flag
php -f /home/enkaizen/public_html/soporte/wp-content/scripts/index.php
It is best practice to use the full path to the executable when using cron. Unfortunately this is distribution/os dependent but it is probably either /usr/bin/php or /usr/local/bin/php
Are you getting any error with "php -q" command ?
Also you can use curl command instead of php -q to execute your scripts through command line.

Cron job is not running

I've tried just about everything to get my cron script to work but am not having any luck. I've been through many mini tutorial several times too! Here's what I'm trying to run...
/usr/bin/php -q /home/username/public_html/yourfilename.php
On cpanel even i am not getting email after running time of my crone job.
thank you
Try this
/usr/bin/php -q /home/username/public_html/yourfilename.php >/dev/null
You need to check below points.
The file location is correct.
check that the crond services running or not. you can check with below commend :
/etc/init.d/crond status
and you should get status running with pid. if you can got it then move on point 3 otherwise. try to restart the cron service via below command:
/etc/init.d/crond restart
and check the logs via below command :
tail -f /var/log/cron
if you getting the cron service working then check your lfd service working on not.
/etc/init.d/lfd status
if its running then check your email proper configure on lfd.
if lfd fine then run below command as root to add cron
crontab -e
give your cron at the end of file with correct format.
sure that time it will work.
if getting any issue in any point. let me know here.

Cannot execute PHP script periodically using crontab on Ubuntu

I want to execute a php script every 5 minutes. I'm using Ubuntu and I followed these steps:
Executed crontab -e from terminal, entered:
*/5 * * * * /usr/bin/php /var/www/test1.php
in the nano text editor, saved it and started the crontab. It gave no errors and said "installing new crontab", but my script is not being executed. I gave the necessary permissions to the files I use in my script, too.
Any help would be greatly appreciated, thanks.
This is what I use for scheduling cron jobs on apache server in cpanel interface :
/usr/bin/php -q /home/domain_name/public_html/cron_test.php
So, you should specify the path to the php executable too, for making the php script work and execute.

Bash script to run php script

I have a php script that I want to be run using a bash script, so I can use Cron to run the php script every minute or so.
As far as I'm aware I need to create the bash script to handle the php script which will then allow me to use the Cron tool/timer.
So far I was told I need to put:
#!/pathtoscript/testphp.php
at the start of my php script. Im not sure what to do from here...
Any advice? Thanks.
If you have PHP installed as a command line tool (try issuing php to the terminal and see if it works), your shebang (#!) line needs to look like this:
#!/usr/bin/php
Put that at the top of your script, make it executable (chmod +x myscript.php), and make a Cron job to execute that script (same way you'd execute a bash script).
You can also use php myscript.php.
Sometimes PHP is placed in non standard location so it's probably better first locate it and then try to execute.
#!/usr/bin/env bash
PHP=`which php`
$PHP /path/to/php/file.php
A previous poster said..
If you have PHP installed as a command line tool… your shebang (#!) line needs to look like this: #!/usr/bin/php
While this could be true… just because you can type in php does NOT necessarily mean that's where php is going to be... /usr/bin/php is A common location… but as with any shebang… it needs to be tailored to YOUR env.
a quick way to find out WHERE YOUR particular executable is located on your $PATH, try..
➜which -a php ENTER, which for me looks like..
php is /usr/local/php5/bin/php
php is /usr/bin/php
php is /usr/local/bin/php
php is /Library/WebServer/CGI-Executables/php
The first one is the default i'd get if I just typed in php at a command prompt… but I can use any of them in a shebang, or directly… You can also combine the executable name with env, as is often seen, but I don't really know much about / trust that. XOXO.
You just need to set :
/usr/bin/php path_to_your_php_file
in your crontab.
I'm pretty sure something like this is what you are looking for:
#!/bin/sh
php /pathToScript/script.php
Save that with your desired script name (such as runPHP.sh) and give it execution rights, then you can use it however you want.
Edit: You might as well not use a bash script at all and just add the "php ..." command to the crontab, if I'm not mistaken.
Good luck!
The bash script should be something like this:
#!/bin/bash
/usr/bin/php /path/to/php/file.php
You need the php executable (usually found in /usr/bin) and the path of the php script to be ran. Now you only have to put this bash script on crontab and you're done!
a quick way to find out WHERE YOUR particular executable is located on your $PATH, try.
Even quicker way to find out where php is ...
whereis php
I'm running debian and above command showing me
php: /usr/bin/php /usr/share/php /usr/share/man/man1/php.1.gz
Hope that helps.
If you don't do anything in your bash script than run the php one, you could simply run the php script from cron with a command like /usr/bin/php /path/to/your/file.php.
I found php-cgi on my server. And its on environment path so I was able to run from anywhere. I executed succesfuly file.php in my bash script.
#!/bin/bash
php-cgi ../path/file.php
And the script returned this after php script was executed:
X-Powered-By: PHP/7.1.1
Content-type: text/html; charset=UTF-8
done!
By the way, check first if it works by checking the version issuing the command php-cgi -v
Create file.php with first line in files: file.php(#!/bin/php) file.sh(#!/bin/bash).
Check installed php.Run command in terminal:
which php
If set there will be an answer:
/usr/bin/php
Run file.php with command:
php file.php
if the file has started then you can write this command to file.sh:
#!/bin/bash
run_php=`php file.php`
echo $run_php
Be careful ' and ` different!!!

Categories