
PHP (Hypertext Preprocessor) is a widely used server-side scripting language for building dynamic web applications. PHP 5.6 is an older, end-of-life release that is still required for maintaining certain legacy applications that depend on deprecated features or extensions. It lacks the security and performance improvements of newer PHP versions but remains in use where application upgrades are not yet possible.
This article explains how to install PHP 5.6 and PHP-FPM on FreeBSD 14.0 by compiling from source, as PHP 5.6 is unavailable in the default pkg repositories. It also covers testing the setup with a basic PHP file.
Before you begin, you need to:
This section covers installing the necessary build tools and libraries for compiling PHP 5.6.
Update the package index.
Install build dependencies.
Due to changes in system libraries, PHP 5.6 requires compatibility patches to compile on FreeBSD 14.0. This section explains how to compile PHP 5.6 from the source with the required dependencies.
Switch to the /tmp directory.
Download the PHP 5.6.40 source code, which is the final release of the 5.6 branch. You can find additional PHP 5.x versions at the PHP Museum archive.
Extract the PHP source.
Enter the PHP directory.
Apply compatibility patches for FreeBSD 14. PHP 5.6 has compatibility issues with modern libxml2 in FreeBSD 14. Apply the following fixes to resolve compilation errors.
Fix ATTRIBUTE_UNUSED macro compatibility. This patch removes an unnecessary macro that causes an error with modern compilers.
Fix xmlStructuredErrorFunc type casting. This patch adds an explicit type cast to resolve a function pointer mismatch.
Fix xmlGetLastError return type. This patch adds an explicit type cast to the return value of xmlGetLastError to match the newer libxml2 library's definition.
Configure PHP with FPM support and disable DOM.
The --disable-dom flag avoids compilation errors due to type mismatches with modern libxml2. Omit this if DOM support is required and you've resolved the dependency manually.
Compile PHP.
Install PHP.
Verify PHP installation.
This section covers testing the PHP CLI using the built-in development server.
Create a new sample test file named info.php.
Add the following PHP code to the file.
Save and exit the file.
Launch the PHP built-in server.
This command starts the PHP built-in web server. The -S flag specifies the address and port to listen on. 0.0.0.0 means it will listen on all available network interfaces. The -t flag sets the document root to the /tmp directory, where the info.php file is located.
In your browser, visit http://SERVER-IP:8080/info.php.
You should see the PHP configuration page. When you are done, press Ctrl + C to stop the server.
Remove the test file after verification.
This section explains how to install and configure PHP-FPM.
Return to the PHP source directory.
The PHP source code includes two sample configuration files, php.ini-development and php.ini-production. Copy the production PHP configuration file.
Create PHP-FPM configuration directory.
Create the main PHP-FPM configuration file.
Add the following content.
Save and close the file.
Create the PHP-FPM pool configuration file.
Add the following content.
Save and close the file.
Add PHP to PATH.
Reload the shell configuration.
Create a PHP-FPM user.
Create the rc.d directory if it doesn't exist.
Create a service script for PHP-FPM.
Add the following service script.
Save and close the file.
Set permissions for the service script.
Enable PHP-FPM.
Start PHP-FPM.
Verify PHP-FPM status.
This section covers testing PHP 5.6 by creating a sample file and accessing it via Nginx.
Install Nginx.
Create the web root directory.
Configure Nginx to process PHP files.
Find the default server block inside the http {} block. Make the following changes:
Set the server_name to your server's IP address or domain name.
Change the root directive to /usr/local/www/php56, which is the directory you created earlier.
Add index.php to the index directive.
Add the following location block to handle PHP files:
Save and close the file.
Test Nginx configuration.
Enable Nginx.
Start Nginx.
Create a test PHP file.
Add the following PHP code to the file.
Save and close the file.
Visit http://SERVER-IP/ in your browser to view PHP information.
You should see the PHP information page displaying PHP 5.6.40 with details about the installation, loaded extensions, and configuration.
PHP 5.6 reached end-of-life in December 2018 and no longer receives security updates. Use it only for legacy applications that cannot be upgraded.
This article explained how to install PHP 5.6 and PHP-FPM on FreeBSD 14.0 by compiling from the source and applying necessary compatibility patches. You configured Nginx to process PHP files and verified the setup with a test page. To extend this setup, consider adding more PHP extensions or integrating it with a database like MySQL. For more details, check the PHP documentation.
0 Comments
Be the first to comment and share your perspective with the community.