Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to set up virtual hosts in Centos7. I followed this guide:

http://twohlix.com/2011/05/setting-up-apache-virtual-hosts-on-centos/

however I keep getting the following error:

Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' `for details.`

the relevant output from journalctrl is as follows:

-- Unit httpd.service has begun starting up.
Aug 17 14:21:54 [8235]: AH00548: NameVirtualHost has no effect and will be removed in the next release
Aug 17 14:21:54 [1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Aug 17 14:21:54 [1]: Failed to start The Apache HTTP Server.
-- Subject: Unit httpd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

I cannot figure out what this can be. I have also tried to use a different method whereby the VirtualHost container is inside the httpd.conf file but still no luck. I am using the following configuration.

Server version: Apache/2.4.6 (CentOS)
Server built:   Jul 23 2014 14:48:00

I have not configured DNS etc could this have an impact on it? This is the only other thing I could think of. Any help would be much appreciated I have spent the last couple of days trying to figure out what this could be but everything I tried failed.

share|improve this question
    
Have a look in /var/log/httpd/error_log. –  garethTheRed Aug 17 at 15:13
    
Note that the config file has changed in v2.4. The document you referred to was for CentOS 6, which used apache v2.2. –  garethTheRed Aug 17 at 15:14
    
@garethTheRed thanks but all I can find is for centos6 or equivalent. can you please suggest an updated guide and/or would know how to do it in centos7? thanks –  John S Aug 17 at 15:19
    
no errors in Apache's log –  John S Aug 17 at 15:20

2 Answers 2

up vote 0 down vote accepted

It's quite a minimal config for a basic virtual host. Create a new config file in /etc/httpd/conf.d/ and name it (for example) after your domain. It has to end in .conf though:

# nano /etc/httpd/conf.d/example.net.conf

<VirtualHost example.net:80>
    DocumentRoot /var/www/example.net/
</VirtualHost>

Make sure there's viewable content in /var/www/example.net

Reload your webserver:

# systemctl reload httpd

Make sure you have example.net resolvable to your host's IP from the client and test. Any errors should be in /var/log/httpd/error_log.

share|improve this answer
1  
Hi thanks for the help but it still not working plus I do not get anything in the error log the only thing I get is Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details. –  John S Aug 17 at 15:36
    
All solved now thanks for the help! I am not sure exactly what it was but it works! I will finish the work I'm doing now and hopefully I'll include a comprehensive guide on how to do thins in Cento7 shortly. Cheers again Gareth! –  John S Aug 17 at 15:59

Take also into account that the default SELinux configuration will prevent your virtual hosts directories from being accessed by httpd. You will need to set the appropriate context for them:

# chcon -R -u system_u -r object_r -t httpd_sys_content_t <DocumentRoot>

The other option is to disable SELinux.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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