How to get apache virtual hosts working

I have tried following every tutorial I can find and I can’t seem to get the WordPress one click setup to serve files from a different directory besides the default /var/www/html.

I have used a2dissite, a2ensite, reloaded, restarted apache. The properties in the config file ServerName, etc.

One interesting detail is that when I ran a2dissite 000-default.conf came back with an error to the effect that the corresponding file in sites-enabled was not symlinked. Which is weird since creating new .conf files in sites-available does seem to symlink them into sites-enabled. I have setup these files on other droplets and had no problems. Is this something unique to this pre configured droplet?

I scrapped my first droplet - I had deleted all the original default .conf files in frustration and apache was, in my opinion, still using one of them. It was looking for a directory that I had deleted, which though an error, but that directory was not pointed to in any of the configurations that were supposed to be active.

This is my /etc/apache2/sites-available/mydomain.conf file.

<VirtualHost *:80>
    ServerAdmin ben@mydomain
    DocumentRoot /var/www/html.old
    ServerName mydomain
    ServerAlias www.mydomain
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /var/www/html.old/>
        Options FollowSymLinks
        AllowOverride All
        Require all granted

The only way I found to serve something else is to change the contents of /var/www/html. This is not ideal, since my next move is to get multiple sites running with subdomains. As of right now I am getting by but starting to get frustrated with the learning curve.

Any help would be greatly appreciated. Thanks.

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


What I could suggest is the following:

  • First run an Apache config test to make sure that there are no problems with your configuration:
apachectl -t
  • Share the output of the following command here:
ls -l /etc/apache2/sites-enabled
  • Access your site and right after that check your Apache error log:
tail -100 /var/log/apache2/error.log
  • Make sure that your Apache user has permissions to read and write to the /var/www/html.old folder:
chown -R www-data:www-data /var/www/html.old

Let me know how it goes! Regards, Bobby