I have run into an annoying issue that seems to be popping up intermittently across my applications.
These applications live in /data/www/directory which is the php document root. All of these applications need to access a shared php file for SSO authentication which lives in /usr/share/php.
Even if I change the location of the file to /data/new/path, it will still fail.
When a file uses include_once "SSO.php";, it will sometimes fail, resulting in the following message:
Warning: include_once(): Failed opening '/usr/share/php/SSO.php' for inclusion (include_path='.:/usr/share/php') in /data/www/directory/path/to/index.php on line 2
I am using the default include_path in the apache2 php.ini which is where SSO.php lives.
The weird thing about this issue, is that if I open the file with file_get_contents(), I can var_dump the contents onto the screen. Example:
var_dump(file_get_contents('/usr/share/php/SSO.php'));
In the example I know that I'm using an absolute path. I have also tried to use include_once with the absolute path to the shared php file with the same error resulting.
Any suggestions would be excellent!
I am running xampp, and I want to have multiple websites in the htdocs folder. When I just install Wordpress into the htdocs folder, it works fine. However, when I clone (from github) a pre-existing build of wordpress and place it into the htdocs folder (ex - htdocs/somesite.com) I cannot access it.
I get an error of:
Warning: require(C:\xampp\htdocs\mysite.com/wp-includes/load.php):
failed to open stream: No such file or directory in
C:\xampp\htdocs\mysite.com\wp-settings.php on line 21
Fatal error: require(): Failed opening required
'C:\xampp\htdocs\mysite.com/wp-includes/load.php'
(include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\mysite.com\wp-settings.php on line 21
I am confused on two things:
I see the file there that is SAYS is missing in the directory. This I have triple and quadruple checked. I also do not understand the reference to the c:\xampp\php\PEAR path
I also do not know whether or not there are problems coming from the fact that the slashes between directories changing direction are causing the problem. Like why are they starting off with the "\" but then going to "/" after the "mysite.com".
This is the second time I have run into this problem. What am I doing wrong?
Hi I have this database_setup script witten in php. I have a project in a Linux debian machine. The top of the file looks like this:
database_setup.php
require_once("../classes/admin.php");
require_once("../classes/client.php");
require_once("../classes/database.php");
require_once("./config.php");
But when I run php database_setup.php I get the following error:
PHP Warning: require_once(../classes/admin.php): failed to open stream:
No such file or directory in /path/to/the/file/database_setup.php on line 6
PHP Fatal error: require_once():
Failed opening required '../classes/admin.php'
(include_path='.:/usr/share/php:/usr/share/pear')
in /path/to/the/file/database_setup.php on line 6
When I run other code as usual with "normal" contact with the database (I mean the normal case being one where the files of models (as client and admin ) are in the same directory as the database) there is no fatal error or warning.
The config.php file contains the password and name of the db, and so on, which the database.php requires(_once). And the database_setup is in the same folder as the config file.
I really don't understand why the code works on my MAMP server on my mac but not on another system. Has it to do with apache2.conf or something else? Thanks.
I think that this
require_once("../classes/admin.php");
Will be relative to where you are running the php command from.
Try changing directory to the folder above classes and then running php database_setup.php
You can change directory via the command line like this
cd /var/www/httpdocs/classes
Changing the open_basedir directive to work with subdomains works absolutely fine on my server by simply setting the directive to:
C:\Inetpub\vhosts\domain.net\subdomains\beta\httpdocs\;C:\Inetpub\vhosts\domain.net\httpdocs\
However, when I try to do the same from one hostname to another, the open base directory does not work. This is what I am setting:
C:\Inetpub\vhosts\domainOne.net\httpdocs\;C:\Inetpub\vhosts\domainTwo.net\httpdocs\
I know that this can be quite challenging to achieve with FastCGI and PHP, but surely there is an easy fix?
I have tried giving permissions to the user of the current site, on the other sites folder but this has not worked.
The error being returned (as expected) is the following:
Warning: include(): open_basedir restriction in effect.
File(C:\Inetpub\vhosts\domainOne.net\httpdocs_snippets_global\paths.php)
is not within the allowed path(s):
(C:\Inetpub\vhosts\domainTwo.com\httpdocs\;C:\Inetpub\vhosts\domainOne.net\httpdocs)
in C:\Inetpub\vhosts\domainTwo.com\httpdocs\index.php on line 3
Warning:
include(C:\Inetpub\vhosts\domainOne.net\httpdocs_snippets_global\paths.php):
failed to open stream: Operation not permitted in
C:\Inetpub\vhosts\domainTwo.com\httpdocs\index.php on line 3
So my question is, how do I open the base directory cross domain on a Windows Server running IIS 7, Plesk 11 and PHP 5.3 running as FastCGI Application?
Thanks in advance
All sorted, the open base directory setting was indeed correct.
I was on the right lines with adding permissions to the user, I just added the wrong user!
So quite simply, if you run into this, assuming this is the issue you are experiencing, just make sure the user of the website in question also has permissions on the folder and files of the included directory.
I am getting the following error from Apache
[Sat Mar 19 23:10:50 2011] [warn] mod_fcgid: stderr: PHP Fatal error: require_once() [function.require]: Failed opening required '/common/configs/config_templates.inc.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/viapics1/public_html/common/configs/config.inc.php on line 158
I am definately not an expert of Apache but the file config.inc.php & config_templates.inc.php are there. I also tried navigating to a test.html page I placed in common/configs/ so I assume there is no rights issues going on. I also set the rights on config_templates.inc.php to give everyone read, write, and execute rights. Not sure what to do at this point, I checked to see if there was a /usr/share/php directory and I found there was not but when I did yum install php it said it had the latest. Ideas?
It's not actually an Apache related question. Nor even a PHP related one.
To understand this error you have to distinguish a path on the virtual server from a path in the filesystem.
require operator works with files. But a path like this
/common/configs/config_templates.inc.php
only exists on the virtual HTTP server, while there is no such path in the filesystem. The correct filesystem path would be
/home/viapics1/public_html/common/configs/config_templates.inc.php
where
/home/viapics1/public_html
part is called the Document root and it connects the virtual world with the real one. Luckily, web-servers usually have the document root in a configuration variable that they share with PHP. So if you change your code to something like this
require_once $_SERVER['DOCUMENT_ROOT'].'/common/configs/config_templates.inc.php';
it will work from any file placed in any directory!
Update: eventually I wrote an article that explains the difference between relative and absolute paths, in the file system and on the web server, which explains the matter in detail, and contains some practical solutions. Like, such a handy variable doesn't exist when you run your script from a command line. In this case a technique called "a single entry point" is to the rescue. You may refer to the article above for the details as well.
If you have SELinux running, you might have to grant httpd permission to read from /home dir using:
sudo setsebool httpd_read_user_content=1
Run php -f /common/configs/config_templates.inc.php to verify the validity of the PHP syntax in the file.
You could fix it with the PHP constant __DIR__
require_once __DIR__ . '/common/configs/config_templates.inc.php';
It is the directory of the file. If used inside an include, the directory of
the included file is returned. This is equivalent to
dirname __FILE__ . This directory name does not have a trailing slash
unless it is the root directory. 1
Just in case this helps anybody else out there, I stumbled on an obscure case for this error triggering last night. Specifically, I was using the require_once method and specifying only a filename and no path, since the file being required was present in the same directory.
I started to get the 'Failed opening required file' error at one point. After tearing my hair out for a while, I finally noticed a PHP Warning message immediately above the fatal error output, indicating 'failed to open stream: Permission denied', but more importantly, informing me of the path to the file it was trying to open. I then twigged to the fact I had created a copy of the file (with ownership not accessible to Apache) elsewhere that happened to also be in the PHP 'include' search path, and ahead of the folder where I wanted it to be picked up. D'oh!
you can set the include path in php.ini
include_path = ".:/home/viapics1/public_html"
I was having the exact same issue, I triple checked the include paths, I also checked that pear was installed and everything looked OK and I was still getting the errors, after a few hours of going crazy looking at this I realized that in my script had this:
include_once "../Mail.php";
instead of:
include_once ("../Mail.php");
Yup, the stupid parenthesis was missing, but there was no generated error on this line of my script which was odd to me