I am trying to implement oAuth using Zendframe work. The script is running great on my localhost whereas when i am hosting the same files on to server (online) it is giving me include path error. I am not figuring out what might be the problem.
Error : Warning: require_once(Zend/Http/Client.php) [function.require-once]: failed to open stream: No such file or directory in
Thank You
You have to add the path in which Zend Framework is installed to your include path:
set_include_path('/path/where/Zend/directory/is' . PATH_SEPARATOR . get_include_path());
The include path is where PHP searches when you include a script.
Also, it's likely that you may have to upload the Zend Framework to your hosting server, as your hosting provider may not have installed it.
Sounds like the location where Zend Framework exists on your local host is defined in the default include path of your PHP configuration, or you're setting some include paths specific to application environment.
Compare the output of your get_include_path() in development and production, to see where it goes wrong. You can add the path where the application can find the Zend files from with set_include_path(), eg:
set_include_path(
APPLICATION_PATH.'/../library'.
PATH_SEPARATOR.
get_include_path()
);
Related
Since I develop on localhost but deploy elsewhere, and since I don't want to have to force my sites to be under a Windows partition's root directory (currently F:\web_dev\htdocs), code like this:
require_once($_SERVER['DOCUMENT_ROOT'] . '/projXY/database/database_common.php');
OdbcExec($sql); // defined in the file above
causes Netbeans to issue a "Warning: unknown function".
Now, I could get round this by using a directory structure like :
F:\project_1
F:\project_2
instead of
F:\web_dev_htdocs\project_1
F:\web_dev_htdocs\project_2
and then using
require_once('/database/database_common.php');
BUT that imposes constraints on where the end-user an install my site.
Simplest by far would be to tell NetBeans which local directory corresponds to $_SERVER['DOCUMENT_ROOT'], but I can't find a configuration option for that. I am sure this is a common problem. Any suggestions?
Update: NetbBeans v7.0.1
Simply add the /path/to/projXY/database/ directory to your project's include path. Netbeans will then pick up the files there and use them as code references.
http://netbeans.org/kb/docs/php/project-setup.html#phpIncludePath
Addendum
Relying on $_SERVER['DOCUMENT_ROOT'] is generally a bad idea. For one, it eliminates the ability to run parts of your application via the console / command line.
You should instead either use configurable, absolute paths to shared libraries or do as in Brandon's answer and use a relative path from __DIR__ (PHP 5.3) or dirname(__FILE__)
Not sure if this is what you are looking for or not, but I commonly use:
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'file.php');
I've been trying to install Zend Gdata. I'm running from a dev environment so have access to php.ini.
I've set the include path and when I run the verification script I get the following..
Ran PHP Installation Checker on 2011-04-28T02:25:20+00:00
PHP Extension Errors Tested
No errors found
Zend Framework Installation Errors Tested
No errors found
SSL Capabilities Errors Tested
No errors found
YouTube API Connectivity Errors Tested
No errors found
But when I try to run any of the demo files I get the floowing error...
Warning: require_once(Zend/Loader.php): failed to open stream: No such file or directory in /usr/lib/php/ZendGdata/demos/Zend/Gdata/blogger.php on line 37
Fatal error: require_once(): Failed opening required 'Zend/Loader.php' (include_path='.:/usr/lib/php') in /usr/lib/php/ZendGdata/demos/Zend/Gdata/blogger.php on line 37
The most logical conclusion is that there is a problem with the include path, but I have checked it and it seems right.
Here's what I have for it...
.:/usr/lib/php/ZendGdata/library/Zend:/usr/lib/php/ZendGdata/library/
Any suggestions would be greatly appreciated.
Put this in the beginning of Blogger.php
set_include_path('/usr/lib/php/ZendGdata/library' . PATH_SEPARATOR . get_include_path());
You say you're setting the include path in a configuration file but that doesn't seem to be affecting CLI. Make sure you're editing the right php.ini file with php --ini
$clientLibraryPath = 'ZendGdata/library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);
if you do not know the root path of the server, use relative path for accessing library. Its pretty handy to use.
above two lines should be written on the top of any file{page1,page2,page3} having folder structure as below
Website
Page1.php
Page2.php
Page3.php
ZendGdata
You can use your relative path as per your need
I just copied the library folder on the root directory of my net server . i.e. /var/www .
and used
require ( 'GChartPhp/gChart.php' ) ;
in my code on the file graph.php.
ERROR : But, for some reason , the browsers do not load this (graph.php) file .
However, I did the same on my local wamp server and my I am able to run the file.
I have no idea what I need to additionally do for this linux / apache server .
Thanks
I suppose the include_path is not configured the same way on your two servers : you might have to add either the WAMP equivalent of /var/www or . to it.
Modifying the include_path can be done by editing your php.ini file, or using set_include_path() at the beginning of your scripts.
Another possible solution would be to use an absolute path to the file you are including -- which can be done using something like this :
include dirname(__FILE__) . '/GChartPhp/gChart.php';
Notes :
__FILE__ will correspond to the full path to the file in which you write it
And using dirname() on it will get you the path to the directory which contains that file.
Which means that this line will use an absolute path... but written relatively to the file in which you put that line.
I'm deploying from my WAMP testing environment to an online test...
Locally I had my include paths something like this:
include('C/wamp/www...')
how do i find the equivalent path on my server?
i've tried using '/' to get to the root but i get this error:
Warning:
require_once(/test123/mvc/views/txt/index_nav_txt.php)
[function.require-once]: failed to
open stream: No such file or directory
in
/home/user/public_html/test123/mvc/views/components/st_footer.php
on line 37
Fatal error: require_once()
[function.require]: Failed opening
required
'/test123/mvc/views/txt/index_nav_txt.php'
(include_path='.:/usr/lib/php:/usr/local/lib/php')
in
/home/user/public_html/test123/mvc/views/components/st_footer.php
on line 37
You would actually need:
require_once("/home/codlife/public_html/test123/mvc/views/txt/index_nav_txt.php");
notice the edition of /home/codlife/public_html/
The initial / Takes you to the root of the server and your code is located inside /home/codlife/public_html/
do you mean
$_SERVER['DOCUMENT_ROOT']
which basically gives you the full path to your working website directory i.e. c:/wamp/www/(windows) or /var/www/vhost/domain.com/httpdocs/ (linux)
You should probably read up on include_path ( http://php.net/include_path ) - This is generally set to include the document root (where your website is) and can be altered so that you don't have to repeatedly include the same paths.
how do i find the equivalent path on my server?
You don't find it - you tell it where it should be. Admittedly this is not always practical when you buy a hosting package (which IME are usually badly supported and come with virtually no documentation).
First thing to note is regardless of where / how the code is hosted, you should always use paths relative to the directories configured on the php include path (or relative to the PHP script initially invoked by the browser request - the '.' entry from the include_path cited in the error) - never absolute paths. You can easily find this out with:
<?php
print ini_get('include_path');
?>
Judging from the path cited in the error message, it appears to be a POSIX system. The root of the filesystem as seen by the webserver might be quite different from the root as seen from your FTP or SSH software, but they are probably the same.
Note that if this is a shared host, then you probably won't have access to put files in /usr/lib/php or /usr/local/lib/php - so your only option is to use a relative path - which is going to get very messy -
You could do some clever coding around this - but do have a look at packages such as Dokuwiki and phpmyadmin to see how they organise the include files in a relocateable way without any dependance on manipulating the php.ini settings.
Alternatively you may be able to override the include_path via .htaccess, e.g.
php_value include_path ".:/home/codlife/public_html:/usr/lib/php:/usr/local/lib/php"
(which would set a base include_path to your document root)
HTH
C.
Use a configuration file where you store things like:
$application_root = '/home/code_life/public_html/';
In this file use all your environment specific variables or constants. When you deploy the application on a different machine, you just update configuration file.
Example:
You have in your root application a folder called settings with settings.php where you can define:
define('DIR_ROOT', dirname(dirname(__FILE__)) . '/');
Now, on every machine, the DIR_ROOT will be the root of your application and you don't have to change anything.
I have a php script that has the following requirement command: require_once 'HTTP/OAuth.php'; the file HTTP/OAuth.php is in php's include_path that is .:/usr/lib/php.
Nevertheless in Eclipse the require_once line is marked with the following warning: Include filename: 'HTTP/OAuth.php' doesn't exist in project:
How can I make my project see the include_path so it can find the require_once file?
I honestly think you can't access any folder outside the root of your web application, basically you can't go any further than /. Imagine you use a shared web hosting service and someone access your files at will, it's just not safe at all.
You can, however, copy the file and put in inside your application scope. E.g: require('/includes/OAuth.php');.