473,396 Members | 1,970 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,396 software developers and data experts.

newbie: website's root directory

Hello,
I am learning PHP5. I need to obtain my website's root directory in .php
code. I tried the code:
echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
but it displays:
__DIR__/var/www/html
although my_website is installed in user's
directory: /home/robert/public_html/my_website.
I don't know why and how to obtain root directory.
Please help.
Thanks!
Nov 10 '08 #1
11 6606
Jivanmukta escribió:
I am learning PHP5. I need to obtain my website's root directory in .php
code. I tried the code:
echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
but it displays:
__DIR__/var/www/html
although my_website is installed in user's
directory: /home/robert/public_html/my_website.
The __DIR__ constant was added in PHP 5.3.0, which as fas as I know is
expected to be released in the next months.

http://es.php.net/manual/en/language...predefined.php

Your problem is that your ISP has configured the web server in such a
way that the DOCUMENT_ROOT value is unreliable. You'll need to calculate
it yourself. A simple dirname(__FILE__) in your site root will do the trick.

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Nov 10 '08 #2
Jivanmukta wrote:
Hello,
I am learning PHP5. I need to obtain my website's root directory in .php
code. I tried the code:
echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
but it displays:
__DIR__/var/www/html
although my_website is installed in user's
directory: /home/robert/public_html/my_website.
I don't know why and how to obtain root directory.
Please help.
Thanks!
echo $_SERVER['DOCUMENT_ROOT'] should display the root. What webserver
are you running (i.e. Apache, IIS, etc.), and are you running as a
module or a cgi?

If you're not sure, you can find this (and a lot of other information)
with phpinfo(), i.e. a file containing only:

<?php
phpinfo();
?>

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 10 '08 #3
Jivanmukta wrote:
Hello,
I am learning PHP5. I need to obtain my website's root directory in .php
code. I tried the code:
echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
but it displays:
__DIR__/var/www/html
although my_website is installed in user's
directory: /home/robert/public_html/my_website.
I don't know why and how to obtain root directory.
Please help.
Thanks!
Do

echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
Nov 10 '08 #4
sheldonlg wrote:
Jivanmukta wrote:
>Hello,
I am learning PHP5. I need to obtain my website's root directory in .php
code. I tried the code:
echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
but it displays:
__DIR__/var/www/html
although my_website is installed in user's
directory: /home/robert/public_html/my_website.
I don't know why and how to obtain root directory.
Please help.
Thanks!

Do

echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
Scratch that. Just do:

echo $_SERVER['DOCUMENT_ROOT'];

Nov 10 '08 #5
On Nov 10, 1:04*pm, sheldonlg <sheldonlgwrote:
sheldonlg wrote:
Jivanmukta wrote:
Hello,
I am learning PHP5. I need to obtain my website's root directory in .php
code. I tried the code:
* * * * echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
but it displays:
* * * * __DIR__/var/www/html
although my_website is installed in user's
directory: /home/robert/public_html/my_website.
I don't know why and how to obtain root directory.
Please help.
Thanks!
Do
echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];

Scratch that. *Just do:

echo $_SERVER['DOCUMENT_ROOT'];
Many shared hosts pull crap like this. As soon as I can figure out how
to configure a Debian LAMP setup, all of my sites will be on my Linode
account. On these type of shared hosts, "/" can be unreliable if not
handled with care.

Thomas
Nov 10 '08 #6
703designs wrote:
On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote:
>sheldonlg wrote:
>>Jivanmukta wrote:
Hello,
I am learning PHP5. I need to obtain my website's root directory in .php
code. I tried the code:
echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
but it displays:
__DIR__/var/www/html
although my_website is installed in user's
directory: /home/robert/public_html/my_website.
I don't know why and how to obtain root directory.
Please help.
Thanks!
Do
echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
Scratch that. Just do:

echo $_SERVER['DOCUMENT_ROOT'];

Many shared hosts pull crap like this. As soon as I can figure out how
to configure a Debian LAMP setup, all of my sites will be on my Linode
account. On these type of shared hosts, "/" can be unreliable if not
handled with care.

