Tutorials  /  Linux Basics

Install and Configure PHP 7.4 on FreeBSD 14.0

Ccentron Redaktion · September 2025 ·10 min read ·Linux Basics, Tutorial

PHP is a widely adopted server-side scripting language primarily used for developing dynamic websites and applications. Although PHP 7.4 reached end-of-life (EOL) on November 28, 2022, some older projects may still rely on it for compatibility reasons. The current FreeBSD Ports branches no longer include PHP 7.4, but it can still be installed through a legacy branch.

This guide outlines the process of setting up PHP 7.4 on FreeBSD 14.0 using the 2022Q4 branch of the FreeBSD Ports Collection. You will compile PHP from source, configure PHP-FPM, and integrate it with the Apache web server to maintain support for legacy workloads.

Warning

PHP 7.4 is deprecated and no longer receives security patches. Since it has reached EOL, continuing to use it may expose your system to vulnerabilities. It should only be deployed for legacy applications that require it, and you should plan a migration to a supported version as soon as possible.

VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Prerequisites

Before starting, ensure that you:

  • Have access to a FreeBSD 14.0 system as a non-root sudo user.

Step 1: Install the FreeBSD Ports Collection

The FreeBSD Ports Collection allows you to compile and install third-party software from source. To obtain PHP 7.4, you must rely on the older 2022Q4 branch.

Update the package information on your server:

Console
$ sudo pkg update

Install Git:

Console
$ sudo pkg install -y git

Clone the legacy Ports tree using the 2022Q4 branch:

Console
$ sudo git clone --depth 1 https://git.FreeBSD.org/ports.git -b 2022Q4 /usr/ports

Verify that the /usr/ports directory exists:

Console
$ ls /usr/ports

Step 2: Compile and Install PHP 7.4

Since FreeBSD’s current Ports tree no longer supports PHP 7.4, you must compile it using the legacy branch. Follow the steps below to install dependencies, rebuild Perl, and then compile PHP 7.4.

Install required build tools:

Console
$ sudo pkg install -y curl re2c zip cmake gperf libzip html2text libxml2 gettext-tools

Remove the existing Perl binary to prevent conflicts:

Console
$ sudo pkg remove -y perl5

Enter the Perl 5.36 source directory:

Console
$ cd /usr/ports/lang/perl5.36

Compile and install Perl 5.36:

Console
$ sudo make BATCH=yes install clean

Next, navigate to the PHP 7.4 source directory:

Console
$ cd /usr/ports/lang/php74

Build and install PHP 7.4:

Console
$ sudo make BATCH=yes install clean

Step 3: Verify PHP Installation

Confirm the installed version of PHP:

Console
$ php -v

Copy the default production configuration file:

Console
$ sudo cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Review the active variables in the php.ini file:

Console
$ cat /usr/local/etc/php.ini | egrep -v '^;|^$'

This command outputs all enabled configuration options, such as memory limits, execution time, and file upload settings. Adjust these according to the needs of your application.

Install PHP 7.4 Extensions

PHP extensions expand the functionality of PHP by adding features such as database connectivity, advanced data processing, and more. Follow the steps below to compile and enable the required PHP 7.4 extensions on your server.

Navigate to the extensions source directory:

Console
$ cd /usr/ports/lang/php74-extensions

Run the configuration utility:

Console
$ sudo make config

Use the arrow keys to navigate and press Space to select the desired extensions. After making your selections, press Enter to save and exit.

Once configured, compile and install the chosen extensions:

Console
$ sudo make BATCH=yes install

Verify the installed PHP modules:

Console
$ php -m

The output should display a list of installed modules, including database support, compression, XML processing, and more.

Compile and Install PHP 7.4 FPM

PHP-FPM (FastCGI Process Manager) efficiently handles PHP requests and improves performance. When compiling PHP 7.4 from the Ports Collection, PHP-FPM is automatically included. Follow these steps to configure and run the service.

Check the installed PHP-FPM version:

Console
$ php-fpm --version

Enable PHP-FPM to start automatically on boot:

Console
$ sudo sysrc php_fpm_enable=YES

Start the PHP-FPM service:

Console
$ sudo service php-fpm start

Verify the service status to confirm it is running:

Console
$ sudo service php-fpm status

Configure PHP-FPM 7.4

