I'm following instructions from this url on running multiple sites on Apache2
https://www.liquidweb.com/kb/configure-apache-virtual-hosts-ubuntu-18-04/
Instructions are for 2 sites but i need to run 3 sites. I followed all steps and created three different folders for each site in my www folder and three different domain.com.conf
files in sites-available
folder. If i enable all three domains using a2ensite
then my apache2 service gives error on restart but if i enable only 2 sites then my apache service run OK and i can visit my sites in browser. Even with two sites enable i can still visit my all three sites on browser but i only see two conf files in sites-enabled
folder. Once i enable all three sites i get three conf files in sites-enabled
folder but apache service won't restart. Error i get when restarting apache2 service is as follow..
sudo systemctl status apache2
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sun 2021-02-21 04:10:28 UTC; 8s ago Docs: https://httpd.apache.org/docs/2.4/ Process: 23325 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
status says
sudo systemctl status apache2
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sun 2021-02-21 04:10:28 UTC; 1min 31s ago Docs: https://httpd.apache.org/docs/2.4/ Process: 23325 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
systemd[1]: Starting The Apache HTTP Server... apachectl[23336]: apache2: Syntax error on line 225 of /etc/apache2/apache2.conf: Syntax e> apachectl[23325]: Action 'start' failed. apachectl[23325]: The Apache error log may have more information. systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE systemd[1]: apache2.service: Failed with result 'exit-code'. systemd[1]: Failed to start The Apache HTTP Server.
even though all my three sites are running with 2 sites enabled but i still like to enable all three sites and restart apache2 service.
I'm running apache2 on ubuntu server 20.04 LTS
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
My domain1.com.conf file is as follows
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/site1
ServerName domain1.com
ServerAlias www.domain1.com
</VirtualHost>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Other three config files are same except site2, site3 and domain2, domain3.
Another thing i found is apache2 service restart error comes only when i run e2ensite
command on domain1 (site1) only. If i only have site2 and sit3 enabled then i don't get apache2 service error. This tells me that there is something wrong with site1 only.
/etc/apache2/apache2.conf
file. I would suggest looking there first to see if there’s an unnecessary semi-colon or a mid-named XML attribute.sudo service apache2 reload
(orrestart
) after using any of thea2
commands, otherwise the configuration is not reloaded.