Jump to content

How can I alias the virtual host document root to / ?


mesh2005

Recommended Posts

I setup a virtual host as follows:

<VirtualHost 192.168.1.1>
        ServerAdmin webmaster@localhost
        ServerName frame
        DocumentRoot /home/username/Personal/framework
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /home/username/Personal/framework>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        ErrorLog /var/log/apache2/error.log
        LogLevel warn
        CustomLog /var/log/apache2/access.log combined
        ServerSignature On
</VirtualHost>

 

I put a header.php in the /home/username/Personal/framework; I created a subdirectory called test and I put a script index.php inside test that has the following code:

include "/header.php";

 

It fails and I get no such file or directory although the header.php is in the root of the virtual host. It seems that the / is not mapped to /home/username/Personal/framework, how can I fix this?

Thank you

AM

Link to comment
Share on other sites

PHP does not request for files over the http protocol. Instead it does it via the OS

 

You should never begin file paths with a /. Starting file paths in this way tells PHP to look for files from the root of the hard drive. Rather than your sites document root. I recommend you to use

include "./header.php";

or a better way would be

include $_SERVER['DOCUMENR_ROOT'] . "/header.php";

Link to comment
Share on other sites

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.