How to Setup Standalone Apache Server with Name-Based Virtual Hosting with SSL Certificate – Part 4

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Gabriel Cánepa

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

17 Responses

  1. santhosh says:

    Hi All,

    I have question here, can we use the name based Virtual hosts for two different sites with two different SSL certificate in the same Apache server ?

    • Ravi Saive says:


      Yes, you can setup name based virtual hosting on two different websites with different SSL for each…

  2. Michael Heyns says:

    Hi Gabriel and Tecmint team,

    First of all, thank you very much for all your work, I am really grateful for all your effort.

    I’ve been using Apache for years and I have always chown’ed the entire DocumentRoot to the web server user and group. I did some more reading before asking why you don’t do it and for anybody else interested:
    Your web server user should only have the minimum needed authority to function. Allowing it to modify the DocumentRoot will allow any ‘hacker’ to wreak havoc on the compromised system.

    I am practicing the tutorials on CentOS7 virtual machines and I ran into a confusing snag… Apache service would not (re)start with the log files specified for virtual hosts. error_log showed “could not open log file. Unable to open logs”. Turns out SELinux prevents Apache writing logs so I had to do the following:

    # ls -lZ /var/log/httpd/error_log
    This shows the security context required. I then applied it to the individual log files with:

    # chcon system_u:object_r:httpd_log_t:s0 /var/www/html/xxxxxx/error.log

    Is this appropriate? It’s very tedious and there must be a better way.

    • @Michael,
      I know this answer comes pretty late but I am now revising the series and noticing several comments I had not seen before. By default, Apache will not be allowed to write logs outside the default /var/log/httpd directory, as you have observed. Personally, I like keeping logs for virtual hosts separated from the main server, and located in the DocumentRoot for accessibility. In that case, you’re right in that the security context of the log file needs to be updated or SELinux needs to be disabled. You have the choice to do either thing on the exam.

  3. Daniel Voyce says:

    For the LFCE do you know if they specifically specify an Apache server needs to be setup or do they just say webserver? I mostly use NGINX and would rather stick to this than re-learn all the Apache mess.

  4. birdman says:

    by the way, the NameVirtualHost directive is not required any more since 2.4 , see

    NameVirtualHost directive
    No longer needed and is now deprecated

  5. ankurkeelu says:


    Hey thanks, It really helped me.Can you please tell me about the apache modules and error log

  6. mayur says:

    Its not working for me. i have two folders containing .php pages on centos6 . i want to access it by name means i want to configured httpd as name-based vhosting in my workplace.I tried to do everything which is explained here but didnt succeeds.I am able to access site through ip .its only shows the content of index.php page.please guide me

    • @mayur,
      Where have you placed those two folders? Please provide absolute path.
      Have you set up domain name resolution using either a DNS server or the /etc/hosts file in the client machine (meaning the computer you’re using to access the site)?

      • mayur says:

        I want to setup it for internal use (workplace)only.i dont have dns . path of two folder is /var/www/html/foldername/ & exactly gave d same path in httpd.conf.i want to acces it from windows system. And how to setup DNS for local sites.?

        • mayur says:

          what should be inside this file /etc/httpd/conf.d/ can i use other extension instead .com like .local?

          • @mayur,
            Yes, you can. Inside that file you will include specific configuration for that virtual host. I wrote this article using a CentOS 7 box but it should not be all that different.
            If you want to access from a Windows system you should point your browser to the IP of the CentOS server. If it doesn’t work try disabling the firewall for a minute (iptables -F) and see if it works. I’m inclined to think that it’s a firewall issue.

  7. vlad says:

    Hi Gabriel,

    There is a missing link between the first part that contains the list of all 12 tutorials and this one.
    This article would be easier to find if there was a link from the first one.


Leave a Reply to Ravi Saive Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.