Run PHP script in cronjob

Discussion in 'Installation/Configuration' started by MichaelK, Sep 21, 2022.

Tags:
  1. MichaelK

    MichaelK New Member

    Hello,
    It took me hours to find out how to run a PHP script in a cronjob. My final solution was: Set "cronjob type limit" in the Client to "Full Cron". Now the cronjob runs fine:
    Code:
    /usr/bin/php8.1 [web_root]/cronjob/script.php
    But setting the cronjob type to "Full" is insecure I guess, the jail is not applied anymore. And if I increase the PHP version of the site, I have to increase the version in the cronjob, too.

    How is it possible to run a PHP script with the current Site-PHP-Version within the jail?

    I found 2 blog posts where there are helpful variables:
    • schaal-it.com/set-php-version-for-cronjobs/
      {SYSTEM_PHP}, {SITE_PHP}
    • timmehosting.de/anlegen-eines-cron-jobs
    Do these two hosters run a newer version of ISPConfig? Or are the placeholders implemented as custom features by them?

    I would love to see those placeholders in "main" ISPConfig, and it would be nice to be able to activate the jail for cronjobs again.
     
  2. michelangelo

    michelangelo Active Member

    Timmehosting runs its own closed fork of ISPConfig, but I agree with you that it would be nice to have this feature with PHP variables for the cronjob system in the public version as well. I'm not sure if the original developer of this feature is interested in porting it back, but I would love to see this happen. If not, it will be up to a volunteer to add this feature to the public version of ISPConfig.
     
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    That#s no problem at all, you probably just sued wrong paths or referred to a PHP version which you did not install into the jail. The easiest and most convenient way is to just use a URL cron by just putting the URL to the crown script into the command field like:

    https://yourdomain.tld/cronjob/script.php

    and ISPConfig takes care to run it on schedule.

    You can also run it as commandline script, but you have to take care of course that you use a PHP version that's in the jail. And your paths must be correct. So the command would be:

    /usr/bin/php8.1 /web/cronjob/script.php

    or if you have a specific PHP version like PHP 8.1 installed into the jail, then you can also use:

    /usr/bin/php /web/cronjob/script.php

    as / in a jail is the web root, so if the cronjob folder is in the web folder, then the above command is what needs to be used.
     

Share This Page