Jump to content


Photo

Document Root and nesting

document root apache

Best Answer BagoZonde, 10 July 2013 - 02:23 AM

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.

Go to the full post


  • Please log in to reply
4 replies to this topic

#1 BagoZonde

BagoZonde

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 02 July 2013 - 08:42 AM

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.

 


A=1-A ...from Basic...
$a=1-$a ...thru PHP...
LDA $01 EOR #1 ...to 6502 ASM :}

Does it mean I'm going low-level?! ;]

#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,651 posts
  • LocationBonita, FL

Posted 02 July 2013 - 12:22 PM

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.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#3 BagoZonde

BagoZonde

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 03 July 2013 - 01:20 AM

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.


A=1-A ...from Basic...
$a=1-$a ...thru PHP...
LDA $01 EOR #1 ...to 6502 ASM :}

Does it mean I'm going low-level?! ;]

#4 BagoZonde

BagoZonde

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 03 July 2013 - 06:55 AM

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).


A=1-A ...from Basic...
$a=1-$a ...thru PHP...
LDA $01 EOR #1 ...to 6502 ASM :}

Does it mean I'm going low-level?! ;]

#5 BagoZonde

BagoZonde

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 10 July 2013 - 02:23 AM   Best Answer

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 by BagoZonde, 10 July 2013 - 02:24 AM.

A=1-A ...from Basic...
$a=1-$a ...thru PHP...
LDA $01 EOR #1 ...to 6502 ASM :}

Does it mean I'm going low-level?! ;]




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