
PHP is a widely-used server-side scripting language designed for building dynamic websites and web applications. While PHP 7.4 reached its end-of-life (EOL) on November 28, 2022, some legacy applications may still depend on it for compatibility and stability. FreeBSD no longer offers PHP 7.4 through its latest Ports branches, but you can still install it using a legacy branch.
This article explains how to install PHP 7.4 on FreeBSD 14.0 using the 2022Q4 branch of the FreeBSD Ports Collection. You’ll compile PHP from source, configure PHP-FPM, and set it up with the Apache web server for legacy application support.
PHP 7.4 is no longer maintained and does not receive security updates. It has reached end-of-life and may expose your system to unpatched vulnerabilities. Use it only for legacy applications that require it, and plan to migrate to a maintained version to continue receiving security updates.
Before you begin, you need to:
The FreeBSD Ports Collection is a package management framework used to compile and install third-party applications from source. To install legacy versions like PHP 7.4, you must use the older 2022Q4 branch of the Ports Collection.
Update the server's package information index.
Install git on your workstation.
Clone the legacy Ports Collection using the 2022Q4 branch (the last branch to support PHP 7.4).
Verify that the /usr/ports directory exists and contains the cloned Ports tree.
Your output should be similar to the one below:
FreeBSD no longer provides PHP 7.4 through its current Ports tree. However, by using the legacy 2022Q4 Ports Collection, you can still compile PHP 7.4 from source. Follow the steps below to compile and install PHP 7.4 along with its required dependencies and extensions.
Install required build tools and libraries.
Remove the preinstalled Perl 5 binary to avoid build conflicts.
Navigate to the Perl 5.36 source directory.
Compile and install Perl 5.36.
BATCH=yes : Install ports packages and their dependencies without the need for user interaction during the configuration process.clean : Remove build artifacts after installation process is finished, freeing up disk space.Your output should be similar to the one below:
Navigate to the PHP 7.4 source directory.
Compile and install PHP 7.4.
After your build is complete your output should look like:
Verify the installed PHP version.
Your output should be similar to the one below:
Copy the default production php.ini configuration file.
View the active variables mentioned in the php.ini file.
This command will list all the active variables being used on the server.
Your output should be similar to the one below:
Modify these values as per the needs of your application.
PHP extensions enhance the functionality of PHP by providing additional features like support for various databases, data manipulation, and more. Follow the steps below to compile and build the necessary PHP 7.4 extensions on your server.
Navigate to the PHP 7.4 extensions directory.
Create a configuration using the make command.
Use the arrow keys to navigate, Space to select the required extensions. After selecting them, press Enter to save and exit the interactive shell.
After completing the configuration, run the following command to compile and install the selected extensions.
Verify the installed PHP modules by running the following command.
Your output should be similar to the one below:
PHP-FPM (FastCGI Process Manager) efficiently handles PHP requests and enhances performance, making it a common choice in production environments. PHP-FPM is automatically installed when you compile PHP 7.4 from the Ports Collection. Follow the steps below to configure and start the PHP-FPM service.
View the installed PHP-FPM version.
Your output should be similar to the one below:
Enable the PHP-FPM service to start at boot.
Your output should be similar to the one below:
Start the PHP-FPM service.
Your output should be similar to the one below:
View the PHP-FPM service status and verify that it's running.
Your output should be similar to the one below:
In this section you will configure PHP-FPM 7.4 by adjusting the default pool settings and socket permissions to optimize performance based on your server's available resources. Follow the steps below to configure the PHP-FPM pool configuration.
Navigate to the PHP-FPM configuration directory.
List the available files and verify that the www.conf file exists.
Your output should be similar to the one below:
Open the PHP-FPM www.conf configuration file using a text editor such as vim.
Locate the [www] pool configuration and verify that the following parameters are set. Adjust the values as needed to match your server's workload and resource limits.
Save and exit the configuration file.
In the above configuration:
[www]: Defines a pool named www. PHP-FPM can manage multiple pools, each with its own configuration block.user: Defines the system user that PHP-FPM will use to execute PHP scripts securely.group: Sets the system group under which PHP-FPM will run, helping control file and socket access.listen.owner: Ensures the Unix socket is owned by the correct user so that only authorized services can communicate with PHP-FPM.listen.group: Assigns group ownership of the socket to allow shared access with the web server.listen: Determines where PHP-FPM listens for FastCGI requests, typically from the web server, using a Unix socket or TCP address.listen.mode: Controls who can read/write to the socket, securing PHP-FPM communication against unauthorized access.pm: Specifies the strategy for managing worker processes, enabling dynamic adjustment to system load.pm.max_children: Prevents resource exhaustion by limiting the number of concurrent PHP worker processes.pm.start_servers: Reduces latency at startup by preloading a defined number of PHP workers.pm.min_spare_servers: Ensures a baseline number of idle workers is always ready to handle new requests.pm.max_spare_servers: Avoids unnecessary memory usage by limiting excess idle worker processes.Restart the PHP-FPM service to apply the changes.
Your output should be similar to the one below:
View that the PHP-FPM service is running.
Your output should be similar to the one below:
In this section, you will verify the successful installation of PHP 7.4 by testing the PHP Command Line Interface (CLI), running a simple PHP script, configuring the Apache web server to handle FastCGI requests using a UNIX socket file, and confirming that your system is running the correct PHP version. Follow the sections below to test the PHP installation.
To ensure PHP 7.4 is installed correctly, you can test it via the Command Line Interface (CLI). This section walks you through checking the installed PHP version and running a simple PHP script.
View the installed PHP version.
Your output should be similar to the one below:
Navigate to the user's home directory.
Create a test greet.php file to test the PHP CLI.
Add the following PHP content to the file.
Save and close the file.
Run the file using PHP CLI.
Your output should be similar to the one below:
After confirming that PHP 7.4 is working from the CLI, you can test PHP-FPM (FastCGI Process Manager) with Apache. This section walks you through configuring Apache to communicate with PHP-FPM via a UNIX socket and ensuring PHP scripts work properly on the web server.
Install the Apache web server.
Enable the Apache web server service to automatically start at boot.
Your output should be similar to the one below:
Start the Apache service.
Your output should be similar to the one below:
View the Apache web server service status.
Your output should be similar to the one below:
Open the Apache configuration file.
Enable the required modules by removing the # at the beginning of the following lines.
In the above configuration:
These modules are essential for integrating Apache with PHP-FPM over a UNIX socket or TCP.
Create a virtual host configuration.
Add the following content.
Save and exit the file.
Create a test PHP file.
Restart the PHP-FPM service.
View the PHP-FPM service status to verify it is running.
Your output should be similar to the one below:
Restart the Apache web server.
View the Apache web server service status.
Your output should be similar to the one below:
Visit the below URL in your browser to confirm the Vultr Greetings page displays.
You have successfully installed PHP 7.4 on FreeBSD 14.0 using the legacy FreeBSD Ports system, configured PHP-FPM for improved performance, and set up Apache to handle FastCGI requests using a UNIX socket. You tested the PHP installation via the PHP CLI and a simple PHP script, ensuring the correct PHP version was running. This setup is suitable for running legacy applications that require PHP 7.4, with PHP-FPM managing multiple processes to handle high traffic efficiently. However, since PHP 7.4 is deprecated and no longer receives security updates, it is advisable to plan a migration to a supported version, such as PHP 8.x, for better performance, security, and compatibility.
0 Comments
Be the first to comment and share your perspective with the community.