Link to home
Start Free TrialLog in
Avatar of Marthaj
MarthajFlag for United States of America

asked on

Apache2 Adding virtual hosts not working

I have created a project in /var/www  called sayers.com

This is the path of sayers index.html:

/var/www/sayers/html/index.html
        

Open in new window

In the in the /etc/apache2/sites-available, I created this file:

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

Open in new window

And in the /ect/apache2/sites-available. I created this file:

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

Open in new window

Then I rebooted my server. 

It displays the Ubuntu 20.4/Apache2 ItWorks page  just fine using: localhost 

It displays my phpinfo.php just fine using: http://localhost/phpinfo.php

My /etc/host contains:


127.0.0.1       localhost

127.0.1.1       MjsServer5

127.0.0.1       sayers.com

# The following lines are desirable for IPv6 capable hosts

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Open in new window

I executed an apache2 config test and received this:


$ apachectl configtest
AH00112: Warning: DocumentRoot [/var/www/sayers.com/html] does not exist
Syntax OK

Open in new window

So that tells me why but how do I fix this ?? 

Avatar of kenfcamp
kenfcamp
Flag of United States of America image

does the directory path "/var/www/sayers.com/html/" exist?
Did you create the directory "/var/www/sayers.com/html" ?  Creating the 'virtual host' does not automatically do that.
Avatar of Marthaj

ASKER

David - Hello again - it's been a long time. 
You helped a great deal before when i worked on Ubuntu 18 but I can not find my notes from then - I believe it was along the same problem... sigh
Oops - it is /var/www/sayers/html. 
I changed my conf files in both sites-available and sites enabled to reflect the proper location, rebooted and still no go.
Issued sudo apache2 configtest and it returned this:

sudo apache2ctl configtest
Syntax OK

Open in new window

But when I enter this in my browser window:  http://localhost/sayers.com

Not Found

The requested URL was not found on this server.


Apache/2.4.41 (Ubuntu) Server at localhost Port 80

Avatar of Marthaj

ASKER

So I tried this after doing the above in previous comment:

sudo a2ensite sayers.com
ERROR: Site sayers.com not properly enabled: /etc/apache2/sites-enabled/sayers.com.conf is a real file, not touching it

Open in new window

I checked to see what file apache2 was using and this:
 -D SERVER_CONFIG_FILE="apache2.conf"


Open in new window


Could this be the reason it acknowledge my web site ??

Avatar of Marthaj

ASKER

I decided to create another web site - and same thing (but I made sure I had the directory name right)
I did a apache2 config test and it return syntax ok

I tried firefox instead of chrome - with same results:

Not Found

The requested URL was not found on this server.

Apache/2.4.41 (Ubuntu) Server at localhost Port 80

I use localhost/testproject.com
I used 127.0.0.1/testproject.com
samething.




did you chown the website folder and also change the permissions of the website folders?

cd youWebSiteFolder/
Recursively change group permissions of the folders and sub-folders to enable write permissions:
find . -type d -exec chmod -R 775 {} \;
Recursively change group permissions of the files and sub-files to enable write permissions:
find . -type f -exec chmod -R 664 {} \;
Avatar of Marthaj

ASKER

David Johnson - Yep. Same results.

get a list of virtual host
you ran a config test relying on the include in httpd.conf to load the file?


ls -l /etc/apache2/sites-enabled
what do you see there?
is this site's file the only real file, while the others are links?

do you manage the server using cpanel, whm, etc. and this one you manually added?

Run
httpd -D SERVER_CONFIG_FILE="apache2.conf"  -D DUMP_VHOSTS

Is the host of interest listed?
Avatar of Marthaj

ASKER

Arnold - no, i do not use cpanel.
I completely remove sayers folders, config files etc and created a new one called 'testproject'.
I don't understand "you ran a config test relying on the include in httpd.conf to load the file?'
Same thing. I tried this and got this:

 httpd -D SERVER_CONFIG_FILE="apache2.conf"  -D DUMP_VHOSTS

Command 'httpd' not found, did you mean:


Open in new window


This is what ls -l /etc/apache2/sites-enabled show:

marthaj@MjsServer:~$ ls -l /etc/apache2/sites-enabled
total 8
-rw-r--r-- 1 root root 1767 Aug  8 00:11 000-default.conf
-rw-r--r-- 1 root root  268 Aug  7 22:25 testproject.com.conf


Open in new window


Maybe not entering the correct syntax in browser window ?? This is confusing.
This is what my 000-default.conf contains:

<VirtualHost *:80>


   ServerAdmin webmaster@localhost
   DocumentRoot /var/www/html

   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined


</VirtualHost>



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

Open in new window

I know I can multiple virtual websites defined and it then becomes a matter of using the correct website name in browser window. I had something like this about 2 years ago that allowed me switch from one website to another but I think the 000-default,config also contained reference to symlink links. I say this because when I do this:

sudo a2ensite testproject.com
[sudo] password for marthaj: 
ERROR: Site testproject.com not properly enabled: /etc/apache2/sites-enabled/testproject.com.conf is a real file, not touching it


Open in new window


Httpd is likely nonot in your path. The parameter is supposed to list the virtual hosts records.

Could you post the apache2.conf as well?

To work by adding. Conf files to the directory sites..  the bottom of apache2.conf needs to have an include *.conf

If you add an entry  in the 000 file, does the site work?
ASKER CERTIFIED SOLUTION
Avatar of Marthaj
Marthaj
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marthaj

ASKER

I appreciated everyone's suggestions and help. Thank you all. It's been quite awhile since I have worked with Ubuntu and I honestly don't know what I did to make it work.