The Apache HTTP Server is a efficient and extensible web server and the most popular on the Internet.
If you're only updating, check the upgrading guide.
USE flags for www-servers/apache The Apache Web Server
|Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
|Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
|Add support for sys-libs/gdbm (GNU database libraries)
|Add LDAP support (Lightweight Directory Access Protocol)
|!!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
|Add support for SSL/TLS connections (Secure Socket Layer / Transport Layer Security)
|Link in apache2 modules statically rather then plugins
|Install suexec with apache
|Install suexec with capabilities instead of SUID
|Log suexec to syslog instead of to a separate file
|Enable use of systemd-specific libraries and features like socket activation or session tracking
|Add threads support for various packages. Usually pthreads
Support in other packages
There is a global USE flag apache2 which enables support for Apache in other packages. This may causeto be pulled in automatically if such packages are used.
USE="... apache2 ..."
After setting this you want to update your system so the changes take effect:
emerge --ask --changed-use --deep @world
Launching and restarting
Start the Apache server:
Add Apache to the default runlevel:
rc-update add apache2 default
Restart the Apache service:
Verifying IP interfaces and ports on which apache2 is running on and listening to:
netstat -tulpen | grep apache
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 10932720 4544/apache2 tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 0 10932716 4544/apache2
Testing if a connection to a Apache server is working on localhost:
telnet localhost 80
Trying 127.0.0.1... Connected to localhost. Escape character is '^]'.
Interrupt the connection test with Ctrl+c and Enter.
Apache server's configuration in Gentoo is somewhat different from others distribution and this deserves some explanations. There are 2 main files that preside to this configuration.
- Gentoo's own apache2 configuration file /etc/conf.d/apache2
- Apache server's conventionnal configuration file /etc/apache2/httpd.conf
Gentoo's own configuration file
The only active line in this file is as follow :
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE"
This line defines options that will be interpreted by the various configuration files using the <IfDefine option-name> statement to activate or deactivate some part of the whole configuration. We will come back to this where appropriate in the rest of this guide.
Apache server's conventionnal configuration file httpd.conf
In fact this file is only an entry point as the whole configuration is splitted in many files in the /etc/apache2/ directory, that are assembled together using the Include directive. For example, the statement Include /etc/apache2/modules.d/*.conf, in httpd.conf, aims at including all the files in /etc/apache2/modules.d/ which name ends with .conf.
Taking into account what has been said in the subsection above, and as module configuration files (files in /etc/apache2/modules.d) almost always start with the <IfDefine module-name>, the content of one file inside /ect/apache2/modules.d, will ONLY be assembled with the rest of the configuration, if the matching option is set using a -D module-name flag in the APACHE2_OPTS variable in the /etc/conf.d/apache2 file. The 00_default_settings.conf configuration file is an exception to this rule as it doesn't start with an IfDefine statement and therefore is always included in the resulting configuration.
After a fresh install of apache server, the configuration resulting from the assemblage of the different configuration files is as follow. We start with the entry point /etc/apache2/httpd.conf and add the included parts with a comment stating it in an obvious manner.
This is ONLY given for quick reference and to give you an overall view. You are strongly invited to review the comments included in the various files to understand the ins and out of the configuration. Please also refer to the apache manual for an in depth understanding.
First sign of life
As you can see in the initial configuration above, the pre-installed virtual host's DocumentRoot directory is /var/www/localhost/htdocs, its server name is localhost. In addition an index.htlm file is provided in the DocumentRoot directory, thus to ckeck whether all is correctly installed or not, point your browser on http://www.localhost. You should see an " It works !" message on the page.
Enabling PHP support
Install PHP with the apache2 USE flag and enable the module:
APACHE2_OPTS="... -D PHP5"
To test if the PHP module works, create a test page:
<?php phpinfo(); ?>
Now open the test page: http://localhost/. You should see a table describing the PHP settings
Adding your own virtual hosts
For each virtual host, provide a DocumentRoot directory that is made accessible to the apache server, add a myVirtualHost.conf file in /etc/apache2/vhosts.d directory and don't forget to add an entry for your domain name in /etc/hosts.
Don't forget to restart apache server each time you make a change into the configuration files (see above).
- Slicehost article: Installing Apache on Gentoo
- Slicehost article: Apache configuration files on Gentoo
- Slicehost article: Configuring the Apache MPM on Gentoo
- Slicehost article: Apache configuration on Gentoo
- Slicehost article: Apache Virtual Hosts on Gentoo
- Slicehost article: Enabling and using apache's mod_status on Gentoo
- apache.org documentation
- Apache2 mod_pagespeed