Question

Cannot change root of web site with Apache2 Virtual Hosts directive

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

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

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
    </Directory>
ServerAdmin webmaster@example_site.org
ServerName example_site.org
ServerAlias www.example_site.org
DocumentRoot /var/www/example_site/docroot
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =example_site.org [OR]
RewriteCond %{SERVER_NAME} =www.example_site.org
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

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


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

alexdo
Site Moderator
Site Moderator badge
December 25, 2019
Accepted 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.

Regards, Alex

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.