0

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.

6
  • From the error logs you shared, the problem is a syntax error on line 225 of your /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.
    – user1091774
    Feb 21 at 5:00
  • I never edited apache2.conf file. It is same as original. apache2.conf line 225 is IncludeOptional sites-enabled/*.conf
    – smaqsood
    Feb 21 at 5:03
  • Then the syntax issue is in the config file for that third site. Without seeing how you’ve configured things, all we can do is guess.
    – user1091774
    Feb 21 at 5:15
  • I just tested few more things. I used a2dissite command for all my three sites indlucing 000-default site. Currently i don't have any conf file in my sites-enabled folder. All my three sites are running fine in browser. Can anyone explain this?
    – smaqsood
    Feb 21 at 5:16
  • It would be better to update your question with additional info rather than posting updates in the comments. It’s also important to remember to sudo service apache2 reload (or restart) after using any of the a2 commands, otherwise the configuration is not reloaded.
    – user1091774
    Feb 21 at 5:21
0

My mistake. I had additional </VirtualHost> tag by mistake in my domain1.com.conf file. You suppose to have it twice like open and close tag but in my file i had this tag again in the middle and i didn't pay attention to it, maybe it got too late working on this last night. Fix the file and all three sites are working fine. Apache2 service is also restarting without any errors. Your original 000-default-conf should look like this

<VirtualHost *:80>
        
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/site1
        ServerName domain1.com
        ServerAlias www.domain1.com

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

</VirtualHost>

Run a2ensite <domain name> on all your sites. Restart apache2 service by running sudo systemctl restart apache2. Check sites-enabled folder and it should show your conf file pointers. Make sure you got your multiple sites placed in their respective folders in /var/www folder prior to this.

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.