# [SOLVED] How to setup Apache - New Gentoo Installation

## interpegasus

[SOLVED] How to setup Apache - New Gentoo Installation

Hi,

I installed Gentoo recently and I would like to know how to setup the Apache web server in Gentoo. I followed the instructions at http://en.gentoo-wiki.com/wiki/Apache2, however when I point the browser to http://localhost/ or http://127.0.0.1/ the browser response is "Unable to connect to remote host.":

Does anybody know how to fix this issue? Thanks in advance.  :Surprised: 

Below there's the output of some tests and configuration files:

```

# lynx http://127.0.0.1

Looking up 127.0.0.1

Making HTTP connection to 127.0.0.1

Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://127.0.0.1/

```

This is the relevant output of nmap:

```

# netstat -nlp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      3242/mysqld

tcp6       0      0 :::80                   :::*                    LISTEN      8576/apache2

tcp6       0      0 :::443                  :::*                    LISTEN      8576/apache2

Active UNIX domain sockets (only servers)

Proto RefCnt Flags       Type       State         I-Node   PID/Program name     Path

unix  2      [ ACC ]     STREAM     LISTENING     29353    8578/apache2         /var/run/cgisock.8576

```

This is the output of the apache status:

```

# /etc/init.d/apache2 fullstatus

Looking up localhost

Making HTTP connection to localhost

Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://localhost/server-status

```

Verifying the syntax used:

```

# apache2ctl configtest

 * Checking apache2 configuration ...                                                                                          [ ok ]

# apache2ctl configdump

/usr/sbin/apache2 started with '-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP5 -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf'

Looking up localhost

Making HTTP connection to localhost

Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://localhost/server-info/?config

Looking up localhost

Making HTTP connection to localhost

Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://localhost/server-info/?server

Looking up localhost

Making HTTP connection to localhost

Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://localhost/server-info/?list

```

Net checking in /etc/conf.d/rc

```

RC_NET_STRICT_CHECKING="lo"

```

The content of /etc/hosts

```

# cat /etc/hosts: Local Host Database

#

# This file describes a number of aliases-to-address mappings for the for

# local hosts that share this file.

#

# In the presence of the domain name service or NIS, this file may not be

# consulted at all; see /etc/host.conf for the resolution order.

#

127.0.0.1       localhost

# IPv4 and IPv6 localhost aliases

127.0.0.1       localhost

::1             localhost

```

The content of /etc/resolv.conf

```

# Generated by dhcpcd from wlan0

# /etc/resolv.conf.head can replace this line

nameserver 200.75.51.132

nameserver 200.75.51.133

# /etc/resolv.conf.tail can replace this line

```

The content of # cat httpd.conf

```

# cat httpd.conf      

# This is a modification of the default Apache 2.2 configuration file

# for Gentoo Linux.                                                  

#                                                                    

# Support:                                                           

#   http://www.gentoo.org/main/en/lists.xml   [mailing lists]        

#   http://forums.gentoo.org/                 [web forums]           

#   irc://irc.freenode.net#gentoo-apache      [irc chat]             

#                                                                    

# Bug Reports:                                                       

#   http://bugs.gentoo.org                    [gentoo related bugs]  

#   http://httpd.apache.org/bug_report.html   [apache httpd related bugs]

#                                                                        

#                                                                        

# This is the main Apache HTTP server configuration file.  It contains the

# configuration directives that give the server its instructions.         

# See <URL:http://httpd.apache.org/docs/2.2> for detailed information.    

# In particular, see                                                      

# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>              

# for a discussion of each configuration directive.                       

#                                                                         

# Do NOT simply read the instructions in here without understanding       

# what they do.  They're here only as hints or reminders.  If you are unsure

# consult the online docs. You have been warned.                            

#                                                                           

# Configuration and logfile names: If the filenames you specify for many    

# of the server's control files begin with "/" (or "drive:/" for Win32), the

# server will use that explicit path.  If the filenames do *not* begin      

# with "/", the value of ServerRoot is prepended -- so "var/log/apache2/foo_log"

# with ServerRoot set to "/usr" will be interpreted by the                      

# server as "/usr/var/log/apache2/foo.log".                                     

# ServerRoot: The top of the directory tree under which the server's

# configuration, error, and log files are kept.                     

#                                                                   

# Do not add a slash at the end of the directory path.  If you point

# ServerRoot at a non-local disk, be sure to point the LockFile directive

# at a local disk.  If you wish to share the same ServerRoot for multiple

# httpd daemons, you will need to change at least LockFile and PidFile.  

ServerRoot "/usr/lib64/apache2"                                          

# Dynamic Shared Object (DSO) Support

#                                    

# To be able to use the functionality of a module which was built as a DSO you

# have to place corresponding `LoadModule' lines at this location so the      

