Using Crontab with Plesk to call PHP files

By David Pratt / Tags: , , / 36 Comments / Published: 06-05-10

Having battled with getting a php file to be called from a scheduled task (a.k.a. a crontab task) using the Plesk interface panel on a Linux box, I thought I’d share a bit of a how-to on it because I struggled to find anything helpful out there on the topic.

Here is screen shot of a completed “Schedule New Task” form so that you can see what a working configuration looks like:

Setting up Crontab from within Plesk to load a php file.

Setting up Crontab from within Plesk to load a php file.

The fields on the form look fairly self explanatory to fill out, but the first gotcha for me was how to get it so that the job runs every hour instead of on just one named hour. To get the cron to run every hour you just need to use an asterisk (*), the same technique can be applied for all other time frequencies as well.

Once you’ve set the cron to run at the required interval, you will need to tell it what command to call. This isn’t obvious either. Firstly what you need to do is call php or state the path to the php folder, then pass it the parameter “-q” (to suppress the HTTP header output), and then state the full path of the php file that you want to run e.g.

php -q httpdocs/cron.php

If you just put the path to the name of the php file that you want to run, then the cron will throw an error.

For reference, I’m using Plesk 9.5.1 & PHP 5.3

Category: Tech

Tags: , ,

Posted: on May 6th, 2010 at 8:39 pm.

Feeds: RSS 2.0

36 Responses to “Using Crontab with Plesk to call PHP files”

Glenn July 31st, 2010 at 12:30 pm

A thousand thank yous. This process is so simple yet the information was so hard to find. Running a cron job on plesk was so easy with your help. I spent more time finding this tutorial than i did following it.

Bill August 5th, 2010 at 10:45 am

Thanks for your help, I had trouble working out he full path so this helped a lot.

rakibulalam September 16th, 2010 at 10:35 am

Thx for providing this…

David October 9th, 2010 at 2:19 pm

Great, thank you!!

Elisa Hamdan October 17th, 2010 at 1:07 am

This helped a lot! It wasn’t letting PHP run but with the “php -q” trick it went all well! Thanks!

selim October 29th, 2010 at 11:44 pm

Thanks for that simple and useful example!

Maria Antignolo December 8th, 2010 at 12:39 pm

Thanks a lot for your clear explanation :)

David Pratt December 14th, 2010 at 7:15 pm

The other thing you can do is use wget to ping the target file e.g.
wget -O - -q -t 1

botiko January 12th, 2011 at 10:48 am

This is exactly what i was looking for and it was hard to find.
Thanks for sharing.

joachim February 12th, 2011 at 6:59 pm

It makes error:Could not open input file: –q

please help

sara April 18th, 2011 at 2:39 pm

i need the ocde for :
the file is in the cron_jobs folder and the name is invoice_cron.php
i try this code but it dont go

php -q httpdocs/cron_jobs/invoice_cron.php

please help
which code i must use ?

Jo May 21st, 2011 at 7:47 pm

Thank you! This helped me a lot :)

Lee May 21st, 2011 at 11:25 pm

sara the code ur using is invalid it has to be full path not jsut httpdocs if u had 5 domains it wouldnt know which httpdocs to use so something like either
php -q /srv/www/vhosts/yourdomain/httpdocs/yourcronfile.php
or typically
php -q /var/www/vhosts/yourdomain/httpdocs/yourcronfile.php

shazly August 1st, 2011 at 3:13 pm

Thanks a dozen david!

lakshmikanth September 15th, 2011 at 5:23 pm

As suggested by Lee cron job works likes a charm for my main domain i.e ,so the path for this is php -q /srv/www/vhosts/mydomain/httpdocs/yourcronfile.php

if i need to run cronjob on my subdomain i.e what would be be the path for it

Ralph September 25th, 2011 at 10:26 am

