Install and enable Apache HTTP Server 2.4 from the FreeBSD ports and packages collection:
pkg install -y apache24 sysrc apache24_enable="YES" service apache24 start
Verify that the server is up and running by visiting your server’s public IP address or domain name in a web browser. The page will display the words “It works!” in large letters. Alternatively, use a utility like
curl to check from the command line:
curl localhost (or with FreeBSD’s
fetch -qo- http://localhost).
To avoid a warning any time the web server starts or restarts, change the
ServerName directive in
/usr/local/etc/apache24/httpd.conf to your server’s public IP address or domain name. You may also want to change the
ServerAdmin directive, as well, though this is optional:
ServerAdmin firstname.lastname@example.org ServerName www.yourdomain.com
By default, Apache 2.4 on FreeBSD uses the prefork MPM (Multi-Processing Module), which is non-threaded. This is fine in many cases and offers the most compatibility, but the threaded event and worker MPMs provide better performance on most systems and reliable support for HTTP/2. However, since PHP is not thread-safe without extra compilation options, the traditional
mod_php method of integrating PHP with Apache is only compatible with prefork. PHP-FPM (FastCGI Process Manager) is an alternative that provides a CGI daemon that can be used by threaded versions of Apache and offers its own performance benefits over
mod_php. We’ll fully set PHP-FPM up later, but we need to make a few changes to Apache first.
In the main Apache config file (
/usr/local/etc/apache24/httpd.conf), uncomment or add the following to enable the event MPM and two modules necessary for PHP-FPM:
LoadModule mpm_event_module libexec/apache24/mod_mpm_event.so LoadModule proxy_module libexec/apache24/mod_proxy.so LoadModule proxy_fcgi_module libexec/apache24/mod_proxy_fcgi.so
Make sure that
mpm_event_module is the only MPM module enabled; the
mpm_worker_module lines must be commented out or removed. Restart the web server with
service apache24 restart to apply the new configuration.
- Config files:
- Web root:
Creating a virtualhost
To make configuration of our site easier, let’s create a Virtual Host. This will also allow us to host multiple sites on the same server using different names. In
/usr/local/etc/apache24/Includes, create a file named
nextcloud.conf containing the following:
<VirtualHost *:80> ServerName www.yourdomain.com <Directory "/usr/local/www/apache24/data/nextcloud/"> Require all granted AllowOverride All Options FollowSymLinks MultiViews <IfModule mod_dav.c> Dav Off </IfModule> </Directory> </VirtualHost>
Restart the web server with
service apache24 restart to apply the new configuration. Any requests to
http://www.yourdomain.com will now use this configuration over the default.