tags:

views:

41

answers:

5

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

+3  A: 

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/

Lizard
thanks just got there myself!
Haroldo
Nice one... Please feel free to accept my answer! and vote up ofcourse!
Lizard
+1  A: 

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)

PHPology
A: 

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.

AllenJB
A: 

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.

symcbean
A: 

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.

narcisradu