Size: 2657
Comment:
|
← Revision 18 as of 2023-04-03 12:48:41 ⇥
Size: 3490
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 13: | Line 13: |
Most Linux and BSD distributions offer a package for `httpd(8)`, but it will be named differently across systems. The most common names are `apache` and `apache2`. | Most [[Linux]] and [[BSD]] distributions offer a package for `httpd(8)`, but it will be named differently across systems. The most common names are `apache` and `apache2`. |
Line 17: | Line 17: |
=== Containers === [[Docker]] container images are also available for the current version. The image is available from [[Docker/Hub|DockerHub]] as `docker.io/library/httpd` (or simply `httpd` when using `docker(1)` specifically). Try: {{{ docker run --detach --name my-apache \ --publish 127.0.0.1:8080:80 \ --mount type=bind,src=/path/to/web/root,dst=/usr/local/apache2/htdocs \ httpd:2.4 }}} ---- == Setup == |
|
Line 19: | Line 40: |
For [[Linux/AlpineLinux|Alpine]], try: {{{ rc-service apache2 start rc-update add apache2 }}} |
For [[Linux/OpenRC#Usage|OpenRC-based systems]], start the `apache2` service and set it to start on boot. |
Line 91: | Line 107: |
=== Encryption === See [[Apache/SSL|here]] for details. |
|
Line 112: | Line 134: |
=== FastCGI === See [[Apache/FastCGI|here]] for details. ---- == See also == [[https://httpd.apache.org/docs/current/|Apache server documentation]] [[https://man.archlinux.org/man/httpd.8|httpd(8)]] [[Apache/FastCGI|Apache with FastCGI]] [[Apache/SSL|Apache with SSL/TLS]] |
Apache
httpd(8), also known as Apache or Apache2, is one of the oldest and most extensible web servers. It has survived so long precisely because it is so extensible; system administrators have been able to continuously tune and upgrade the server for modern best practices.
Contents
Installation
Most Linux and BSD distributions offer a package for httpd(8), but it will be named differently across systems. The most common names are apache and apache2.
Supporting programs like htpasswd(1) are sometimes split into a separate package named like apache2-utils.
Containers
Docker container images are also available for the current version. The image is available from DockerHub as docker.io/library/httpd (or simply httpd when using docker(1) specifically).
Try:
docker run --detach --name my-apache \ --publish 127.0.0.1:8080:80 \ --mount type=bind,src=/path/to/web/root,dst=/usr/local/apache2/htdocs \ httpd:2.4
Setup
For systemd-capable systems, start and enable httpd.service or apache2.service (again, differing across systems).
For OpenRC-based systems, start the apache2 service and set it to start on boot.
Otherwise try:
service apache2 start #also: stop, restart, and reload
For BSD distributions, try:
/usr/local/sbin/apachectl start #also: stop, restart, and graceful
See apachectl(8) for more information.
To launch the server on startup, update /etc/rc.conf:
apache_enable="YES"
Configuration
Server
The server is configured by a central file. Distributions disagree about the correct location for this file. Try all of the following:
/etc/apache2.conf
/etc/apache2/apache2.conf
/etc/httpd/conf/httpd.conf
/usr/local/etc/apache/httpd.conf
Virtual Hosts
Virtual hosts are declared in domain-specific files. An example site configuration for a CGI script, such as cgit.
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName git.my-domain.com DocumentRoot /usr/share/cgit Alias / /usr/share/cgit/cgit.cgi <Document '/usr/share/cgit/'> Options ExecCGI FollowSymLinks Require all granted AddHandler cgi-script .cgi DirectoryIndex cgit.cgi </Document> ErrorLog /var/log/apache2/error.log CustomLog /var/log/apache2/access.log combined </VirtualHost>
Encryption
See here for details.
Authentication
A document can be set to require authentication, except for a local network user.
<Document "/"> AuthType Basic AuthName "Authentication Required" AuthUserFile /var/www/ftp-htpasswd <RequireAny> Require valid-user Require ip 192.168 Require ip 10 </RequireAny> </Document>
This method of authentication is 'good-enough' for personal uses. It relies entirely on the traffic encryption (HTTPS).
FastCGI
See here for details.