Cannot change root of web site with Apache2 Virtual Hosts directive

Posted December 23, 2019 2k views
ApachePHPDrupalUbuntu 18.04

I need to have this site’s root be /var/www/examplesite/docroot/
Running SSL with a Let’s Encrypt certificate, and heavy .htaccess file in /var/www/example

Whenever I run phpinfo() it tells me that the DOCUMENTROOT still remains /var/www/examplesite

Here is the apache2 Virtual Hosts conf directive, which I took care of enabling with a2ensite and have restarted apache2 numerous times. The default 000 conf file was disabled.

<VirtualHost *:443 *:80>
    <Directory /var/www/example_site/docroot>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
DocumentRoot /var/www/example_site/docroot
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} [OR]
RewriteCond %{SERVER_NAME}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

Also, does a ‘Virtual Host’ directive need to have both port 443 and 80 specified, or would *:80 be enough?

edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hello, @journeyintosound

Have you restarted Apache once you’ve made the changes to the Virtual Hosts? Also before doing this you can check for any syntax errors in the configuration file using the following command:

httpd -t

If you have SSL Certificate installed and you want to have your site available in the browser via https you will need a virtual host for port 443 as well. I’m not sure how was the certificate installed, but if you use certbot to install LE for example it will automatically add the virtual host for port 443 and will ask if you to set the needed http –> https redirections on your behalf as well.


  • Hello Alex, thanks for your reply. I must have only restarted Apache2 about 37 times....LOL. Honestly it got too messy with my not being able to retrace my steps after editing many different .conf files, because I didn’t keep a detailed set of notes (mistake #1) and also didn’t take time to save some snapshots of my droplet. (mistake #2 - lesson learned)

    (For the benefit of anyone reading with similar issues) not really sure if it was a VirtualHosts directive problem, something to do with apache2.conf, some arcane .htaccess settings or whatever else but I decided to re-install from scratch, took the time to redo it all but very carefully and this time I am keeping extremely detailed notes on any modifications, and saving droplet images at every step of the way.

    As far as the VirtualHosts I guess (as you were saying) certbot inserted some mod_rewrite conditions which let me keep the port as *:80 but it automatically redirects to https, seems to be running smooth. Not sure if this is a bit more taxing on the processor cycles rather than having the *:443 directive explicitly added on its own, I assume it’s probably trivial unless I had a high-traffic site with thousands of users.

    The only thing I did differently is that since I knew my base URL was going to be /var/www/my-site-name/docroot, I set this as the DocumentRoot before my install through Composer, whereas on my first attempt I initially had it set one folder higher up, the problem started happening when I couldn’t get it to change to the subfolder of where it needed to be no matter what I tried.

    Anyway, quite happy to report that everything is now working great, got a full Composer/Lightning (drupal8) development site running with FQDN, SSL as well as clean URLs with all the trimmings, and not a thing to complain about except for the fact that I wasted two days, but I guess it’s all part of the learning experience?

    Merry Xmas.