Thomas
Thomas,

Don't install LAMP. Everything you need on Debian is available via
aptitude or apt_get. They're not necessarily the absolute latest and
greatest - but they're fairly recent and stable.

Debian already comes with MySQL installed (in fact, you want to use that
version because Debian also uses MySQL). And it will make
administration much easier.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 10 '08 #7
On Nov 10, 1:18*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
703designs wrote:
On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote:
sheldonlg wrote:
Jivanmukta wrote:
Hello,
I am learning PHP5. I need to obtain my website's root directory in ..php
code. I tried the code:
* * * * echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
but it displays:
* * * * __DIR__/var/www/html
although my_website is installed in user's
directory: /home/robert/public_html/my_website.
I don't know why and how to obtain root directory.
Please help.
Thanks!
Do
echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
Scratch that. *Just do:
echo $_SERVER['DOCUMENT_ROOT'];
Many shared hosts pull crap like this. As soon as I can figure out how
to configure a Debian LAMP setup, all of my sites will be on my Linode
account. On these type of shared hosts, "/" can be unreliable if not
handled with care.
Thomas

Thomas,

Don't install LAMP. *Everything you need on Debian is available via
aptitude or apt_get. *They're not necessarily the absolute latest and
greatest - but they're fairly recent and stable.

