$_SERVER['DOCUMENT_ROOT'] directs to /var/www not ~/public_html


 
Thread Tools Search this Thread
Top Forums Web Development $_SERVER['DOCUMENT_ROOT'] directs to /var/www not ~/public_html
# 1  
Old 06-20-2014
$_SERVER['DOCUMENT_ROOT'] directs to /var/www not ~/public_html

Hi all,

Exactly like my title says.
I am learning PHP and MySQL and I used to use /var/www/ to host (contain or store) my files (.htm/.php) for testing. I could configure, finally, apache2 to use ~/public_html instead.

Now I when I tried to use $_SERVER['Document_ROOT'] it still directs (I used echo to show its path) to /var/www and not the expected ~/public_html.
My question is: how to make variable ($_SERVER['Document_ROOT']) directs to ~/public_html and not the default /var/www. I found this but I did not understand it. I am totally new to servers/networks.

I use Ubuntu 12.04 on a Dell Desktop.

Thank you in advance,

~faizlo
# 2  
Old 06-20-2014
$_SERVER['DOCUMENT_ROOT'] is a PHP global variable for the entire PHP (and web server) configuration set in the the core web server config files (for example the global Apache2 conf file). You can change it there if you have root access.

Sounds like you are on a shared server? Yes? No?

Quote:
$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the » CGI/1.1 specification, so you should be able to expect those.
This User Gave Thanks to Neo For This Post:
# 3  
Old 06-21-2014
Hi Neo

The box I use is my own box at home. I am using it to learn Web Development with PHP and MySQL, so I can do anything I want with it - no problem.
That said, I could configure apache2 to use ~/public_html via commenting few lines in /etc/apache2/mods_available/php5.conf. The instructions were in the file itself.

One other thing is that my httpd.conf file (in /etc/apache2/) has nothing in it, it's empty (of size 0.)

I hope these info can help you figure out how to use ~/public_html/
# 4  
Old 06-21-2014
You can use the Apache2 DocumentRoot directive to set the document root.

Perhaps you should search on line and find a basic working example of setting up your Apache2 config files?

Most Linux distributions have easy step-by-step LAMP set up instructions. Which Linux distribution are you using?
This User Gave Thanks to Neo For This Post:
# 5  
Old 06-21-2014
I use UBUNTU 12.04 LTS on a Dell Machine (Core i5, 8GB RAM, NVIDIA Graphics.)
Where can I change this $_SERVER["DOCUMENT_ROOT"] directive?
# 6  
Old 06-21-2014
As said by Neo, you have to change DocumentRoot directive

1. Copy default configuration file safety point of view $ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mynewsite

2. Edit $ vi /etc/apache2/sites-available/mynewsite

3. Change DocumentRoot /var/www to DocumentRoot /your/new/path/to/site

4. Replace <Directory /var/www/> with <Directory /your/new/path/to/site/>

5. Deactivate old and activate new site $ sudo a2dissite default && sudo a2ensite mynewsite

6. Restart Apache $ sudo service apache2 restart
These 2 Users Gave Thanks to Akshay Hegde For This Post:
# 7  
Old 06-21-2014
Akshay_Hedge

Thank you so much. That did the trick.
Now, if I can take the chance, would you please explain me what I (we) just did?

Thanks again to all of you who replied

~faizlo
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Web Development

Botnet Map from $_SERVER[HTTP_REFERER]

4000 node Botnet derived from PHP superglobal $_SERVER mapped with Google Maps Engine. https://www.unix.com/members/1-albums112-picture640.png total ips 54945 unique ips 4000 unique countries 64 (2 Replies)
Discussion started by: Neo
2 Replies

2. Debian

Help request. FTP user to var/www/html

Hi all. I appologise this is my first post, I will gladly have a further look around to see if this has been posted elsewhere, but so far it has not, or it doesnt quite explain in full what I need. If anyone here can help me out, I would really appreciate this. I want to make sure I do this... (1 Reply)
Discussion started by: Pinkfloyd
1 Replies

3. UNIX for Dummies Questions & Answers

How to protect directory var/www in debian?

hi i need somme help to protect directory in debian with user and pass var/www thank's (6 Replies)
Discussion started by: azzeddine2005
6 Replies

4. UNIX for Dummies Questions & Answers

Granting user permission for public_html

I have problem giving user access to his public_html directory. While when I am logged as root I can access my files by going to www.myserver.com/file.htmlwhere file.html is actually on this path... var/www/file.htmlBut when user tries to access his file.html on this path.... ~user/file.html it... (10 Replies)
Discussion started by: joker40
10 Replies

5. UNIX for Dummies Questions & Answers

Permissions of the folder var/www

what should be the permissions of the folder var/www in my ubuntu ? I need it to be safe and at the same time I need ftp users to be able to edit it. I was wondering if I should create a group with all permissions and add ftp users to this group in unix. what's the standard way to do it ?... (4 Replies)
Discussion started by: aneuryzma
4 Replies

6. Web Development

var/www/html permissions

Hi, first post. I have no Linux experience. I have an e-friend that set me up a VPS and my website with Apache and FTP access so I could upload my files the way I do it regularly with my shared hosting. The OS in the VPS is Fedora by the way. Now the thing is: http ://www.mydomain.com presents... (0 Replies)
Discussion started by: JPA
0 Replies

7. UNIX for Advanced & Expert Users

resize /var/www (debian)

I have several live websites running in the /var/www/XXXX directory. Initially when I did the Debian install I limited the web directory to 6GB. I am now outgrowing that limit. Question is: Is there a simple way to add space to the web directory??? I'd hate to have to redo the whole... (3 Replies)
Discussion started by: seagonus
3 Replies

8. UNIX for Dummies Questions & Answers

chmod for public_html ?

Hello! My web host has the public_html permission on my account set to 750. 1. Does this setting permit the world to use my submission forms (contained within contact.html and purchase_order.html)? 2. The "0" entry looks like it blocks the public from conducting all activity on my site.... (6 Replies)
Discussion started by: Texan
6 Replies
Login or Register to Ask a Question