I have a php socket server script that I would like to run as a crontab. Thing is, I would like it to start when the webserver starts and stay running. Crontab seems to run at regular intervals and I am not sure if once started it stays running and if it does how would I kill it to run it again. It is not practical to leave an SSH session open. Any suggestions? Thank you.

Jacques October 5th, 2011 at 10:23 pm

Thanks a lot, I use it to backup a joomla website with akeeba backup.

Works like a charm!

Justin Nahin October 13th, 2011 at 10:33 pm

I am getting an email every time the cron executes in Plesk. How do I turn this off? in cPanel it was really easy, checkbox right on the cron page.

anonymous October 17th, 2011 at 10:56 pm

@Justin Nahin

just add >/dev/null 2>&1 at the end of the command

Leon November 4th, 2011 at 5:38 pm

Thanks man. I swear I spent about 4 hours trying to get this working about 1 year ago. The servers tech support also couldn’t get this working. After a request to implement this again I followed your tutorial and in little more than 2 mins, it works!!!!!

Tim November 9th, 2011 at 12:15 pm

This post made my day! Thanks a lot!

I would like to add to use a seperate cronjob user or the www-data which has its root in /var/www (assuming you use ubuntu lte)

Ronny Singh November 21st, 2011 at 12:31 pm

Thanks for information. This is very use full for plesk users.


Tim January 7th, 2012 at 12:06 am

I had everything BUT the -q. Without the -q I was getting errors that cron couldn’t access the file. With -q, everything works just fine.

ashley sargent January 8th, 2012 at 10:27 am

i have followed this exactly but my crons still dont work please can you help me its for my text based browser game

Selçuk January 19th, 2012 at 10:16 pm

thanks for your info. Very usefuly for me.

Mantas February 5th, 2012 at 5:33 pm

Thanks, that helped me too, didn’t know about that -q

dave February 13th, 2012 at 3:41 am

exactly what I was looking for – thank you!

Ranma March 2nd, 2012 at 2:00 pm

Hi there,
The cronjob is running when I launch the runcronjobs.php from shell but when I try from plesk I keep getting errors.
This is the set path:
/usr/bin/php -q /var/www/vhosts/
and this is the error I am getting:
Could not open input file: /var/www/vhosts/

What’s wrong with it? Thanks!

Ranma March 4th, 2012 at 4:30 pm

For some unknown to me reasons, some Plesks are not much willing to run the above given syntax while prefer this other one

cd /var/www/vhosts/; php -q script.php

At least this is what had worked for me.


bingo March 7th, 2012 at 6:25 pm

Thanks a lot for your tutorial! Is it possible also for shared hosting?

Tison April 18th, 2012 at 2:01 am

All – after some ridiculous searching, if you are using Plesk 10.1 or greater – this will not work for you.

You will need to upgrade server prefs, then it will work as it did in the previous version. Here’s more:

Vitor Soares June 1st, 2012 at 12:00 am

Atenção! O CronTab não funciona quando você passa um parâmetro GET. Ex: cronJob.php?funcao=teste

So funciona acessando arquivos diretos ex: cronJob.php

Bilal July 3rd, 2012 at 1:09 am

I want to run a php file that i have in all subdomains .. i have around 500 subdomains and i dont want to create a cron job for each .. can i make one single cron job that goes in each subdomain and get the php file execute


Theo August 10th, 2012 at 4:58 am

For some that gifs the error -: php: command not found

put in ssh follow command /opt/psa/bin/server_pref -u -crontab-secure-shell “/bin/sh”

From plesk forum

Greetings Theo Lodewijk

krishna September 26th, 2012 at 11:16 am

thanks alot….. i have find the correct solution after one month ….. this task is my solution ….. thanks alot once again

krishna September 26th, 2012 at 11:20 am

hello ranma u no need to include /var/www/vhosts/……..

u just include after httpdocs/cron/cron.php … bcz some of ur hosting by the seller account .. thats like a sub admin… super admin is a host provider… so if u put in to the commnd “php -q httpdocs/cron.php” thats enf…. thanks again to this blog..

Leave a reply