Troubleshooting (Apache)

From vwiki
Revision as of 06:53, 28 August 2012 by Sstrutt (talk | contribs) (Added "Permission denied - unable to check htaccess file")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

NameVirtualHost *:80 has no VirtualHosts

On restarting Apache you get presented with the following warning

[Thu Jan 12 10:58:20 2012] [warn] NameVirtualHost *:80 has no VirtualHosts

This is generally caused by duplicate NameVirtualHost entries in your config.

Perform the following in /etc/apache2 folder to identify where the entries and delete the unwanted duplicates..

grep NameVir * -R

Address Already In Use

On restarting Apache you get presented with the following error

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
                                                                     [fail]

Apache is attempting to start but cannot bind (start listening on) TCP port 80 (or 443 if you're using SSL and the error refers to 0.0.0.0:443, or another port if you're using non-standard ports.

The reason for the problem can vary, and you need ascertain what's already using the port by running netstat and grep'ing for port 80 (or whatever port Apache won't start on).

root@web2:/etc/apache2# netstat -lnp | grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      20482/apache2
  • If Apache is already listening on the port (as shown in above example, running with PID 20482)
    • There is either a problem with the Apache config, and its trying to listen on the port twice, or you've got an old rogue process knocking around.
    1. Kill the process using the process ID
      • EG kill 20482
    2. Restart Apache, if it starts OK - problem solved!, otherwise continue
      • service apache2 restart
    3. Check your config for multiple servers on the port
      • EG grep -r 80 /etc/apache2/conf.d/* /etc/apache2/*.conf /etc/apache2/sites-enabled/*
      • Multiple <VirtualHost *:80> are OK, multiple Listen 80 or NameVirtualHost *:80 are not, fix as required
  • If its another process you need to track down the cause and resolve.
    • If you haven't accidentally caused the problem, your server may have been breached.
    1. Kill the process by name (dodgy.pl in example below, in-case there's more than one running)
      • EG killall -9 dodgy.pl
    2. From root, find the file and delete
      • EG cd /
      • EG find -iname dodgy.pl
      • EG rm -f /path/to/dodgy.pl

Permission denied - unable to check htaccess file

Files within certain directories cannot be found when viewing via a web browser, and the Apache error logs have entries like...

  • [Fri Jul 20 07:40:55 2012] [crit] [client 123.234.12.123] (13)Permission denied: /var/www/folder/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable

...you needn't be using an htaccess file to get the above error!

Caused by incorrect permissions on the affected folder(s), to fix ensure that the web server has execute rights over the folder. So, assuming your web server user (www-data) has group rights over your site use to give execute rights to the group...

  • chmod g+x <folder>

Source: http://www.liamdelahunty.com/tips/apache_pcfg_openfile_unable_to_check_htaccess.php