General developer forum

PHP Warning Require_once(../../config.php): failed to open stream:

 
 
Picture of Samuel Than
PHP Warning Require_once(../../config.php): failed to open stream:
 

Hi all,

Am trying to dive into developement and writing my on importcourse script from external database.

Am getting this error 

PHP Warning:  require_once(../../config.php): failed to open stream: No such file or directory in ....MY web server directory

If i run the php code manually via a web browser it'll work, however when it's triggered by a cron job i get that error. 

Any advice where to go about resolving this ? Thanks

Oh yeah my environment is as follows:

Moodle 1.9.9

VPS running Centos 6.4

PHP 5.4

Apache

MariaDB

 

Thanks again for pointers.

 

 
Average of ratings: -
Picture of Darko Miletić
Re: PHP Warning Require_once(../../config.php): failed to open stream:
Group DevelopersGroup Particularly helpful Moodlers

This relative path assumes that the current directory is the root of moodle, however when you run command line script current directory is most likely something else. You have two options here:

1. in your shell script do something like this:

#!/bin/sh

cd /path/to/moodle/

/usr/bin/php -f <optional relative path>myscript.php

2. Alter your script to look like this:

require_once(dirname(__FILE__) . '/../../config.php');

 

 
Average of ratings: -
Picture of Samuel Than
Re: PHP Warning Require_once(../../config.php): failed to open stream:
 

Oh.. i'll give that a try.

Thanks for pointing out smile

 
Average of ratings: -