Jump to content


Photo

Document Root setup for PHP


  • Please log in to reply
4 replies to this topic

#1 Kosta2014

Kosta2014

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 14 February 2014 - 12:25 PM

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.



#2 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,543 posts

Posted 14 February 2014 - 12:44 PM

 

 

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



#3 Kosta2014

Kosta2014

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 14 February 2014 - 01:25 PM

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

 



#4 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,543 posts

Posted 14 February 2014 - 01:35 PM

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, 14 February 2014 - 01:40 PM.


#5 Kosta2014

Kosta2014

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 14 February 2014 - 01:59 PM

Perfect. It worked. Thank you so much!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com