Install Apache Server

Synopsis:

The Apache HTTP Server is the number one HTTP server on the Internet.

I. Installation
Apache Server is included in the FreeBSD Ports. If you need to install Ports, go Here

Package Method:

#
# pkg install -y apache24
#

Ports Method:

#
# cd /usr/ports/www/apache24 && make install clean
#

Use the default compile options for Ports Method:
Now the actual installation will proceed.
The compiler and installation process takes around 20 minutes to install the program on the Celeron 1.6G system.

II.Configuration

1. Add the start up to the rc.conf file:
#
# sysrc apache24_enable="YES"
#
2. Load the HTTP Accept Filter for FreeBSD kernel
In /boot/loader.conf add:
#
# echo 'accf_http_load="YES"' >> /boot/loader.conf
#
Manually load kernel module:
#
# kldload accf_http
#
3. Apache Configuration in httpd.conf:
Apache uses a configuration file that must be manually edited for your own customization.
#
# cd /usr/local/etc/apache24
# mv httpd.conf httpd.conf.original
# cp httpd.conf.original httpd.conf
# ee httpd.conf
#
find: ServerAdmin webmaster@example.com
(put in the web admin's email address, like webmaster@'yourdomain')

find: ServerName www.example.com
(put in your server's name, like www.'yourdomain'. If you do not have a registered DNS, use the server's IP address here.)

find: .htaccess AllowOverride None
(default, but if you want to use .htaccess files, change 'None' to 'All')

find: DirectoryIndex index.html
add in order; index.php index.html index.htm

For PHP support create a file called php.conf in the Includes folder:
<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>
If server doesn't answer to DNS by name:
comment out (place pound sign at start of configuration line):
#LoadModule unique_id_module libexec/apache24/mod_unique_id.so
[ESC] and save httpd.conf.

III. Startup the server and confirm:
#
# service apache24 start
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.
# tail -10 /var/log/httpd-error.log
[Mon Jul 22 12:31:29.576724 2024] [mpm_prefork:notice] [pid 99680] AH00163: Apache/2.4.62 (FreeBSD) configured -- resuming normal operations
[Mon Jul 22 12:31:29.578113 2024] [core:notice] [pid 99680] AH00094: Command line: '/usr/local/sbin/httpd -D NOHTTPACCEPT'
#

IV. Test
Open a browser and try to browse on the web server:

location= "http://'your server's IP address'/"
The default Apache24 home page should display the "It Works!" message.

To locate the server's root;
#
# cd /usr/local/www/apache22/data
#
V. Tuning
For faster downloads, enable compression:
in the httpd.conf file,
Enable these three load modules
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadMOdule filter_module modules/mod_filter.so
find the Directory section
 <Directory "/usr/local/www/apache24/data/">
put these lines just before </Directory>:
AddOutputFilterByType DEFLATE text/html
DeFlateCompressionLevel 9