1

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));
}
NDBoost
  • 10,184
  • 6
  • 53
  • 73
  • 1
    does that error occur if you run the cron file via your browser? – Rooster Apr 27 '12 at 16:19
  • no it does not, if i setup a secured controller that runs the task it doesnt freak out. only on CLI & cron task. – NDBoost Apr 27 '12 at 17:00
  • well then, if you use a wget shell command to run your cron job that should do the trick because its basically like someone visiting that page via a broswer. – Rooster Apr 27 '12 at 17:09
  • i appreciate the comment, but id prefer to fix the problem than dive around it. – NDBoost Apr 27 '12 at 17:18
  • ok but I dont get it, is "cron" one of your controllers there, or is it a command? Did you try writing a "|" between the index.php and cron? or in the first case a "/"? – Taha Paksu Apr 28 '12 at 00:51
  • its a controller, and according to the documentation you dont need anything except for spaces. – NDBoost Apr 28 '12 at 15:33

7 Answers7

4

I`d like to write just a comment, but I couldn't.... I'm new in here and I don't have the option to add a comment on the question.

Well... I had the same problem 1 year ago with my dedicated server.

The solution was to leave the $system_path blank...

$system_path = '';

you can try this instead:

$system_path = './system';
pcsi
  • 604
  • 6
  • 11
  • I left `system_path` blank, and then it errored about `application_path`, left that blank and CLI works great but now http doesn't! – NDBoost May 17 '12 at 13:47
3

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!

NDBoost
  • 10,184
  • 6
  • 53
  • 73
  • im running this at server (while i cant use CLI other than cron job from cPanel, all i can have is report through emails by crons), i've set index.php into 755, i follow to change sys path to empty or `./system`, but it comes no change,. do you have another option? – Henry J Oct 07 '13 at 14:56
3

Another better solution is to use dirname() like,

Change the below 2 lines

$system_path = 'system';
$application_folder = 'application';

By

$system_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'system';
$application_folder = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'application';
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
0
/*
 *---------------------------------------------------------------
 * 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';

/*
 *---------------------------------------------------------------
 * APPLICATION FOLDER NAME
 *---------------------------------------------------------------
 *
 * If you want this front controller to use a different "application"
 * folder then the default one you can set its name here. The folder
 * can also be renamed or relocated anywhere on your server.  If
 * you do, use a full server path. For more info please see the user guide:
 * http://codeigniter.com/user_guide/general/managing_apps.html
 *
 * NO TRAILING SLASH!
 *
 */
    $application_folder = '../application';

you can try this bro if dont work add another ../

definitely the error reporting will not say that so if the path is set correctly :)

just helping ^_^ hope thiss will

Jhonathan H.
  • 2,734
  • 1
  • 19
  • 28
0

Are you sure that nothing got screwed around in FTP transfer? i.e. system is actually in the same directory as index.php?

Also, are you sure you are calling php from the right place? and is the path right?

I had this problem recently: CodeIgniter + Command Line + Cron + Cpanel

Try running it:

/usr/local/bin/php your/path/to/index.php <controller> <method>

For the path, it probably should be a full path? not the www.example.com/index.php? i.e. mine is something like:

/usr/local/bin/php /home/account_name/public_html/index.php <controller> <method> /dev/null 2>&1
Community
  • 1
  • 1
MikeCruz13
  • 1,254
  • 1
  • 10
  • 19
0

In index.php

I have made these changes and worked for me.

$system_path = '../system/';

$application_folder = '../application/';
Harikrishnan
  • 9,688
  • 11
  • 84
  • 127
0

To change all the directories to 755 (-rwxr-xr-x):

find /opt/lampp/htdocs -type d -exec chmod 755 {} \;

To change all the files to 644 (-rw-r--r--):

find /opt/lampp/htdocs -type f -exec chmod 644 {} \;

Fix codeigniter 3.0.0 distributive plz!