Resolved Cronjob /Scheduled PHP script how to set include_path

MHC_1

Regular Pleskian
Server operating system version
AlmaLinux 9.7
Plesk version and microupdate number
Plesk 18.0.74
WE have a scheduled cronjobs which run
Cron <"account"@"server> (/opt/plesk/php/8.4/bin/php -f 'cronMailer/docuMailer.php') > /dev/null

But these come back with an error because:

PHP Warning: require(class.database.php): Failed to open stream: No such file or directory in /var/www/vhosts/account.co.uk/cronMailer/docuMailer.php on line 18
PHP Fatal error: Uncaught Error: Failed opening required 'class.database.php' (include_path='.:/opt/plesk/php/8.4/share/pear') in /var/www/vhosts/account.co.uk/cronMailer/docuMailer.php:18

The code in the PHP file is:

require class.database.php


The Standard Public Website files works correctly because the PHP in the "PHP" Plesk settings under "additional Directives" shows:


include_path = ".:/usr/local/lib/php"
open_basedir = {WEBSPACEROOT}{/}:/tmp/:/usr/local/lib/php/

The class we need to use is placed in /usr/local/lib/php . How do we tell the PHP iteration that runs the Cronjob to load the "include_path" which works perfectly for the public facing PHP.

Documentation on this is obscured because the word "include" incorporates all the answers involving standard PHP script "include" function.
 
Are you running it as a scheduled task or manually setting up through the server itself? If as a scheduled task, you doing it under the domain level or system level?

Ideally you would want to create the task under the domain level choosing to run a PHP script, this will utilize the PHP settings for the domain and thus should avoid those errors.

See Scheduling Tasks
 
@scsa20 This is a "Scheduled Task"/cronjob under the domain level. And yes it's choosing to run the PHP script and the script keeps coming back with these errors that are not present when the website PHP is run. There are no options for Scheduled Tasks as to setting which PHP Handler (and by extension which PHP.ini settings) to run Cronjobs under.

Also I am unclear how to set the -c for the php.ini file (as set in the other question I commented on) in the construct for "run a PHP Script" . I assume I'd have to run a full separate command, but again, If running a full separate command can't I just tell the CLI to simply use the same handler as the website uses?

Plesk has an epic lack of documentation on these things.
 
Then what you can do is switch it to run a command and run it as so:

Bash:
/opt/plesk/php/8.4/bin/php -c /var/www/vhosts/system/account.co.uk/etc/php.ini -f /var/www/vhosts/account.co.uk/cronMailer/docuMailer.php

I have not test it so you might need to change the subscription to allow bash for it to work properly or run at the system, etc.
 
Back
Top