---
title: How to Install PHP 5.6 on FreeBSD 14.0
url: https://docs.vultr.com/how-to-install-php-5-6-on-freebsd-14-0
description: Learn how to install PHP 5.6 on FreeBSD 14.0 with step-by-step instructions. This guide covers installation methods, configuration, and troubleshooting tips.
publish_date: 2025-12-05T17:01:20.854848Z
last_updated: 2025-12-05T17:18:04.466042Z
author: José Rafael Gutierrez
header_image: https://lhr1.vultrobjects.com/docs-main-doc-assets-1/2406/304a93fb-ad63-4567-b2dc-55a8b380d9e5.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

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.

## Prerequisites

Before you begin, you need to:

* Have access to a [FreeBSD 14.0](https://www.vultr.com/servers/freebsd/) as a non-root user with sudo privileges.

## Install Required Dependencies

This section covers installing the necessary build tools and libraries for compiling PHP 5.6.

1. Update the package index.

    ```console
    $ sudo pkg update
    ```

1. Install build dependencies.

    ```console
    $ sudo pkg install -y gcc autoconf libxml2 curl png freetype2 gmp readline libxslt icu
    ```

## Compile and Install PHP 5.6

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.

1. Switch to the `/tmp` directory.

    ```console
    $ cd /tmp
    ```

1. 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](https://www.php.net/releases/).

    ```console
    $ fetch https://museum.php.net/php5/php-5.6.40.tar.gz
    ```

1. Extract the PHP source.

    ```console
    $ tar -xzf php-5.6.40.tar.gz
    ```

1. Enter the PHP directory.

    ```console
    $ cd php-5.6.40
    ```

1. 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.

    1. Fix `ATTRIBUTE_UNUSED` macro compatibility. This patch removes an unnecessary macro that causes an error with modern compilers.

        ```console
        $ sed -i.bak 's/int compression ATTRIBUTE_UNUSED)/int compression)/' ext/libxml/libxml.c
        ```

    1. Fix `xmlStructuredErrorFunc` type casting. This patch adds an explicit type cast to resolve a function pointer mismatch.

        ```console
        $ sed -i.bak 's/xmlSetStructuredErrorFunc(NULL, php_libxml_structured_error_handler);/xmlSetStructuredErrorFunc(NULL, (xmlStructuredErrorFunc)php_libxml_structured_error_handler);/' ext/libxml/libxml.c
        ```

    1. 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.

        ```console
        $ sed -i.bak 's/error = xmlGetLastError();/error = (xmlErrorPtr)xmlGetLastError();/' ext/libxml/libxml.c
        ```

1. Configure PHP with FPM support and disable DOM.

    ```console
    $ ./configure --prefix=/usr/local/php-5.6.40 --enable-mbstring --with-pdo-mysql --with-mysqli --enable-fpm --disable-dom
    ```

    > [!NOTE]
    > 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.

1. Compile PHP.

    ```console
    $ make -j$(sysctl -n hw.ncpu)
    ```

1. Install PHP.

    ```console
    $ sudo make install
    ```

1. Verify PHP installation.

    ```console
    $ /usr/local/php-5.6.40/bin/php -v
    ```

## Quick Test with PHP Built-in Server

This section covers testing the PHP CLI using the built-in development server.

1. Create a new sample test file named `info.php`.

    ```console
    $ vi /tmp/info.php
    ```

1. Add the following PHP code to the file.

    ```php
    <?php phpinfo(); ?>
    ```

    Save and exit the file.

1. Launch the PHP built-in server.

    ```console
    $ /usr/local/php-5.6.40/bin/php -S 0.0.0.0:8080 -t /tmp
    ```

    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.

1. In your browser, visit `http://SERVER-IP:8080/info.php`.

    ![php test ok](https://lhr1.vultrobjects.com/docs-main-doc-assets-1/2406/a6e949f8-46f0-41b0-90f6-9c951cc81b32.png)

    You should see the PHP configuration page. When you are done, press :key_Ctrl: + :key_C: to stop the server.    

1. Remove the test file after verification.

    ```console
    $ sudo rm /tmp/info.php
    ```

## Compile and Install PHP 5.6 FPM

This section explains how to install and configure PHP-FPM.

1. Return to the PHP source directory.

    ```console
    $ cd /tmp/php-5.6.40
    ```

1. The PHP source code includes two sample configuration files, `php.ini-development` and `php.ini-production`. Copy the production PHP configuration file.

    ```console
    $ sudo cp php.ini-production /usr/local/php-5.6.40/lib/php.ini
    ```

1. Create PHP-FPM configuration directory.

    ```console
    $ sudo mkdir -p /usr/local/php-5.6.40/etc/php-fpm.d
    ```

1. Create the main PHP-FPM configuration file.

    ```console
    $ sudo vi /usr/local/php-5.6.40/etc/php-fpm.conf
    ```

1. Add the following content.

    ```ini
    [global]
    pid = /var/run/php56-fpm.pid
    error_log = /var/log/php56-fpm.log

    include=/usr/local/php-5.6.40/etc/php-fpm.d/*.conf
    ```

    Save and close the file.

1. Create the PHP-FPM pool configuration file.

    ```console
    $ sudo vi /usr/local/php-5.6.40/etc/php-fpm.d/www.conf
    ```

1. Add the following content.

    ```ini
    [www]
    user = www
    group = www
    listen = 127.0.0.1:9000
    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
    ```

    Save and close the file.

1. Add PHP to PATH.

    ```console
    $ echo 'PATH="/usr/local/php-5.6.40/bin:$PATH"' >> ~/.shrc
    ```

1. Reload the shell configuration.

    ```console
    $ . ~/.shrc
    ```

1. Create a PHP-FPM user.

    ```console
    $ sudo pw user show www || sudo pw user add -n www -s /sbin/nologin -c "PHP-FPM User"
    ```

1. Create the `rc.d` directory if it doesn't exist.

    ```console
    $ sudo mkdir -p /usr/local/etc/rc.d
    ```

1. Create a service script for PHP-FPM.

    ```console
    $ sudo vi /usr/local/etc/rc.d/php56_fpm
    ```

1. Add the following service script.

    ```ini
    #!/bin/sh
    #
    # PROVIDE: php56_fpm
    # REQUIRE: LOGIN
    # KEYWORD: shutdown

    . /etc/rc.subr

    name="php56_fpm"
    rcvar="php56_fpm_enable"

    start_cmd="php56_fpm_start"
    stop_cmd="php56_fpm_stop"
    status_cmd="php56_fpm_status"

    php56_fpm_start() {
        if [ -x "/usr/local/php-5.6.40/sbin/php-fpm" ]; then
            echo "Starting php56-fpm."
            /usr/local/php-5.6.40/sbin/php-fpm \
                -c /usr/local/php-5.6.40/lib/php.ini \
                --fpm-config /usr/local/php-5.6.40/etc/php-fpm.conf
            sleep 1
        else
            echo "Error: /usr/local/php-5.6.40/sbin/php-fpm not found or not executable."
            exit 1
        fi
    }

    php56_fpm_stop() {
        if [ -f "/var/run/php56-fpm.pid" ]; then
            echo "Stopping php56-fpm."
            kill -TERM "$(cat /var/run/php56-fpm.pid)"
        else
            echo "php56-fpm is not running (PID file not found)."
        fi
    }

    php56_fpm_status() {
        if [ -f "/var/run/php56-fpm.pid" ]; then
            _pid="$(cat /var/run/php56-fpm.pid)"
            if ps -p "$_pid" > /dev/null; then
                echo "php56_fpm is running as pid $_pid."
            else
                echo "php56_fpm is not running (PID file exists but process is gone)."
            fi
        else
            echo "php56_fpm is not running."
        fi
    }

    load_rc_config $name
    run_rc_command "$@"
    ```

    Save and close the file.

1. Set permissions for the service script.

    ```console
    $ sudo chmod +x /usr/local/etc/rc.d/php56_fpm
    ```

1. Enable PHP-FPM.

    ```console
    $ sudo sysrc php56_fpm_enable="YES"
    ```

1. Start PHP-FPM.

    ```console
    $ sudo service php56_fpm start
    ```

1. Verify PHP-FPM status.

    ```console
    $ sudo service php56_fpm status
    ```

## Test and Use PHP 5.6

This section covers testing PHP 5.6 by creating a sample file and accessing it via Nginx.

1. Install Nginx.

    ```console
    $ sudo pkg install -y nginx
    ```

1. Create the web root directory.

    ```console
    $ sudo mkdir -p /usr/local/www/php56
    ```

1. Configure Nginx to process PHP files.

    ```console
    $ sudo vi /usr/local/etc/nginx/nginx.conf
    ```

1. 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:

        ```ini
        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
        ```

        Save and close the file.

1. Test Nginx configuration.

    ```console
    $ sudo nginx -t
    ```

1. Enable Nginx.

    ```console
    $ sudo sysrc nginx_enable="YES"
    ```

1. Start Nginx.

    ```console
    $ sudo service nginx start
    ```

1. Create a test PHP file.

    ```console
    $ sudo vi /usr/local/www/php56/index.php
    ```

1. Add the following PHP code to the file.

    ```php
    <?php phpinfo(); ?>
    ```

    Save and close the file.

1. Visit `http://SERVER-IP/` in your browser to view PHP information.

    ![php is ready](https://lhr1.vultrobjects.com/docs-main-doc-assets-1/2406/751a6b06-1feb-4c31-aa72-aace9bd9a2fd.png)

    You should see the PHP information page displaying PHP 5.6.40 with details about the installation, loaded extensions, and configuration.

> [!WARNING]
> 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.

## Conclusion

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](https://www.php.net/docs.php).
