including files from /var/www in apache virtualhost subdomain

Posted on

including files from /var/www in apache virtualhost subdomain – Problems with loading a website are often blamed on the Internet connection, but even the most perfectly set up network cannot help if there is no service to reply at your destination. One of the most popular HTTP servers used for this task is Apache2. Much of Apache’s popularity can be attributed to its easy installation and use, but never the less it is possible to run into problems with even the easiest of the software. If you’ve encountered an issue loading your web page, follow these simple troubleshooting methods outlined in this guide to attempt to get your web server back up and working again. Below are some tips in manage your apache2 server when you find problem about apache-2.2, php, virtualhost, , .

I’ve been having this problem for a while and still can’t come up with a proper solution – I want to include files from directories within /var/www from my Apache server. This isn’t a problem whenever I’m including anything from any of the directories within /var/www but my subdomain (also coming from a directory in /var/www) isn’t behaving well.

Here’s the virtualhost config

<VirtualHost *:80>
ServerName support.cruisetouch.com
ServerAlias cruisetouch.com/Support
ServerRoot /var/www/

DocumentRoot /var/www/html/Support

<Directory /var/www/html/Support>
    Options -Indexes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
</Directory>

I usually include files with PHP like so:

include $_SERVER["DOCUMENT_ROOT"]."/_INCLUDES/Header.php"; ?>

and they would be pulled from the /var/www/_INCLUDES directory, but whenever I use this line of code in /var/www/Support (the subdomain directory) it thinks that I’m looking within THAT directory.

How can I include files from /var/www without it treating /var/www/Support as the document root? Linking directly to the files isn’t an option either.

Any support is greatly appreciated.

Running Apache on Ubuntu.

I would guess that it would behave better if you used SERVER_ROOT instead of DOCUMENT_ROOT in your PHP include.

Edit for right answer from comments : My bad, this var doesn’t seem to be available in the $_SERVER array. Try to simply change the include to $_SERVER[“DOCUMENT_ROOT”].”../../_INCLUDES/Header.php”; ?>

Leave a Reply

Your email address will not be published. Required fields are marked *