0

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.

1 Answer 1

0

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"; ?>

3
  • Gives back the error of Warning: include(/_INCLUDES/Header.php): failed to open stream: No such file or directory in /var/www/html/Support is again thinking that the root is /Support, but the ServerRoot in the VHost file was explicitly put as /var/www
    – Lachlan
    Jul 12, 2016 at 12:24
  • My bad, this var doesn't seem to be available in the $_SERVER array. Have you tried to simply change the include to $_SERVER["DOCUMENT_ROOT"]."../../_INCLUDES/Header.php"; ?>
    – Doezer
    Jul 12, 2016 at 12:37
  • Bam. Legend. That works if you browse through the subdomain, but not if you go to cruisetouch.com/Support - I'll probably just add a redirect :)
    – Lachlan
    Jul 12, 2016 at 13:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .