We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How To Install PHP 7.2 on FreeBSD 12

Learn how to – How To Install PHP 7.2 on FreeBSD 12.

Hello good folks. This month I decided to give FreeBSD a try and see if can use it as my blog hosting server. As part of learning, I’m writing this article on how to install  PHP 7.2 on FreeBSD 12.x.

For PHP 7.3, use: How to Install PHP 7.3 on FreeBSD 12

FreeBSD is a free and open-source Unix-like operating system which provides some good features such as preemptive multitasking, memory protection, virtual memory, support for jails, multi-user facilities, SMP support, Extensive security features e.t.c.

Follow the steps below to have PHP 7.2 installed on your FreeBSD server.

Step 1: Update ports tree

Start by updating your FreeBSD server Ports tree using the portsnap command:

$ jmutai@freebsd:~ % sudo su -
Password:
root@freebsd:~# portsnap fetch update
Looking up portsnap.FreeBSD.org mirrors... 5 mirrors found.
Fetching public key from ec2-ap-southeast-2.portsnap.freebsd.org... done.
Fetching snapshot tag from ec2-ap-southeast-2.portsnap.freebsd.org... done.
Fetching snapshot metadata... done.
Fetching snapshot generated at Sun Dec  9 00:19:28 UTC 2018:
Extracting snapshot... done.
Verifying snapshot integrity... done.
Fetching snapshot tag from ec2-ap-southeast-2.portsnap.freebsd.org... done.
Fetching snapshot metadata... done.
Updating from Sun Dec  9 00:19:28 UTC 2018 to Sun Dec  9 19:15:19 UTC 2018.
Fetching 5 metadata patches... done.
Applying metadata patches... done.
Fetching 0 metadata files... done.
Fetching 78 patches. 
(78/78) 100.00%  done.                                   
done.
Applying patches... 
done.
Fetching 3 new ports or files... done.
/usr/ports was not created by portsnap.
You must run 'portsnap extract' before running 'portsnap update'.

When running Portsnap for the first time, you need to extract the snapshot into /usr/ports:

# portsnap extract

You should get the message below at the end of the output.

Building new INDEX files... done.

Confirm that everything is up to date.

# portsnap fetch update
Looking up portsnap.FreeBSD.org mirrors... 5 mirrors found.
Fetching snapshot tag from ec2-eu-west-1.portsnap.freebsd.org... done.
Latest snapshot on server matches what we already have.
No updates needed.
Ports tree is already up to date.

By default, the Ports Collection itself is stored as a subdirectory of /usr/ports.

Step 2: Install PHP 7.2 on FreeBSD

There are two ways you can install PHP 7.2 on FreeBSD.

  1. Install from Binary packages
  2. Install from source using ports

Method 1: Install PHP 7.2 on FreeBSD from binary

Download and install pkg if not already done:

# /usr/sbin/pkg
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:13:amd64/latest, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
Installing pkg-1.10.5_5...
the most recent version of pkg-1.10.5_5 is installed

Then install PHP 7.2

# pkg install php72
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:
	php72: 7.2.10
	libargon2: 20171227_1
	pcre: 8.42

Number of packages to be installed: 3

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

Proceed with this action? [y/N]: y
[1/3] Fetching php72-7.2.10.txz: 100%    3 MiB 192.9kB/s    00:18    
[2/3] Fetching libargon2-20171227_1.txz: 100%   64 KiB  65.3kB/s    00:01    
[3/3] Fetching pcre-8.42.txz: 100%    1 MiB  44.9kB/s    00:28    
Checking integrity... done (0 conflicting)
[1/3] Installing libargon2-20171227_1...
[1/3] Extracting libargon2-20171227_1: 100%
[2/3] Installing pcre-8.42...
[2/3] Extracting pcre-8.42: 100%
[3/3] Installing php72-7.2.10...
[3/3] Extracting php72-7.2.10: 100%

Confirm PHP version installed.

# php -v
PHP 7.2.10 (cli) (built: Dec  1 2018 01:31:03) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Install PHP 7.2 Extensions on FreeBSD

Extensions can be installed using syntaxphp72-<extension>. See example below which installs standard extensions.

# pkg install php72-curl php72-extensions php72-json php72-xml 
php72-zip php72-intl php72-mysqli php72-pdo_mysql php72-pdo 
php72-pear php72-soap php72-phar

You can view loaded modules with:

# php -m

Method 1: Install PHP 7.2 on FreeBSD from ports

Change your working directory to PHP 7.2 ports folder

# cd /usr/ports/lang/php72

Then build and install PHP 7.2

# make install clean

To  install PHP 7.2 extensions on FreeBSD, do it like below:

# cd /usr/ports/lang/php72-extensions/
# make install clean

That’s all. You now have PHP 7.2 installed on your FreeBSD server.

Cart

Your Cart is Empty

Back To Shop