Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/279788-document-root-and-nesting/
Share on other sites

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.

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.

  • Solution

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