# directives contained in it are actually available _before_ they are used.   

# Statically compiled modules (those listed by `httpd -l') do not need        

# to be loaded here.                                                          

#                                                                             

# Example:                                                                    

# LoadModule foo_module modules/mod_foo.so                                    

#                                                                             

# GENTOO: Automatically defined based on APACHE2_MODULES USE_EXPAND variable. 

#         Do not change manually, it will be overwritten on upgrade.          

#                                                                             

# The following modules are considered as the default configuration.          

# If you wish to disable one of them, you may have to alter other             

# configuration directives.                                                   

#                                                                             

# Change these at your own risk!                                              

LoadModule actions_module modules/mod_actions.so

LoadModule alias_module modules/mod_alias.so    

LoadModule auth_basic_module modules/mod_auth_basic.so

LoadModule authn_alias_module modules/mod_authn_alias.so

LoadModule authn_anon_module modules/mod_authn_anon.so  

LoadModule authn_dbm_module modules/mod_authn_dbm.so    

LoadModule authn_default_module modules/mod_authn_default.so

LoadModule authn_file_module modules/mod_authn_file.so      

<IfDefine AUTHNZ_LDAP>                                      

LoadModule authnz_ldap_module modules/mod_authnz_ldap.so    

</IfDefine>                                                 

LoadModule authz_dbm_module modules/mod_authz_dbm.so        

LoadModule authz_default_module modules/mod_authz_default.so

LoadModule authz_groupfile_module modules/mod_authz_groupfile.so

LoadModule authz_host_module modules/mod_authz_host.so          

LoadModule authz_owner_module modules/mod_authz_owner.so        

LoadModule authz_user_module modules/mod_authz_user.so          

LoadModule autoindex_module modules/mod_autoindex.so            

<IfDefine CACHE>                                                

LoadModule cache_module modules/mod_cache.so                    

</IfDefine>                                                     

LoadModule cgid_module modules/mod_cgid.so                      

<IfDefine DAV>                                                  

LoadModule dav_module modules/mod_dav.so                        

</IfDefine>                                                     

<IfDefine DAV>                                                  

LoadModule dav_fs_module modules/mod_dav_fs.so                  

</IfDefine>                                                     

<IfDefine DAV>                                                  

LoadModule dav_lock_module modules/mod_dav_lock.so              

</IfDefine>                                                     

LoadModule deflate_module modules/mod_deflate.so                

LoadModule dir_module modules/mod_dir.so                        

<IfDefine CACHE>                                                

LoadModule disk_cache_module modules/mod_disk_cache.so          

</IfDefine>                                                     

LoadModule env_module modules/mod_env.so                        

LoadModule expires_module modules/mod_expires.so                

LoadModule ext_filter_module modules/mod_ext_filter.so          

<IfDefine CACHE>                                                

LoadModule file_cache_module modules/mod_file_cache.so          

</IfDefine>                                                     

LoadModule filter_module modules/mod_filter.so                  

LoadModule headers_module modules/mod_headers.so                

LoadModule include_module modules/mod_include.so                

<IfDefine INFO>                                                 

LoadModule info_module modules/mod_info.so                      

</IfDefine>                                                     

<IfDefine LDAP>                                                 

LoadModule ldap_module modules/mod_ldap.so                      

</IfDefine>                                                     

LoadModule log_config_module modules/mod_log_config.so          

LoadModule logio_module modules/mod_logio.so                    

<IfDefine CACHE>                                                

LoadModule mem_cache_module modules/mod_mem_cache.so            

</IfDefine>                                                     

LoadModule mime_module modules/mod_mime.so                      

LoadModule mime_magic_module modules/mod_mime_magic.so          

LoadModule negotiation_module modules/mod_negotiation.so        

LoadModule rewrite_module modules/mod_rewrite.so                

LoadModule setenvif_module modules/mod_setenvif.so              

LoadModule speling_module modules/mod_speling.so                

<IfDefine SSL>                                                  

LoadModule ssl_module modules/mod_ssl.so                        

</IfDefine>                                                     

<IfDefine STATUS>                                               

LoadModule status_module modules/mod_status.so                  

</IfDefine>                                                     

LoadModule unique_id_module modules/mod_unique_id.so

<IfDefine USERDIR>

LoadModule userdir_module modules/mod_userdir.so

</IfDefine>

LoadModule usertrack_module modules/mod_usertrack.so

