php script Config settings - php

I have found a little script which looks interesting, you can download the svn from google code at
http://code.google.com/p/streetwire/source/browse/
I am trying to set it up on my xampp localhost install, and there is little documentation, here are the first two lines of the config
// Paths
define('VHOST_DIR', '/data/vhost');
define('ROOT_DIR', VHOST_DIR . '/www.streetwire.org');
I have tried the following settings but it doesnt seem to work
// Paths
define('VHOST_DIR', 'C:/xampp/htdocs');
define('ROOT_DIR', VHOST_DIR . '/streetwirescript');
For anyone who has looked at the script, im not sure where to go for the 'start' page of the script either!!
Any thoughts on what should go into Vhost_dir?

Searching through the trunk (http://www.google.com/codesearch?q=root_dir+package%3Ahttp%3A%2F%2Fstreetwire.googlecode.com&origq=vhost_dir&btnG=Search+Trunk), VHOST_DIR is only used to define ROOT_DIR. It looks like all that matters is that ROOT_DIR points to the folder that the script is located in.

It's also possible that the script doesn't run on Windows.

It looks like you need to set /docs as the document root for this to work. E.g. index.php I assume you've seen INSTALL too.
Do you have error reporting on and set to maximum? There's a devsite constant in config that I assume gives error information too. What errors are you getting?

Related

How come my code works separately but not when I merge it with my controller?

I wrote this code in a test.php file.
<?php
include ($_SERVER["DOCUMENT_ROOT"].'/MySite/protected/MyYouTube/google/src/Google/autoload.php');
require_once ($_SERVER["DOCUMENT_ROOT"].'/MySite/protected/MyYouTube/google/src/Google/Client.php');
require_once ($_SERVER["DOCUMENT_ROOT"].'/MySite/protected/MyYouTube/google/src/Google/Service/YouTube.php');
?>
If I go to this file like this: localhost/MySite/protected/MyYouTube/test.php it works, but if I copy the same code into my controller that is located under the same folder as test.php, I get this:
include(Google_Service.php): failed to open stream: No such file or
directory
There are no conflicts with the imports. In fact, the controller and view can be empty and still I get the same thing.
Apparently that happens when autoload.php is not actually loaded.
How is it possible that when the code is integrated into the website it throws this error?
This is what the path to my site looks like:
localhost/MySite/index.php/user/view It seems that the way I visit the file matters.
I tried several things. I tried importing the test.php into my view or my controller, and still I get the same error. I tried using Yii::app()->basePath and it gives the same problem.
The paths are correct, I have checked several times. How can I fix this?
The include path is actual server path, not site path, if you use / at the beginning, you are telling it to look in the server root.
If you know the absolute path in the server you can use it like /var/www/MySite or c:\mysiteif you don't know that then you use relative paths.
$_SERVER["DOCUMENT_ROOT"] works well with PHP 5.3, not sure if below check your version. Try removing the '/' before the MySite part, as the variable already does it for you so it might be printing like localhost//MySite, although I'm not sure if that should or shouldn't work. ]
Also the autoload php should be loaded with a require_once function, not with the include. Good luck!

include_path behaviour not working as expected

I've just moved a load of sites to a new VPS and have a strange problem
with include_path. It's something that worked fine on the old server but
not on the new.
I'll try and explain it using a simple example...
In /home/kin/www/lib/Zend and also in /home/kin/www/ipb/_membadmin/Zend
there is a file called test1.php which simply echoes which folder it is in.
In /home/kin/www/ipb/_membadmin there is a file called test.php
It has one line....
require_once 'Zend/test1.php';
When you run it, as you would expect, it echoes the line from test1.php in
/home/kin/www/ipb/_membadmin/Zend
If you then rename /home/kin/www/ipb/_membadmin/Zend to something else (so
the 'include' statement can't find it), and run test.php again, it SHOULD
(I think) echo the file in /home/kin/www/lib/Zend because php include_path
is set to include /home/kin/public_html/lib (which phpinfo.php confirms).
... but it doesn't.
Why not? If there is an include path of /home/kin/public_html/lib then
surely
require_once 'Zend/test1.php';
should point to /home/kin/www/lib/Zend. It does on the old server!
I must be missing something obvious but I don't know what!
Any thoughts?
Thanks
After the diagnostic you just gave it now seems clear that something is overriding the environment path.
There has to be some line in your code where the set_include_path is getting called. Is any Zend specific code running that you haven't checked? That missing directory clearly paints the culprit as a rogue set_include_path()

PHP include path different on different servers

In my site, i have a place that says:
include('../tpls/header_home.php');
and it works. Now i am moving the site to another server, where i get the error:
Warning: include(../tpls/header_home.php) [function.include]: failed to open stream: No such file or directory in /home/usern/public_html/site/tpls/static/home.php on line 4
now if I replace the line with this one, it works:
include('site/tpls/header_home.php');
I could change it, but i don't know how many more places I have of broken paths all around, not only in templates, but files, uploads etc.
I would rather fix the problem generally from a setting or something else I am missing. What do I do?
HINT:
Old working server gives me CWD:
/home/ortho/public_html/site/lib
New server that is problematic gives me CWD:
/home/orthosho/public_html
why?
STRUCTURE:
/home/usern/public_html/site/tpls/static/home.php
/home/usern/public_html/site/tpls/header_home.php
PHP old server: 5.2.17
PHP new server: 5.3.8
maybe that is causing problems?
Well, you basically answered your own question.
Create a settings file where you keep all of these specific paths as variables or otherwise, and include that file wherever you need to reference the paths. That's generally how it works.
settings.inc.php:
$_CONFIG['BASE_DIR'] = "/var/www/yoursite.com/";
some_file.php:
require 'settings.inc.php';
include $_CONFIG['BASE_DIR'] . "some_dependency.php";
I assume you are trying to fix the issue having already made the entire system, without a common settings file, in which case I don't have an answer. You should really centralise things as soon as you start coding to avoid these kinds of issues.
You must have config file, which will have the abosolute path to your site, ofc it will be relative (no need to be hardcoded url) and then use it in all include calls.
Let me explain you, lets say you have a folder in your site called config and in in file called config.php. If you want you could make config class that will hold all your important variables. One of them should be
$ROOT_PATH = str_replace( '\\', '/', dirname( dirname( __FILE__ ) ) ) . '/';
That will be root path relative to your project. Then you can simply call this variable elsewhere when you include something:
require_once $ROOT_PATH . 'blabla/test.php';
Alternative to fix your broken code is to redefine include path with set_include_path()
http://php.net/manual/en/function.set-include-path.php
But for future, learn to code smart :)
Given your new information, the problem is the following:
Old server => ~/public_html/site/lib
New server => ~/public_html
Why? Well, it's because you've set it that way. How do you access the previous website? yourdomain.com/site/, or just yourdomain.com? If it's the first one, then it's bound to be that you've got different web roots.
Now, what you're trying to include is this:
Old server => ~/public_html/site/tpls/...
New server => ~/tpls/
That doesn't quite look right does it?
My guess is that you'd need to alter the document root in httpd.conf in some way.
Sometimes it helps to use dirname so its really relative to the current file. this is what I use if I make cronjobs, and its more "portable" this way
<?php
include dirname(__FILE__)."/../tpls/header_home.php";

DOCUMENT_ROOT is not complete, missing domain folder

I have searched many threads so far but cant seem to find a solution. Inside one of my php scripts I am trying to get a server document root but the value I get is not complete, its simply missing the domain folder. I believe it is due to sharing hosting or smth else.
Here is the current way I am using:
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
and the path I get is like:
/home/content/01/0151247/html
although I know it should be like:
/home/content/01/0151247/html/mydomain
I know as I compared it with SCRIPT_NAME and I see the mydomain there in the path.
Hope someone could direct me.
Thank you and sorry for probably asking another thousand time same question over community, I really tried things around from here, nothing helps me so far.
UPDATE
unfortunately I cant not simply use my index file with DIR as it is a wordpress setup and I am working on a separate folder where I am including some wordpress functionality but for that I need a document_root. If that would help.
UPDATE
apparantly the following way resolved my case, maybe it will help someone one day:
realpath($_SERVER["SUBDOMAIN_DOCUMENT_ROOT"]);
basically because of the server setup and domain configured as a subdomain.
Thanks to all who participated.
Prior to PHP 5.3 you can put a file in the directory whose path you want and define a constant:
define('ROOT_DIR', dirname( __FILE__ ));
After 5.3 you can just do:
define('ROOT_DIR', __DIR__);
The idea being that this would be in config.php of some sort that is included every time the application runs.
Magic Constants Docs
UPDATE
In the config file, you can just append the DOCUMENT_ROOT variable:
$_SERVER['DOCUMENT_ROOT'] = $_SERVER['DOCUMENT_ROOT'] . '/mydomain';
And that should take care of it for you.
Old Solution
The DOCUMENT_ROOT is an environment variable set by the server. So if this is on shared hosting, you cannot changed. An alternative is to set your own constant to it, so in a config type file that is included on your pages you can do something like:
define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT'] . '/mydomain');
And then just use that constant in place of $_SERVER['DOCUMENT_ROOT']. The other option is to contact your host and inquire about it, maybe it was an oversight on their part and they will fix it.
EDIT
Probably using the __DIR__ as others have posted about is the better way, as the DOCUMENT_ROOT can be set to different items and at least with the __DIR__ you should get an accurate directory each time.
Personally, to get the root of a folder in PHP, I use this in the my index file:
define('ROOT', dirname(__FILE__)); // __DIR__ will work under PHP 5.3

php includes that include another php file

I'm getting really muddled up now and my brain hurts! :( lol
Root:
index.php
Includes:
cat.php
dog.php
index includes dog: include("includes/dog.php");
dog includes cat: include("cat.php");
When I run index, for cat it says:
A link to the server could not be established
Access denied for user ...
However, if I run dog, I get no problems...
I'm guessing its the path, but i've tried ./includes/cat.php to no joy...
This is because when you include a relative path, it's relative to the entry point (the first PHP file, called by the webserver).
In dog, do
include(dirname(__FILE__) . '/cat.php'); // __FILE__ is always the name of the php file it's in
It depends on where the script you are executing lies. When you execute /index.php the path of the script set to /, so all includes start from there. This means that you can find /includes/dog.php, but it's not possible to find /cats.php. Mind that, even if you are including cats.php from your /includes/dog.php script, this doesn't change the original execuption path.
When, on the other hand, you are executing /includes/dog.php, your path is set to /includes/, which is why PHP can also find cats.php.
Read Bart's comment on how to solve this.
Another way to solve this is to set the include path of files, take a look at this.
http://ve2.php.net/manual/en/function.set-include-path.php
Thanks for this nice thread.
I used bart's answer to solve this issue. But I still have one question here.
I was surprised that it worked in my mate's system even without using dirname(__FILE__) so I did little research and compared both php.ini files. I noticed there is little difference at include_path parameter in php.ini.
In my php.ini it is set to Pear directory. So I commented out just to test and to my wonder it worked. This is when I realized we need to include some folder which I dont know or comment it out so that it takes default value.

Categories