BagoZonde Posted July 2, 2013 Share Posted July 2, 2013 Hello everyone, I'm making some improvements to site I haven't created so please tell me how it exactly works as I have problems to configure it properly. I've downloaded all files and run localhost using XAMPP. Site should run when accessing /home/some_domain/public_html/index.php so I've created : <VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/SomeProject/home/some_domain/public_html" ServerName some_project <Directory "C:/xampp/htdocs/SomeProject/home/some_domain/public_html"> AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> That means, when I'm accessing http://some_project it runs index.php And that's ok. In index.php there's some include: include_once("includes/startup.php"); So it includes relatively there: /home/some_domain/public_html/includes/startup.php And that's fine. However... In startup.php there's something like this: define("_ROOTPATH_","/home/some_domain/public_html/"); and next line: include_once(_ROOTPATH_ ."includes/config.php"); And that's my problem as index.php was executed from C:/xampp/htdocs/SomeProject/home/some_domain/public_html/ so that include_once will behave this way: C:/xampp/htdocs/SomeProject/home/some_domain/public_html/home/some_domain/public_html/includes/config.php Of course such file is not available as it should direct to: C:/xampp/htdocs/SomeProject/home/some_domain/public_html/includes/config.php I'm not sure how it works on server and what I should do with my localhost to achieve that same environment. $_SERVER['DOCUMENT_ROOT'] for real site is: /home/some_domain/public_html Please help me to understand what I'm doing wrong. Quote Link to comment https://forums.phpfreaks.com/topic/279788-document-root-and-nesting/ Share on other sites More sharing options...
kicken Posted July 2, 2013 Share Posted July 2, 2013 so that include_once will behave this way: C:/xampp/htdocs/SomeProject/home/some_domain/public_html/home/some_domain/public_html/includes/config.php No, it won't resolve to that location. It will resolve to: C:\home\some_domain\public_html\includes\config.php When a path begins with a /, it is treated as an absolute path so the current working directory has no influence on how it is interpreted. Of course, that is still not correct, as your path should have the xamp prefix. What you need to do is define your _ROOTPATH_ constant with the full and complete path to the document root, including the xamp prefix: define('_ROOTPATH_', 'C:/xampp/htdocs/SomeProject/home/some_domain/public_html'); The variable $_SERVER['DOCUMENT_ROOT'] should already be defined with the value you need, and will be the appropriate value for each server you are on. So something like define('_ROOTPATH_', $_SERVER['DOCUMENT_ROOT']); should work fine to define the root path as needed on both your live and development servers. Quote Link to comment https://forums.phpfreaks.com/topic/279788-document-root-and-nesting/#findComment-1439090 Share on other sites More sharing options...
BagoZonde Posted July 3, 2013 Author Share Posted July 3, 2013 Thank you for reply, kicken. I'm wonder how it works on live server (I'm not an author of this code). I can't change every place with __ROOTPATH__ (there are few of them), so how it works exactly? In other words, how to set my local server that same way as it was set on live serv? How to do it without touching anything in code? I don't get it. Quote Link to comment https://forums.phpfreaks.com/topic/279788-document-root-and-nesting/#findComment-1439199 Share on other sites More sharing options...
BagoZonde Posted July 3, 2013 Author Share Posted July 3, 2013 I was talking with some advanced coder and he told me that path solution is possible to work properly only on some *nix (I'm working on Win8). Quote Link to comment https://forums.phpfreaks.com/topic/279788-document-root-and-nesting/#findComment-1439237 Share on other sites More sharing options...
Solution BagoZonde Posted July 10, 2013 Author Solution Share Posted July 10, 2013 (edited) Well, finally I achieved my target few days ago. So, I've installed Virtual Box with Ubuntu, and I've used shared folder (/media/sf_htdocs) to share httdocs/ folder between Win8 and Ubuntu (@Virtual Box). Then I've mounted that folder with /home so I can access /home/[user]/public_html directly: sudo mount --bind /media/sf_htdocs/SomeProject/home /home so for now everything works like a charm. I can access site from the root. It was just Windows issue as that type of sites works well on *nix systems. Edited July 10, 2013 by BagoZonde Quote Link to comment https://forums.phpfreaks.com/topic/279788-document-root-and-nesting/#findComment-1440129 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.