Kosta2014 Posted February 14, 2014 Share Posted February 14, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/286204-document-root-setup-for-php/ Share on other sites More sharing options...
Ch0cu3r Posted February 14, 2014 Share Posted February 14, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/286204-document-root-setup-for-php/#findComment-1468936 Share on other sites More sharing options...
Kosta2014 Posted February 14, 2014 Author Share Posted February 14, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/286204-document-root-setup-for-php/#findComment-1468947 Share on other sites More sharing options...
Ch0cu3r Posted February 14, 2014 Share Posted February 14, 2014 (edited) 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 February 14, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/286204-document-root-setup-for-php/#findComment-1468948 Share on other sites More sharing options...
Kosta2014 Posted February 14, 2014 Author Share Posted February 14, 2014 Perfect. It worked. Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/286204-document-root-setup-for-php/#findComment-1468952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.