Debian already comes with MySQL installed (in fact, you want to use that
version because Debian also uses MySQL). *And it will make
administration much easier.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Thanks, I know how Debian works, after all (it's my favorite OS). I
actually have no trouble running LAMP itself (having used a Debian
LAMP server locally for a year), it's getting the mail services and
DNS that gives me fits. I may check out that book put out by No Starch
once they update it to Etch (it was stuck on Sarge last I checked). At
this point, they may as well update it for Lenny.

Thomas
Nov 10 '08 #8
703designs wrote:
On Nov 10, 1:18 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>703designs wrote:
>>On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote:
sheldonlg wrote:
Jivanmukta wrote:
>Hello,
>I am learning PHP5. I need to obtain my website's root directory in .php
>code. I tried the code:
> echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
>but it displays:
> __DIR__/var/www/html
>although my_website is installed in user's
>directory: /home/robert/public_html/my_website.
>I don't know why and how to obtain root directory.
>Please help.
>Thanks!
Do
echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
Scratch that. Just do:
echo $_SERVER['DOCUMENT_ROOT'];
Many shared hosts pull crap like this. As soon as I can figure out how
to configure a Debian LAMP setup, all of my sites will be on my Linode
account. On these type of shared hosts, "/" can be unreliable if not
handled with care.
Thomas
Thomas,

Don't install LAMP. Everything you need on Debian is available via
aptitude or apt_get. They're not necessarily the absolute latest and
greatest - but they're fairly recent and stable.

Debian already comes with MySQL installed (in fact, you want to use that
version because Debian also uses MySQL). And it will make
administration much easier.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Thanks, I know how Debian works, after all (it's my favorite OS). I
actually have no trouble running LAMP itself (having used a Debian
LAMP server locally for a year), it's getting the mail services and
DNS that gives me fits. I may check out that book put out by No Starch
once they update it to Etch (it was stuck on Sarge last I checked). At
this point, they may as well update it for Lenny.

Thomas
Exim does pretty with a little work. It can be hard to configure for
special circumstances, but I've found it works OK.

With that said - I've heavily customized my Exim installations for spam
filtering, aliases via MySQL database, etc. But even without that, it
worked with minimal setup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 10 '08 #9
On Nov 10, 2:52*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
703designs wrote:
On Nov 10, 1:18 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
703designs wrote:
On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote:
sheldonlg wrote:
Jivanmukta wrote:
Hello,
I am learning PHP5. I need to obtain my website's root directory in .php
code. I tried the code:
* * * * echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
but it displays:
* * * * __DIR__/var/www/html
although my_website is installed in user's
directory: /home/robert/public_html/my_website.
I don't know why and how to obtain root directory.
Please help.
Thanks!
Do
echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
Scratch that. *Just do:
echo $_SERVER['DOCUMENT_ROOT'];
Many shared hosts pull crap like this. As soon as I can figure out how
to configure a Debian LAMP setup, all of my sites will be on my Linode
account. On these type of shared hosts, "/" can be unreliable if not
handled with care.
Thomas
Thomas,
Don't install LAMP. *Everything you need on Debian is available via
aptitude or apt_get. *They're not necessarily the absolute latest and
greatest - but they're fairly recent and stable.
Debian already comes with MySQL installed (in fact, you want to use that
version because Debian also uses MySQL). *And it will make
administration much easier.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Thanks, I know how Debian works, after all (it's my favorite OS). I
actually have no trouble running LAMP itself (having used a Debian
LAMP server locally for a year), it's getting the mail services and
DNS that gives me fits. I may check out that book put out by No Starch
once they update it to Etch (it was stuck on Sarge last I checked). At
this point, they may as well update it for Lenny.
Thomas

Exim does pretty with a little work. *It can be hard to configure for
special circumstances, but I've found it works OK.

With that said - I've heavily customized my Exim installations for spam
filtering, aliases via MySQL database, etc. *But even without that, it
worked with minimal setup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Just curious, what led you to choose Exim over SendMail? Is SendMail
the CVS of mail servers?

Thanks,
Thomas
Nov 10 '08 #10
703designs wrote:
On Nov 10, 2:52 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>703designs wrote:
>>On Nov 10, 1:18 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
703designs wrote:
On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote:
>sheldonlg wrote:
>>Jivanmukta wrote:
>>>Hello,
>>>I am learning PHP5. I need to obtain my website's root directory in .php
>>>code. I tried the code:
>>> echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
>>>but it displays:
>>> __DIR__/var/www/html
>>>although my_website is installed in user's
>>>directory: /home/robert/public_html/my_website.
>>>I don't know why and how to obtain root directory.
>>>Please help.
>>>Thanks!
>>Do
>>echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
>Scratch that. Just do:
>echo $_SERVER['DOCUMENT_ROOT'];
Many shared hosts pull crap like this. As soon as I can figure out how
to configure a Debian LAMP setup, all of my sites will be on my Linode
account. On these type of shared hosts, "/" can be unreliable if not
handled with care.
Thomas
Thomas,
Don't install LAMP. Everything you need on Debian is available via
aptitude or apt_get. They're not necessarily the absolute latest and
greatest - but they're fairly recent and stable.
Debian already comes with MySQL installed (in fact, you want to use that
version because Debian also uses MySQL). And it will make
administration much easier.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Thanks, I know how Debian works, after all (it's my favorite OS). I
actually have no trouble running LAMP itself (having used a Debian
LAMP server locally for a year), it's getting the mail services and
DNS that gives me fits. I may check out that book put out by No Starch
once they update it to Etch (it was stuck on Sarge last I checked). At
this point, they may as well update it for Lenny.
Thomas
Exim does pretty with a little work. It can be hard to configure for
special circumstances, but I've found it works OK.

With that said - I've heavily customized my Exim installations for spam
filtering, aliases via MySQL database, etc. But even without that, it
worked with minimal setup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Just curious, what led you to choose Exim over SendMail? Is SendMail
the CVS of mail servers?

Thanks,
Thomas
It's much easier to configure, for one thing. SendMail is a real bear!
It's difficult even to configure it to handle all of your incoming
mail without accidentally becoming a spam relay.

Of course, so is Exim for more complicated things - but at least for the
majority of the sites it's pretty easy to configure. And the basic
configuration is done by a command line script - all you need to do is
fill in the blanks and it configures Exim for your site.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 10 '08 #11
On Nov 10, 5:23*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
703designs wrote:
On Nov 10, 2:52 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
703designs wrote:
On Nov 10, 1:18 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
703designs wrote:
On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote:
sheldonlg wrote:
>Jivanmukta wrote:
>>Hello,
>>I am learning PHP5. I need to obtain my website's root directoryin .php
>>code. I tried the code:
>>* * * * echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
>>but it displays:
>>* * * * __DIR__/var/www/html
>>although my_website is installed in user's
>>directory: /home/robert/public_html/my_website.
>>I don't know why and how to obtain root directory.
>>Please help.
>>Thanks!
>Do
>echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
Scratch that. *Just do:
echo $_SERVER['DOCUMENT_ROOT'];
Many shared hosts pull crap like this. As soon as I can figure out how
to configure a Debian LAMP setup, all of my sites will be on my Linode
account. On these type of shared hosts, "/" can be unreliable if not
handled with care.
Thomas
Thomas,
Don't install LAMP. *Everything you need on Debian is available via
aptitude or apt_get. *They're not necessarily the absolute latest and
greatest - but they're fairly recent and stable.
Debian already comes with MySQL installed (in fact, you want to use that
version because Debian also uses MySQL). *And it will make
administration much easier.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Thanks, I know how Debian works, after all (it's my favorite OS). I
actually have no trouble running LAMP itself (having used a Debian
LAMP server locally for a year), it's getting the mail services and
DNS that gives me fits. I may check out that book put out by No Starch
once they update it to Etch (it was stuck on Sarge last I checked). At
this point, they may as well update it for Lenny.
Thomas
Exim does pretty with a little work. *It can be hard to configure for
special circumstances, but I've found it works OK.
With that said - I've heavily customized my Exim installations for spam
filtering, aliases via MySQL database, etc. *But even without that, it
worked with minimal setup.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Just curious, what led you to choose Exim over SendMail? Is SendMail
the CVS of mail servers?
Thanks,
Thomas

It's much easier to configure, for one thing. *SendMail is a real bear!
* It's difficult even to configure it to handle all of your incoming
mail without accidentally becoming a spam relay.

Of course, so is Exim for more complicated things - but at least for the
majority of the sites it's pretty easy to configure. *And the basic
configuration is done by a command line script - all you need to do is
fill in the blanks and it configures Exim for your site.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Sounds like exactly what I'm looking for, as I'm not exactly building
Gmail here. SendMail was driving me up the wall.

Thanks!

Thomas
Nov 10 '08 #12

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

Similar topics

2
by: jpb | last post by:
Could someone please help me with this. I want to use PHP in my website; but run into a snag, the recommended method of calling an include is: <?php include($_SERVER."/inc/css-gateway.inc");...
2
by: yburtin | last post by:
Hi, I'm currently working on a dotnet web application and here is the problem I have: On my computer (french version of xp pro), I have my webserver installed. Inside one of my webpages, I...
10
by: Sridhar | last post by:
HI, I am having problems setting up a website so that it will be available only inside the domain. We have three servers. One is iis server and second one is internal server and the third one is...
0
by: =?Utf-8?B?bWVuc3V1cg==?= | last post by:
hi, as you are all aware, the asp.net folders like app_data have to be at the root directory or the server. well, the thing is... i dont have that directory. one has given me a subdirectory. is...
1
by: Frank Miverk | last post by:
Hi, I have a situation which I think is fairly common. 1. Public area 2. Secure area accessed via SSL e.g. MyWebsite/ /MySecureWebsite
6
by: Eric | last post by:
Hi Everyone, I have an ASP 1.1 website being hosted in a virtual directory that is a child node of an ASP 2.0 website. So I have: http://mainapp (which is a 2.0 site) And: ...
3
by: ningjun.wang | last post by:
I use Visual Studio .NET 2005 to create a website called "website1". When I start this website in Visual Studio, the URL is http://localhost:49299/website1/default.aspx How can I get rid of...
8
by: =?Utf-8?B?V2hpc2tleVJvbWVv?= | last post by:
I am trying to copy files and folders onto a production machine (Windows 2003 web edition -- we had to install the .NetFramework 2.0 on it). I wasn't even sure which files to copy for a ASP.NET...
1
by: MMAS | last post by:
I've seen a similar post about this problem but still cannot find an automated solution. Below is the code I'm using to create a website (for IIS 6.0) via C#. once the site is created, it will not...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.