After updating a server to EasyApache 4 I noticed that several cron jobs quit working. After some testing, I've determined that PHP scripts running as crons are not properly including files from upper level directories after EasyApache 4 is installed.
To demonstrate the issue, I created a simple PHP script with two files:
The first file is public_html/config.php with the following contents:
And the second file is public_html/testdir/testfile.php with the contents:
When I open testdir/testfile.php in my browser, the file runs fine with both EasyApache 3 and EasyApache 4.
I added the file as a cron job with the command:
/usr/bin/php -f /home/testsite/public_html/testdir/testfile.php
In EasyApache 3 the file continues working as expected. However, after upgrading to EasyApache 4, the file terminates with a fatal error:
[12-Mar-2016 22:23:01 UTC] PHP Warning: require(../config.php): failed to open stream: No such file or directory in /home/testsite/public_html/testdir/testfile.php on line 3
[12-Mar-2016 22:23:01 UTC] PHP Fatal error: require(): Failed opening required '../config.php' (include_path='.:/opt/cpanel/ea-php56/root/usr/share/pear') in /home/testsite/public_html/testdir/testfile.php on line 3
I've reverted back to EasyApache 3 and reinstalled EasyApache 4 several times, and the results have been consistent. The file always runs fine when I open it in a browser, and it works fine as a cron in EasyApache 3, but it fails to run as a cron in EasyApache 4. The file also works fine as a cron on a different server where CloudLinux is installed. I used PHP 5.6 in each test.
Another thing I noticed is that when running as a cron in EasyApache 4, the errors are written to the user's home directory /home/testsite/error_log rather than the directory in which the PHP file was executed. I wasn't sure if this was by design, or if it could be related to the issue.
To demonstrate the issue, I created a simple PHP script with two files:
The first file is public_html/config.php with the following contents:
<?php
$dbhost = 'localhost';
$dbname = 'testsite_database';
$dbuser = 'testsite_dbuser';
$dbpass = 'Testing123';
?>
$dbhost = 'localhost';
$dbname = 'testsite_database';
$dbuser = 'testsite_dbuser';
$dbpass = 'Testing123';
?>
And the second file is public_html/testdir/testfile.php with the contents:
<?php
require "../config.php";
$dblink = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die("Unable to connect to database");
mysqli_query($dblink, "INSERT INTO log (logentry) VALUES ('Successfully ran file at ".date("F j, Y, g:i:s a")."')");
?>
require "../config.php";
$dblink = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die("Unable to connect to database");
mysqli_query($dblink, "INSERT INTO log (logentry) VALUES ('Successfully ran file at ".date("F j, Y, g:i:s a")."')");
?>
When I open testdir/testfile.php in my browser, the file runs fine with both EasyApache 3 and EasyApache 4.
I added the file as a cron job with the command:
/usr/bin/php -f /home/testsite/public_html/testdir/testfile.php
In EasyApache 3 the file continues working as expected. However, after upgrading to EasyApache 4, the file terminates with a fatal error:
[12-Mar-2016 22:23:01 UTC] PHP Warning: require(../config.php): failed to open stream: No such file or directory in /home/testsite/public_html/testdir/testfile.php on line 3
[12-Mar-2016 22:23:01 UTC] PHP Fatal error: require(): Failed opening required '../config.php' (include_path='.:/opt/cpanel/ea-php56/root/usr/share/pear') in /home/testsite/public_html/testdir/testfile.php on line 3
I've reverted back to EasyApache 3 and reinstalled EasyApache 4 several times, and the results have been consistent. The file always runs fine when I open it in a browser, and it works fine as a cron in EasyApache 3, but it fails to run as a cron in EasyApache 4. The file also works fine as a cron on a different server where CloudLinux is installed. I used PHP 5.6 in each test.
Another thing I noticed is that when running as a cron in EasyApache 4, the errors are written to the user's home directory /home/testsite/error_log rather than the directory in which the PHP file was executed. I wasn't sure if this was by design, or if it could be related to the issue.