?

Log in

No account? Create an account

Previous Entry | Next Entry

Gentoo and Apache2

Just posting here about a problem I was having with Apache2 under Gentoo that no-one had any real answer to. Actually, there was one guy, but he didn't post the answer, just that he'd found it.

Solution at the bottom for those who tl;dr

PROBLEM
Emerged Apache onto a fairly fresh installation of Gentoo. Tried to run it from the get-go:
#> /etc/init.d/apache2 start
 * Starting apache2 ...
apache2: apr_sockaddr_info_get() failed for GoldGentoo
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
 * start-stop-daemon: failed to start `/usr/sbin/apache2'
#>


Hmmm, okay. Not especially useful. Try running Apache directly, then; see where that would get us.
#> /usr/sbin/apache2
no listening sockets available, shutting down
Unable to open logs

#>

All the forums said that something was probably already using, and thus blocking, port 80. Fine, let's see if anything's already listening on port 80
#> lsof -i :80
COMMAND    PID      USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
#>

Well, quite. Google searches suggest that there are multiple "Listen 80" commands in /etc/apache2/httpd.conf and/or the /etc/apache2/vhosts.d/*.conf files. More symptomatic with the "make_sock: could not bind to address 0.0.0.0:80" error, but let's see anyway.
#> grep -r "80" /etc/apache2/httpd.conf /etc/apache2/vhosts.d/*.conf
/etc/apache2/vhosts.d/00_default_vhost.conf:#Listen 12.34.56.78:80
/etc/apache2/vhosts.d/00_default_vhost.conf:Listen 80
/etc/apache2/vhosts.d/00_default_vhost.conf:NameVirtualHost *:80
/etc/apache2/vhosts.d/00_default_vhost.conf:<VirtualHost *:80>

#>

Again, nope. One Listen, one NameVirtualHost, the actual VirtualHost info and a commented-out line. Useless. Maybe there's a firewall blocking ports or something?
#> ipchains
bash: ipchains: command not found
#>

Of course, I don't even have it. Fresh Gentoo install, remember? Well, that was the Internet more or less out of ideas.
Then, someone, somewhere, points out that "no listening sockets" is a funny way of saying that Apache's not been told to listen to anything, because they'd just nuked their httpd.conf file.

HMMMM.

SOLUTION
Add Listen 80 into /etc/apache2/httpd.conf, restart Apache.
It works! The web-browser won't load anything, but there aren't any virtualhost settings, so that's to be expected.
Remove the Listen 80 again (it's just a quick hack) and delve into /etc/apache2/vhosts.d/00_default_vhost.conf, where the virtual host settings are meant to be.


[Note: There's a section in /etc/conf.d/apache2 that sets options for when Apache runs:
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE"
Note the "-D DEFAULT_VHOST" part. That's used to tell Apache to load the default vhost file that comes with Apache (under Gentoo?), /etc/apache2/vhosts.d/00_default_vhost.conf]


Out of guided curiosity, comment out the <IfDefine DEFAULT_VHOST> and </IfDefine> lines, restart Apache.
Woah! Two in a row! Looks like Apache2 wasn't defining DEFAULT_VHOST. Uncomment the lines again, restart Apache again..

Wait a minute! Apache's still working?!
I don't know why, but now it listens to the DEFAULT_VHOST settings. Go figure.
Anyway, hope this helps someone out there.

Comments

( 1 comment — Leave a comment )
Jonathan Nicol
Apr. 8th, 2012 04:29 am (UTC)
thanks for this
I had too many Listens.
( 1 comment — Leave a comment )