Jump to content

Document Root setup for PHP


Kosta2014

Recommended Posts

I have PHP installed on my Ubuntu server with Apache 2. Document root for Apache is set in apache2.conf to be /var/www which is the standard. This is a dedicated server and no virtual servers are installed. HTML files recognize Document Root and wherever I put a file, it will know that /some/directory/file is starting from /var/www. This is not the case with PHP. I always have to provide exact path starting from the directory where the actual file is located. This works, but then I cannot really have good include files because the parsed root address will be different every time depending on the location of the file. 

 

I have found locations of php.ini files and also apache configuration files. Since I am very much a beginner in setting up server, php and apache, I need some very basic help here. Thanks a lot guys.

Link to comment
Share on other sites

 

 

is is not the case with PHP. I always have to provide exact path starting from the directory where the actual file is located. 

What do you mean by this?

 

if you installed Apache and PHP from Ubuntu's package manager then everything should be setup and ready to go. No extra config on Apache/PHP's part is necessary. The only thing you may need to do is add your ubuntu username to the www-data group so you can add/edit/remove files from /var/www

Link to comment
Share on other sites

What I mean is this:

If I have this line in HTML file:

<img src="/Images/headerback.jpg" width="2" height="50" alt=""/>

server understand that /Images/headerback.jpg starts from /var/www

 

If I have this line in PHP file:

<?php include('/Includes/header.php'); ?>

PHP does not understands that it should start from /var/www. Instead this will work only if the file is in root directory, assuming that "Includes" are just under root directory:

<?php include('Includes/header.php'); ?>

 

Can I change settings of PHP so that it understands that root directory is always /var/www

 

Link to comment
Share on other sites

The is because the / at the beginning of a path has a different meanings in PHP and HTML.

 

In HTML it means the root of the url.

 

Whereas with PHP it means the root of the file path (think of it as C:/ for windows). If you want to include a file from the document root. Then use

include $_SERVER['DOCUMENT_ROOT'] . '/includes/header.php'; 
Edited by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.