LoadModule vhost_alias_module modules/mod_vhost_alias.so

# If you wish httpd to run as a different user or group, you must run

# httpd as root initially and it will switch.

#

# User/Group: The name (or #number) of the user/group to run httpd as.

# It is usually good practice to create a dedicated user and group for

# running httpd, as with most system services.

User apache

Group apache

# Supplemental configuration

#

# Most of the configuration files in the /etc/apache2/modules.d/ directory can

# be turned on using APACHE2_OPTS in /etc/conf.d/apache2 to add extra features

# or to modify the default configuration of the server.

#

# To know which flag to add to APACHE2_OPTS, look at the first line of the

# the file, which will usually be an <IfDefine OPTION> where OPTION is the

# flag to use.

Include /etc/apache2/modules.d/*.conf

# Virtual-host support

#

# Gentoo has made using virtual-hosts easy. In /etc/apache2/vhosts.d/ we

# include a default vhost (enabled by adding -D DEFAULT_VHOST to

# APACHE2_OPTS in /etc/conf.d/apache2).

Include /etc/apache2/vhosts.d/*.conf

# vim: ts=4 filetype=apache

```

The content of default_vhost.include 

```

# cat default_vhost.include                           

# ServerAdmin: Your address, where problems with the server should be  

# e-mailed.  This address appears on some server-generated pages, such 

# as error documents.  e.g. admin@your-domain.com                      

#ServerAdmin root@domain.com                                    

# DocumentRoot: The directory out of which you will serve your

# documents. By default, all requests are taken from this directory, but

# symbolic links and aliases may be used to point to other locations.   

#                                                                       

# If you change this to something that isn't under /var/www then suexec 

# will no longer work.                                                  

DocumentRoot "/var/www/localhost/htdocs"                                

# This should be changed to whatever you set DocumentRoot to.

<Directory "/var/www/localhost/htdocs">                      

        # Possible values for the Options directive are "None", "All",

        # or any combination of:                                      

        #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

        #                                                                          

        # Note that "MultiViews" must be named *explicitly* --- "Options All"      

        # doesn't give it to you.                                                  

        #                                                                          

        # The Options directive is both complicated and important.  Please see     

        # http://httpd.apache.org/docs/2.2/mod/core.html#options                   

        # for more information.                                                    

        Options Indexes FollowSymLinks                                             

        # AllowOverride controls what directives may be placed in .htaccess files.

        # It can be "All", "None", or any combination of the keywords:            

        #   Options FileInfo AuthConfig Limit                                     

        AllowOverride All                                                         

        # Controls who can get stuff from this server.

        Order allow,deny                              

        Allow from all                                

</Directory>                                          

<IfModule alias_module>

        # Redirect: Allows you to tell clients about documents that used to

        # exist in your server's namespace, but do not anymore. The client

        # will make a new request for the document at its new location.

        # Example:

        #   Redirect permanent /foo http://www.example.com/bar

        # Alias: Maps web paths into filesystem paths and is used to

        # access content that does not live under the DocumentRoot.

        # Example:

        #   Alias /webpath /full/filesystem/path

        #

        # If you include a trailing / on /webpath then the server will

        # require it to be present in the URL.  You will also likely

        # need to provide a <Directory> section to allow access to

        # the filesystem path.

        # ScriptAlias: This controls which directories contain server scripts.

        # ScriptAliases are essentially the same as Aliases, except that

        # documents in the target directory are treated as applications and

        # run by the server when requested rather than as documents sent to the

        # client.  The same rules about trailing "/" apply to ScriptAlias

        # directives as to Alias.

        ScriptAlias /cgi-bin/ "/var/www/localhost/cgi-bin/"

</IfModule>

# "/var/www/localhost/cgi-bin" should be changed to whatever your ScriptAliased

# CGI directory exists, if you have that configured.

<Directory "/var/www/localhost/cgi-bin">

        AllowOverride None

        Options None

        Order allow,deny

        Allow from all

</Directory>

# vim: ts=4 filetype=apache

```

The content of 00_default_vhost.conf  

```

cat 00_default_vhost.conf                           

# Virtual Hosts                                                        

#                                                                      

# If you want to maintain multiple domains/hostnames on your           

# machine you can setup VirtualHost containers for them. Most configurations

# use only name-based virtual hosts so the server doesn't need to worry about

# IP addresses. This is indicated by the asterisks in the directives below.  

#                                                                            

# Please see the documentation at                                            

# <URL:http://httpd.apache.org/docs/2.2/vhosts/>                             

# for further details before you try to setup virtual hosts.                 

#                                                                            

# You may use the command line option '-S' to verify your virtual host       

# configuration.

<IfDefine DEFAULT_VHOST>

# see bug #178966 why this is in here

# Listen: Allows you to bind Apache to specific IP addresses and/or

# ports, instead of the default. See also the <VirtualHost>

# directive.

#

# Change this to Listen on specific IP addresses as shown below to

# prevent Apache from glomming onto all bound IP addresses.

#

#Listen 12.34.56.78:80

Listen 80

# Use name-based virtual hosting.

NameVirtualHost *:80

# When virtual hosts are enabled, the main host defined in the default

# httpd.conf configuration will go away. We redefine it here so that it is

# still available.

#

# If you disable this vhost by removing -D DEFAULT_VHOST from

# /etc/conf.d/apache2, the first defined virtual host elsewhere will be

# the default.

<VirtualHost *:80>

        ServerName localhost

        Include /etc/apache2/vhosts.d/default_vhost.include

        <IfModule mpm_peruser_module>

                ServerEnvironment apache apache

        </IfModule>

</VirtualHost>

</IfDefine>

# vim: ts=4 filetype=apache

```

Thanks[/b]Last edited by interpegasus on Thu May 06, 2010 12:57 am; edited 2 times in total

----------

## alunduil

Your nestat suggests that apache is only listening on an ipv6 interface.  What appears when you type ::1 in the browser?

Regards,

Alunduil

----------

## interpegasus

Thanks for the reply,

The browser output of "::1" is:

```

Using Opera

Error!

The address type is unknown or unsupported

```

```

Using Firefox

This address is restricted

This address uses a network port which is normally used for purposes other than Web browsing. Firefox has canceled the request for your protection.

```

```

Using Lynx

# lynx ::1

Looking up : first

Looking up www.:.com, guessing...

Looking up www.:.edu, guessing...

Looking up www.:.net, guessing...

Looking up www.:.org, guessing...

Can't Access `file://localhost/etc/apache2/vhosts.d/::1'

Alert!: Unable to access document.

lynx: Can't access startfile

```

Thanks

----------

## alunduil

Yeah, I looked at mine again (I just recently added ipv6 support so I'm still getting used to how things change) and saw that wasn't the issue.  I'll look through the output you provided one more time and see what I can figure out from it.

Regards,

Alunduil

----------

## interpegasus

Thanks for the reply.

I also executed nmap this time to test open ports:

```

# nmap -A -T4 localhost

Starting Nmap 5.21 ( http://nmap.org ) at 2010-05-04 15:03 PDT

Note: Host seems down. If it is really up, but blocking our ping probes, try -PN

Nmap done: 1 IP address (0 hosts up) scanned in 2.34 seconds

# nmap -A -T4 -PN localhost

Starting Nmap 5.21 ( http://nmap.org ) at 2010-05-04 15:03 PDT

Nmap scan report for localhost (127.0.0.1)

Host is up (0.015s latency).

rDNS record for 127.0.0.1: localhost

All 1000 scanned ports on localhost (127.0.0.1) are filtered

Too many fingerprints match this host to give specific OS details

Network Distance: 3 hops

TRACEROUTE (using proto 1/icmp)

HOP RTT      ADDRESS

1   3.42 ms  192.168.0.1

2   ...

3   16.33 ms localhost (127.0.0.1)

OS and Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .

Nmap done: 1 IP address (1 host up) scanned in 106.73 seconds

#

```

Thanks

----------

## interpegasus

Hi all, 

Apache still doesn't serve pages from http://localhost or any other virtualhost in my machine. The browser response is "Unable to connect to remote host."

These are some steps I have tried to solve the issue:

i.  I tried resinsttalling Apache with different USE flag combinations

ii. I downgraded to version: Apache/2.2.14

Does anybody have suggestions to solve this issue?? Thanks in advance!

----------

## interpegasus

Solved!

The loopback inteface was down.

Execute: 

```
/sbin/ifconfig lo up
```

Then the net interfaces should look something like this:

```

# /sbin/ifconfig

eth0      Link encap:Ethernet  HWaddr 00:1d:ba:1e:57:43

          UP BROADCAST MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

          Interrupt:16

lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 00:16:ea:5b:e6:ce

          inet addr:192.168.0.5  Bcast:192.168.0.255  Mask:255.255.255.0

          inet6 addr: fe80::216:eaff:fe5b:e6ce/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:1079 errors:0 dropped:0 overruns:0 frame:0

          TX packets:1248 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:824177 (804.8 KiB)  TX bytes:201331 (196.6 KiB)

```

----------

