gorelative gorelative - 3 months ago 40
PHP Question

CodeIgniter CLI giving system_path error "path does not appear to be set correctly."

I have a cron task setup to run the following:

php /var/www/vhosts/examplesite.com/index.php cron processCategoryItemCount


When i run this on my production server (hosted via MediaTemple dv4) the following error flashes on the ssh window:


Your system folder path does not appear to be set correctly. Please
open the following file and correct this: index.php


When i run the php CLI command on my development mac, i dont get any errors at all.

As far as i can tell my system_path is set properly.. here is the snippet.

/*
*---------------------------------------------------------------
* SYSTEM FOLDER NAME
*---------------------------------------------------------------
*
* This variable must contain the name of your "system" folder.
* Include the path if the folder is not in the same directory
* as this file.
*
*/
$system_path = 'system';


Manual Testing



I did some testing to go through the code that CI uses to determine
system_path
and
application_path
. From what i can tell its working properly..

CodeIgniter Uses The Following Code For path validation

// Set the current directory correctly for CLI requests
if (defined('STDIN'))
{
chdir(dirname(__FILE__));
}

if (realpath($system_path) !== FALSE)
{
$system_path = realpath($system_path).'/';
}

// ensure there's a trailing slash
$system_path = rtrim($system_path, '/').'/';

// Is the system path correct?
if ( ! is_dir($system_path))
{
exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
}


As a result I made a test.php file and stuck it in my httproot..

<?php
$system_path = 'system';
echo "index.php dir is: ".dirname(__FILE__)."\n";
chdir(dirname(__FILE__));
echo "System Dir is: ".realpath($system_path)."\n";
if ( ! is_dir($system_path)){
exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
}else{
echo "System Path Set Properly\n";
}
sleep(30);


I ran this via command line with this command:

/usr/bin/php /var/www/vhosts/examplesite.com/client/stage/test.php`


This is what i get back:



index.php dir is: /var/www/vhosts/examplesite.com/client/stage
System Dir is: /var/www/vhosts/examplesite.com/client/stage/system
System Path Set Properly


So, a bit more testing and i discover the problem is in this part:



if ( ! is_dir($system_path))
{
exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
}

Answer

The problem was permissions related. I never thought of this, but when pulling from github if im logged in as root obviously the ownership is root. As a result php cannot execute properly.

i ran: chown exampleuser:psacln index.php and alls good now!

So as a lesson to others running into this issue.. if you're getting the same problem make sure ownership and file permissions are right!