Now adjust PHP-FPM settings by editing the default pool configuration. These adjustments help optimize resource usage and improve performance based on the server’s workload.

Navigate to the configuration directory:

Console
$ cd /usr/local/etc/php-fpm.d/

Ensure the www.conf file exists:

Console
$ ls

Edit the www.conf file with a text editor:

Console
$ sudo vim www.conf

Adjust the following pool configuration values:

Code
[www]
user = www
group = www
...
listen = /var/run/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0660
...
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
......

Explanation of key parameters:

  • [www]: Defines the pool name. Multiple pools can be managed independently.
  • user/group: Determines the system account PHP-FPM uses to execute scripts securely.
  • listen: Specifies the socket or TCP address used for FastCGI connections.
  • listen.owner / listen.group: Controls socket ownership to restrict access.
  • listen.mode: Defines permissions for the socket.
  • pm: Configures the process management strategy (dynamic scaling in this case).
  • pm.max_children: Limits maximum concurrent PHP workers.
  • pm.start_servers: Defines how many workers to preload at startup.
  • pm.min_spare_servers / pm.max_spare_servers: Manage idle worker thresholds to balance responsiveness and memory usage.

After editing, restart PHP-FPM to apply changes:

Console
$ sudo service php-fpm restart

Check service status again to confirm it is running with the new configuration:

Console
$ sudo service php-fpm status

Test and Use PHP 7.4

In this section, you will confirm that PHP 7.4 is installed and functioning properly by testing the PHP Command Line Interface (CLI), running a sample script, and configuring Apache to handle PHP-FPM requests via a UNIX socket. This ensures your server is running the intended PHP version.

Test PHP CLI

First, check the installed PHP version:

Console
$ php -v

Navigate to your home directory:

Console
$ cd ~

Create a test file named greet.php:

Console
$ vim greet.php

Insert the following PHP code into the file:

Code
<!--?php echo "Greetings from centron!\n"; echo "Current PHP version: " . phpversion() . "\n"; ?-->

Run the script using PHP CLI:

Console
$ php greet.php

Configure Apache with PHP-FPM

Once PHP 7.4 works from the CLI, integrate it with Apache via PHP-FPM using a UNIX socket.

Install Apache:

Console
$ sudo pkg install -y apache24

Enable Apache to start at boot:

Console
$ sudo sysrc apache24_enable="YES"

Start the Apache service:

Console
$ sudo service apache24 start

Check Apache’s status:

Console
$ sudo service apache24 status

Edit the Apache configuration file:

Console
$ sudo vim /usr/local/etc/apache24/httpd.conf

Uncomment the following modules by removing the # prefix:

Code
LoadModule proxy_module libexec/apache24/mod_proxy.so
LoadModule proxy_fcgi_module libexec/apache24/mod_proxy_fcgi.so
LoadModule rewrite_module libexec/apache24/mod_rewrite.so

Create a virtual host configuration file:

Console
$ sudo vim /usr/local/etc/apache24/Includes/php74.conf

Add the following configuration:

Code
ServerName localhost
DocumentRoot "/usr/local/www/apache24/data"

<Directory "/usr/local/www/apache24/data">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted



    SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/"


ErrorLog "/var/log/httpd-error.log"
CustomLog "/var/log/httpd-access.log" combined

Create a test PHP file in the web root:

PHP
$ echo '<?php 
echo "<div style=\"text-align: center;\">
<h1>Greetings from centron!</h1>
</div>"; 
?>' | sudo tee /usr/local/www/apache24/data/test.php > /dev/null

Restart PHP-FPM and Apache:

Console
$ sudo service php-fpm restart
$ sudo service apache24 restart

Check the services are running:

Console
$ sudo service php-fpm status
$ sudo service apache24 status

Finally, open the following URL in your browser to verify the page:

http://your-server-ip/test.php

Conclusion

You have successfully installed PHP 7.4 on FreeBSD 14.0 using the legacy Ports Collection, configured PHP-FPM for performance optimization, and integrated it with Apache to handle FastCGI requests. You validated the installation through CLI tests and a sample script served over the web. While this setup enables legacy applications to run on PHP 7.4, keep in mind that it is deprecated and no longer receives security patches. It is strongly recommended to migrate to a supported version such as PHP 8.x for enhanced security, compatibility, and performance.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren