Skip to content

Shell command task on clearos fails to select correct PHP version

It seems without invoking the method Process::inheritEnvironmentVariables, some needed environment variables are not set on the child process. On ClearOS, it will make tasks to use the php5.6, even if you call the scheduler using php7.2 directly.

We have a tiki using cronjobs to trigger the scheduler, like below:

# Run Scheduler
* * * * * su apache -s /bin/bash -c 'cd /var/www/virtual/zzz.zzzz.zzz/html && /opt/rh/rh-php72/root/usr/bin/php -d memory_limit=256M console.php scheduler:run'

The error is something like below

From root@xxxx.xxxxx.xxxx  Mon Oct 19 02:17:01 2020
Return-Path: <root@xxxx.xxxxx.xxxx>
X-Original-To: root
Delivered-To: root@xxxx.xxxxx.xxxx
From: "(Cron Daemon)" <root@xxxx.xxxxx.xxxx>
To: root@xxxx.xxxxx.xxxx
Subject: Cron <root@tiki> su apache -s /bin/bash -c 'cd /var/www/virtual/zzz.zzzz.zzz/html && /opt/rh/rh-php72/root/usr/bin/php -d memory_limit=256M console.php scheduler:run'
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: <XDG_SESSION_ID=1944>
X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/0>
X-Cron-Env: <LANG=en_US.UTF-8>
X-Cron-Env: <PATH=/usr/clearos/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Date: Mon, 19 Oct 2020 02:17:01 +0000 (UTC)
Status: R

Warning: Tiki21 and above expects PHP 7.2.0 and above. You are running 7.2.24 at your own risk
ini_set(): Headers already sent. You cannot change the session module's ini settings at this time on line 38 of /var/www/virtual/zzz.zzzz.zzz/html/tiki-setup_base.php
session_name(): Cannot change session name when headers already sent on line 188 of /var/www/virtual/zzz.zzzz.zzz/html/tiki-setup_base.php
ini_set(): Headers already sent. You cannot change the session module's ini settings at this time on line 233 of /var/www/virtual/zzz.zzzz.zzz/html/tiki-setup_base.php
[notice] ***** Running scheduler Run Tracker Events Batch ToDo *****
Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead. on line 305 of /var/www/virtu
al/zzz.zzzz.zzz/html/vendor_bundled/vendor/symfony/process/Process.php
[error] ***** Scheduler Run Tracker Events Batch ToDo - FAILED *****
PHP Parse error:  syntax error, unexpected '?' in /var/www/virtual/zzz.zzzz.zzz/html/lib/init/initlib.php on line 77


Cannot modify header information - headers already sent by (output started at /var/www/virtual/zzz.zzzz.zzz/html/tiki-setup.php:34) on line 0 of Unknown

After accepting this change, the cronjob should be something like

* * * * * su apache -s /bin/bash -c '. /opt/rh/rh-php72/enable; php -d memory_limit=256M /var/www/virtual/zzz.zzzz.zzz/html/console.php scheduler:run'

Merge request reports