Skip to content
Indus LeveL
freebsd apache php lamp sysadmin networking bsd webserver

How to Install Apache and PHP Web Server Stacks on FreeBSD

A comprehensive systems architecture manual on compiling Apache HTTP daemons and PHP runtime modules from FreeBSD source ports.

2 min read
Cover illustration representing high-performance FreeBSD web server stack configuration, compiling Apache HTTP daemons and PHP runtime modules

When deploying highly performant web application stacks across bare-metal server hardware (such as custom data center hosting nodes in east-dc1 or west-dc1), compiling Apache HTTP server and PHP processing engines directly from source yields maximum execution efficiency.

In this systems architecture guide, I examine how to navigate local FreeBSD port boundaries, compile optimized Apache 2.4 server daemons, resolve source compilation dependencies for PHP runtime interpreters, and start daemon processes using system configuration tables (rc.conf).

Step 1: Compiling Apache 2.4 from Source Ports

Access your local FreeBSD source ports tree directory and launch compile rules for the Apache HTTP engine.

# Navigate to Apache web server source directory
cd /usr/ports/www/apache24

# Launch build and install rules
make install clean

Step 2: Enabling Auto-Startup and Running Initialization

To guarantee persistent background operation across server reboot cycles, define initialization directives inside /etc/rc.conf.

# Append enablement directive to system initialization maps
sysrc apache24_enable="YES"

Initialize your compiled web server daemon and verify active listener sockets on port 80:

# Start HTTP service processes
service apache24 start

# Output running process status
service apache24 status

Step 3: Compiling PHP Modules and Integration Maps

Navigate to the PHP source ports directory and compile core language runtime interpreters with explicit dynamic Apache module integration wrappers.

# Navigate to PHP compile directory
cd /usr/ports/lang/php

# Compile source binaries specifying Apache shared object support
make install clean

Configuring Apache Module Mapping (httpd.conf)

Ensure Apache loads compiled shared object processing extensions by modifying the primary server configuration file /usr/local/etc/apache24/httpd.conf:

vi /usr/local/etc/apache24/httpd.conf

Insert the following module configuration block into your HTTP configuration header:

LoadModule php_module libexec/apache24/libphp.so

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

Restart your active Apache web server to apply configuration changes and parse incoming dynamic files:

service apache24 restart

References

Back to Blog
Share:

Follow along

Stay in the loop — new articles, thoughts, and updates.