User:Jaaf/draft2

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a work in progress; treat its contents with caution - jaaf (talk | contribs).

The Apache HTTP Server is a efficient and extensible web server and the most popular on the Internet.

Installation

Note
If you're only updating, check the upgrading guide.
root #emerge --ask www-servers/apache

USE flags

USE flags for www-servers/apache The Apache Web Server

+suexec-caps Install suexec with capabilities instead of SUID
debug 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
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
gdbm Add support for sys-libs/gdbm (GNU database libraries)
ldap Add LDAP support (Lightweight Directory Access Protocol)
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
ssl Add support for SSL/TLS connections (Secure Socket Layer / Transport Layer Security)
static Link in apache2 modules statically rather then plugins
suexec Install suexec with apache
suexec-syslog Log suexec to syslog instead of to a separate file
systemd Enable use of systemd-specific libraries and features like socket activation or session tracking
threads 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 cause www-servers/apache to be pulled in automatically if such packages are used.

FILE /etc/portage/make.conf
USE="... apache2 ..."

After setting this you want to update your system so the changes take effect:

root #emerge --ask --changed-use --deep @world

Launching and restarting

Start the Apache server:

root #/etc/init.d/apache2 start

Add Apache to the default runlevel:

root #rc-update add apache2 default

Restart the Apache service:

root #/etc/init.d/apache2 restart


Testing

Verifying IP interfaces and ports on which apache2 is running on and listening to:

root #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:

user $telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

Interrupt the connection test with Ctrl+c and Enter.


Configuration

Configuration files

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 :

FILE /etc/conf.d/apache2
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.

Default 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.


Warning
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.


FILE http.d
'"`UNIQ--pre-00000009-QINU`"'

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:

FILE /etc/conf.d/apache2
APACHE2_OPTS="... -D PHP5"


To test if the PHP module works, create a test page:

FILE /var/www/localhost/htdocs/index.php
<html>
 <body>
  <?php phpinfo(); ?>
 </body>
</html>

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.

Warning
Don't forget to restart apache server each time you make a change into the configuration files (see above).

Troubleshooting

See also

  • Lighttpd - a fast, lightweight web server.
  • Nginx - a small, robust and high-performance http server

External resources