Install PHP 7.4 on FreeBSD 12

Last Updated:

In this guide, we are going to learn how to install PHP 7.4 on FreeBSD 12. PHP 7.4, which marks the fourth feature update to the PHP 7 series has just been released as of this writing. It comes with a lot improvements and new features as described on the PHP 7.4 new features page.

You can also check the new changes on PHP 7.4 on PHP 7.4 Changelog.

Installing PHP 7.4 on FreeBSD 12

Run System Update

To begin, update your system packages.

pkg update
pkg upgrade

Install PHP 7.4 from FreeBSD Repositories

There are two ways in which PHP 7.4 can be installed on a FreeBSD 12 box; from FreeBSD ports or FreeBSD package repositories. In this guide, PHP 7.4 is installed from FreeBSD package repos by executing the command below;

pkg install php74
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 3 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
 php74: 7.4.0
 libargon2: 20190702
 pcre2: 10.33

Number of packages to be installed: 3

The process will require 35 MiB more space.
5 MiB to be downloaded.

Proceed with this action? [y/N]: y

Verifying Installed PHP Version on FreeBSD 12

The command above installed PHP 7.4. However, you can still verify this by running either of the commands below;

pkg info php74
Name           : php74
Version        : 7.4.0
Installed on   : Fri Jun 21 20:38:37 2019 EAT
Origin         : lang/php74
Architecture   : FreeBSD:12:amd64
Prefix         : /usr/local
Categories     : devel lang www
Licenses       : PHP301
Maintainer     : [email protected]
WWW            :
Comment        : PHP Scripting Language
Options        :
	CGI            : on
	CLI            : on
	DEBUG          : off
	DTRACE         : on
	EMBED          : on
	FPM            : on
	IPV6           : on
	LINKTHR        : on
	MYSQLND        : on
	PHPDBG         : off
	ZTS            : off
Shared Libs required:
Shared Libs provided:
Annotations    :
	FreeBSD_version: 1200086
	cpe            : cpe:2.3:a:php:php:7.4.0:::::freebsd12:x64
	repo_type      : binary
	repository     : FreeBSD
Flat size      : 27.5MiB
Description    :
PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open
Source general-purpose scripting language that is especially suited for
Web development and can be embedded into HTML.  Its syntax draws upon C,
Java, and Perl, and is easy to learn.  The main goal of the language is to
allow web developers to write dynamically generated webpages quickly, but
you can do much more with PHP.



php -v
PHP 7.4.0 (cli) (built: Nov 30 2019 01:12:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

If you have web server installed, you can similarly verify PHP 7.4 installation by creating a PHP test file as shown below.

For example, if you have Apache installed, simply create a PHP 7.4 test file on the document root folder as follows.

echo '<?php phpinfo(); ?>' > /usr/local/www/apache24/data/info.php

Note that Apache can only process PHP files. Hence, ensure that you have mod_php modules installed.

pkg install mod_php74

Next, you need to tell Apache to process PHP files by creating a php.conf configuration file under /usr/local/etc/apache24/Includes/ with the following contents;

vim /usr/local/etc/apache24/Includes/php.conf
<IfModule dir_module>
    DirectoryIndex index.php index.html
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source

Save the file and restart Apache for the changes to take effect.

service apache24 restart

On the browser, enter the address, http://server_IP_address/info.php to verify PHP installation.

php 74

Install PHP Modules/Extensions on FreeBSD 12

If you need to extend the functionality of PHP on FreeBSD 12 box, you can install the modules/extensions by running the command;

pkf install php74-module-name

Where module-name represents the PHP 7.4 module or extension that you need to install.

For example, the command below installs various PHP 7.4 modules/extensions for various functionalities.

pkg install php74 php74-mysqli php74-mbstring php74-zlib php74-curl php74-gd php74-json
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 11 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	php74-mysqli: 7.4.0
	php74-mbstring: 7.4.0
	php74-zlib: 7.4.0
	php74-curl: 7.4.0
	php74-gd: 7.4.0
	php74-json: 7.4.0
	oniguruma: 6.9.3
	curl: 7.66.0
	libgd: 2.2.5_2,1
	webp: 1.0.3_1
	giflib: 5.1.9

Number of packages to be installed: 11

The process will require 13 MiB more space.
3 MiB to be downloaded.

Proceed with this action? [y/N]: y


Well, that marks the end of our simple tutorial. If you have any web application that you need to run on a FreeBSD 12 box, you check our other articles on how to setup LAMP or LEMP stack by following the links below;

Install Nginx, MySQL, PHP (FEMP) Stack on FreeBSD 12

Install Apache, MySQL, PHP (FAMP) Stack on FreeBSD 12

Other FreeBSD 12 tutorials

Install and Configure OpenVPN Server FreeBSD 12

Install and Configure Telegraf on FreeBSD 12

How to Install phpMyAdmin on FreeBSD 12

How to Install FreeBSD 12 on VirtualBox

Install phpMyAdmin with Nginx on FreeBSD 12


We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
I am the Co-founder of, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

1 thought on “Install PHP 7.4 on FreeBSD 12”

  1. Hello,

    Thanks for this tutorial. I spend a day to find the solution, and it’s you articl that give it to me.
    I install in FreeNas in a jail a postgreSQL serveur, and i would like to administrate the database by adding apache, and phpPgAdmin on the same server. But the PHP don’t excute.

    It was missing a package “mod_php74” for working.

    So thank for this article !


Leave a Comment