-1

I setup virtualhost file in /etc/httpd/conf.d/vhost.com.conf like the example and check my file and addresses many times

<VirtualHost *:80>
  ServerName www.vhost.com
  ServerAlias vhost.com
  DocumentRoot /var/www/html/vhost.com/public_html/
  ErrorLog /var/www/html/vhost.com/logs/error.log
  CustomLog /var/www/html/vhost.com/logs/access.log combined
</VirtualHost>

but my Apache doesn't start it show the following error:

[seconduser@VPS- ~]$ sudo systemctl status httpd.service -l
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2016-07-03 11:44:58 IRDT; 54s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 7214 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 7212 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 7212 (code=exited, status=1/FAILURE)

Jul 03 11:44:58 VPS- systemd[1]: Starting The Apache HTTP Server...
Jul 03 11:44:58 VPS- httpd[7212]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::250:56ff:fea3:6805. Set the 'ServerName' directive globally to suppress this message
Jul 03 11:44:58 VPS- systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jul 03 11:44:58 VPS- kill[7214]: kill: cannot find process ""
Jul 03 11:44:58 VPS- systemd[1]: httpd.service: control process exited, code=exited status=1
Jul 03 11:44:58 VPS- systemd[1]: Failed to start The Apache HTTP Server.
Jul 03 11:44:58 VPS- systemd[1]: Unit httpd.service entered failed state.
Jul 03 11:44:58 VPS- systemd[1]: httpd.service failed.

as soon as i remove the vhost.com.conf everything go back to normal and server run again in another configure i add this code to my vhost.com.conf :

<VirtualHost *:80>
  ServerName www.vhost.com
  ServerAlias vhost.com
  DocumentRoot /var/www/vhost.com/public_html/
  ErrorLog /var/www/vhost.com/logs/error.log
  CustomLog /var/www/vhost.com/logs/access.log combined
</VirtualHost>

and send this command sudo chmod -R 755 /var/www and this sudo chown -R apache:apache /var/www/html/www.vhost.com I don't know what do they I just saw them on internet.

EDIT- I checked my error log /var/log/httpd/error_log and get this error : (13)Permission denied: AH00091: httpd: could not open error log file /var/www/vhost.com/logs/error.log. AH00015: Unable to open logs what can I do?

I do all of these because I need to seprate my subdomain.

saeed Am
  • 11
  • 1
  • 2
  • 4
  • Check the apache error log for hints why it fails if `apachectl configtest` doesn't show you any syntax errors in your config. In addition the `/var/www/vhost.com/logs` directory needs to exist and be writeable to Apache. – HBruijn Jul 03 '16 at 07:38
  • @HBruijn, should I make it writeable manually? its under my /var/www it isn't writeable by default? – saeed Am Jul 03 '16 at 07:43
  • Check the error log first. And no even with insecure permissions made with `chmod 777` apache can't write there if the wrong selinux context was set – HBruijn Jul 03 '16 at 07:56

3 Answers3

3

You likely have not enabled the NameVirtualHost *:80 line in conf/httpd.conf

You may also like to add a line for port 443 too if you're using that.

The following commands are your friends:

apachectl configtest
httpd -S
ls -ltr /var/log/httpd

The last command will show the log directory sorted by modification time; most recent last. Useful when you don't know which file to expect to find information.

Cameron Kerr
  • 4,069
  • 19
  • 25
  • [NameVirtualHost is deprecated in Apache 2.4 and currently has no effect](http://httpd.apache.org/docs/2.4/mod/core.html#namevirtualhost), but nice tip for finding information! – Colt Jul 03 '16 at 13:44
  • @Colt Thanks for the update. Yet to really touch 2.4 – Cameron Kerr Jul 04 '16 at 03:52
1

This

Jul 03 11:44:58 VPS- httpd[7212]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::250:56ff:fea3:6805. Set the 'ServerName' directive globally to suppress this message

indicates that you didn't setup ServerName in /etc/httd/http.conf. Uncomment line Servername and set it to ServerName localhost or fqdn of your server.

A K
  • 111
  • 4
1

You applied the very insecure sudo chmod -R 755 /var/www permissions to your desired log directory and still get the following permissions denied error:

(13)Permission denied: AH00091: httpd: could not open error log file /var/www/vhost.com/logs/error.log.
AH00015: Unable to open logs

This is most likely caused because SELinux denies access. The Red Hat 7 manual offers a pretty decent step by step guide to determining if SELinux was indeed the cause and how to resolve SELinux AVC denials: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/chap-Security-Enhanced_Linux-Troubleshooting.html

In short you probably need to run something along the lines of:

sudo chcon -t httpd_log_t /var/www/vhost.com/logs /var/www/vhost.com/logs/*

to label the log directory as an apache target for logs.

HBruijn
  • 77,029
  • 24
  • 135
  • 201