473,394 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Include() & Paths - Best Practices

I have a question regarding paths and the include() statement in PHP.

I develop in a Windows environment and will be publishing to a Linux
server. I would like to do the following:

1. Setup my include references in such a way that I don't have to
change them all every time I have to publish to the production server

2. Setup above in such a way that won't involve php.ini (& LInux
equivalent), as I have access to edit this file locally, but won't be
able to do so in the production environment

My file structure is such:

wwwroot
subdir
global
inc

I tried Windows-styled virtual references such as "/" to refer to the
wwwroot, but that didn't work in the production evironment. I switched
to relative paths (eg include("global/inc/config.inc") or include
("../global/inc/config").

I guess what I'm looking for here is a best practice for how to set
the includes up for maximum portability across servers with different
file systems as well as different platforms. Can you, for instance,
incorporate a variable that defines the root path into the include
statement above? If so, where do you define this variable globally
without having to add to every file? (b/c you can't use an include
statement if you haven't gotten the includes to work) Is there an
equivalent of global.asa for the PHP world?

I'm just raising some issues with my experience thus far. I know
there's a solution and a best practice that I'm just missing to the
point--I would appreciate any wisdom that could be shared.
Jul 17 '05 #1
6 4636
I have different include paths on my development PC (Windows XP) and my
production server (Linux). I use the php.ini file on my development PC, but
on the Linux server I have an entry in the .htaccess file which sets a
different set of path names. In this way none of my PHP scripts has to
*know* what set of include paths to use, so I do not have to change anything
when copying files from my PC to my server.

--
Tony Marston

http://www.tonymarston.net

"JStrummer" <go***********@jstrummer.e4ward.com> wrote in message
news:13*************************@posting.google.co m...
I have a question regarding paths and the include() statement in PHP.

I develop in a Windows environment and will be publishing to a Linux
server. I would like to do the following:

1. Setup my include references in such a way that I don't have to
change them all every time I have to publish to the production server

2. Setup above in such a way that won't involve php.ini (& LInux
equivalent), as I have access to edit this file locally, but won't be
able to do so in the production environment

My file structure is such:

wwwroot
subdir
global
inc

I tried Windows-styled virtual references such as "/" to refer to the
wwwroot, but that didn't work in the production evironment. I switched
to relative paths (eg include("global/inc/config.inc") or include
("../global/inc/config").

I guess what I'm looking for here is a best practice for how to set
the includes up for maximum portability across servers with different
file systems as well as different platforms. Can you, for instance,
incorporate a variable that defines the root path into the include
statement above? If so, where do you define this variable globally
without having to add to every file? (b/c you can't use an include
statement if you haven't gotten the includes to work) Is there an
equivalent of global.asa for the PHP world?

I'm just raising some issues with my experience thus far. I know
there's a solution and a best practice that I'm just missing to the
point--I would appreciate any wisdom that could be shared.

Jul 17 '05 #2
Tony-

What would I need to add to the .htaccess file? Is it different syntax
than standard PHP? I would appreciate any guidance here. Thanks.
Jul 17 '05 #3
Put something like this into your .htaccess file:

php_value include_path ".:/usr/local/lib/php:/path2;/path3"

--
Tony Marston

http://www.tonymarston.net

"JStrummer" <go***********@jstrummer.e4ward.com> wrote in message
news:13**************************@posting.google.c om...
Tony-

What would I need to add to the .htaccess file? Is it different syntax
than standard PHP? I would appreciate any guidance here. Thanks.

Jul 17 '05 #4
"JStrummer" <go***********@jstrummer.e4ward.com> wrote in message
news:13*************************@posting.google.co m...
I have a question regarding paths and the include() statement in PHP.

I develop in a Windows environment and will be publishing to a Linux
server. I would like to do the following:

1. Setup my include references in such a way that I don't have to
change them all every time I have to publish to the production server

2. Setup above in such a way that won't involve php.ini (& LInux
equivalent), as I have access to edit this file locally, but won't be
able to do so in the production environment

My file structure is such:

wwwroot
subdir
global
inc

I tried Windows-styled virtual references such as "/" to refer to the
wwwroot, but that didn't work in the production evironment. I switched
to relative paths (eg include("global/inc/config.inc") or include
("../global/inc/config").
In my opinion, given that your application has a defined directory
structure, I'd always use relative paths.
I guess what I'm looking for here is a best practice for how to set
the includes up for maximum portability across servers with different
file systems as well as different platforms. Can you, for instance,
incorporate a variable that defines the root path into the include
statement above? If so, where do you define this variable globally
without having to add to every file? (b/c you can't use an include
statement if you haven't gotten the includes to work) Is there an
equivalent of global.asa for the PHP world?
$_SERVER['DOCUMENT_ROOT'] will return the document root. Using by itself,
however, means that you may only install your application at a known point
relative to the web root. I might use separate domain names on my home
machine with separate web roots, but I might move code to publicly
accessible server where I put all code under the same domain but under a
separate directory within that domain. If all paths are relative, you can
make this kind of move freely.

You could add dirname(__FILE__) to the mix to get the full path to the
directory in which your index.php file is located (provided you put that
*in* your index.php... and index.php is your default file in your
applicaiton) and then assign that to a variable you always use concatenated
with the relative file/path you want... but then you might as well just use
relative paths IMO.
I'm just raising some issues with my experience thus far. I know
there's a solution and a best practice that I'm just missing to the
point--I would appreciate any wisdom that could be shared.


I'm a relative path proponent....

- Virgil
Jul 17 '05 #5
JStrummer wrote:
I develop in a Windows environment and will be publishing to a Linux
server. I would like to do the following:

1. Setup my include references in such a way that I don't have to
change them all every time I have to publish to the production server


The best solution is to install your own web server. I'm assuming your
Linux-based server uses Apache? Download a copy -- it's free -- and
install it. Just follow some guidelines for security (e.g., only listen
to 127.0.0.1). Add the PHP module. Now you've got a setup that is almost
a mirror of what is live.

--
Brian (remove "invalid" from my address to email me)
http://www.tsmchughs.com/
Jul 17 '05 #6
go***********@jstrummer.e4ward.com (JStrummer) wrote in message news:<13*************************@posting.google.c om>...
I have a question regarding paths and the include() statement in PHP.


<snip>

I use relative path like include('../../foo/foo.php'); working fine all the time.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
3
by: Andreas Busse | last post by:
Hi, I received a big fat package of source code developed with Metrowerks CodeWarrior and now I am trying to convert this project to VC.NET 2003. My problem is, that in order to compile I have...
0
by: karim | last post by:
I have a programmer that wants to learn asp.net(c#) and best practices for coding styles, OO and ease of maintenance. What's the best sample application out there that is a very good source for...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
10
by: Eric | last post by:
Hello, I have some server side includes on a Classic asp page that look something like: <!-- #include virtual="/includes/file1.asp"--> <!-- #include virtual="/includes/file2.asp" --> <!--...
7
by: berkshire | last post by:
We recently upgraded php from 4.3.9 to 4.4.7. Everything is working well, except the php scripts running as cronjobs. It appears the problem is that these scripts utilize the include() function...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.