I have Apache installed on an Ubuntu virtual machine.

Typing http://localhost in the browser brings up the Apache intro site, so I know Apache works.

I created the file /home/test/webs/testapp/index.html:

This is a <b>test</b>.

I created the file /etc/apache2/sites-available/testapp.conf:

<VirtualHost *:80>
 ServerAdmin webmaster@localhost
 ServerName testapp
 ServerAlias testapp
 DocumentRoot /home/test/webs/testapp
<Directory /home/test/webs/testapp>
 Options -Indexes +FollowSymLinks
 AllowOverride All
 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined

I enabled the virtual host:

sudo a2ensite testapp.conf

I restarted the Apache server:

systemctl reload apache2

But when I go to http://localhost/testapp, Apache responds:

Not Found

The requested URL was not found on this server. Apache/2.4.41 (Ubuntu)

Server at localhost Port 80

What else do I have to do to get my virtual host to work on Ubuntu?


In your config file you have:

ServerName testapp

But in your URL you are using:


You will need your DNS server to map testapp to the IP address of your server. Or, edit your /etc/hosts file, adding a line such as:  testapp

Replace with your server's IP address if you are trying to reach it from a different machine.

Then, you can access the host using the url http://testapp

If you want to access the site using http://localhost/testapp, you don't need to do any of this. Instead, you can just use the default virtualhost.

  • I added testapp to my /etc/hosts file, and now when I go to http://testapp (or http://testapp/index.html), it tells me "Forbidden: You don't have permission to access this resource." Where do I provide this permission for the anonymous web user? Sep 11 '20 at 14:36
  • Also, @Bert what do you mean exactly by "use the default virtualhost". When I look for a default virtual host file in /etc/apache2/sites-available, I see only two files: (1) 000-default.conf which I understand is merely a template to make other .conf files, hence the 000-, and (2) default-ssl.conf which I understand is only for secure connections and so not relevant in my case. Sep 11 '20 at 14:44
  • Put your web documents in the DocumentRoot in 000-default.conf, it's a working configuration.
    – Bert
    Sep 11 '20 at 14:49
  • Yes, I know I can put my web documents under /var/www/html/testapp and they will be available at http://localhost/testapp but I am trying to set up virtual hosts so that I have can have e.g. numerous users who each have a public_html directory under their home directory which will be accessible via a separate virtual host, e.g. /home/user1/public_html available at and /home/user2/public_html available at, etc. Your etc/hosts tipped helped, but how do I give the web user permission, see above. Sep 11 '20 at 14:56
  • 1
    Then you should look into mod_userdir, and create a new question if you can't get it working.
    – Bert
    Sep 11 '20 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.