Top Hosting Forum

WebHosting Reviews Forum


Budget DirectAdmin hosting and domain names

TIP: How to call/run php webpage by linux/cpanel cron

Website Development is a general forum for Website Development related issues including questions on codes such as PHP, HTML and Javascript
Hosting Forum Description
Website Development is a general forum for Website Development related issues including questions on codes such as PHP, HTML and Javascript

TIP: How to call/run php webpage by linux/cpanel cron

Postby hostingforum » Tue Oct 23, 2012 1:13 pm

Hi, maybe you have same issue as me. I wanted to run some php script regularly, in my case it was a script which regularly repairs and optimises a mysql table. I have cpanel and its on linux server, so how to do it.

1. Login to clanel and click Cronjob icon. Then set a new cronjob periodicity, like daily, every 15 minutes etc. Then enter command. My command which worked on my reseller linux cpanel account is:
/usr/bin/wget -O - "http://mydomain.com/scripttorun.php"

If you want to hide output, you can do it in quiet mode:
/usr/bin/wget -q -O - "http://mydomain.com/scripttorun.php"

If above command examples dont works, try this:
wget -O - "http://mydomain.com/scripttorun.php"

2. cronjob can be also set directly from linux command line (shell?) Im not sure if this will work, you must have privileges from server admin to do this. Do this only on your own risk if you are not experienced admin, this manual can cause damage to your crontab if used badly
a) login via ssh
b) do: crontab -l
c) if you are able to see list of crons or empty crontab fie, copy its contents by mouse (Ctrl + C and Ctrl + V into notepad) so you can restore it
d) add new crontab like
*/15 * * * * /usr/bin/wget -O - "http://mydomain.com/scripttorun.php"
(runs every 15 minutes)
e) do Ctrl + C command to quit back to command line, save changes by hitting W (write) or similar

Use Google or ask there to get thru this



Ad: There You can have your forum site-wide banner/text ad for $99 yearly. Contact admin


User avatar
hostingforum
Site Admin
 
Posts: 656
Joined: Fri May 20, 2011 7:58 pm
Location: Czech Republic

Return to General Website Development & Programming

Who is online

Users browsing this forum: No registered users and 0 guests

.