How to install PHP on NetBSD?

Español English

PHP 8.0 added new modern features such us: Union Types,Named arguments, Match expressions, Just In Time Compilation and others

Today we are going to install PHP 8.0 on NetBSD 9.1.

Links of interest:

Install PHP and PHP-FPM

PHP-FPM is used together with a web server like Apache or NGINX, PHP-FPM serves dynamic content, while the web server serve static content and act like a reverse proxy in front of PHP-FPM.

PHP-FPM introduces the concept of pools, each pool can receive connections on a TPC/IP (IP:Port) socket or on a UNIX socket, and can run under a different user and group also each pool has its configuration file, to install PHP and PHP-FPM execute the following command:

# pkgin install php80-fpm
calculating dependencies...done.

6 packages to install:
  php80-fpm-8.0.3nb5 readline-8.1 php-8.0.3 pcre2-10.36 libxml2-2.9.10nb3 xmlcatmgr-2.2nb1

0 to refresh, 0 to upgrade, 6 to install
10M to download, 69M to install

proceed ? [Y/n]

After the installation process finish, you can find the configuration files under this directory structure.

|-- php-fpm.conf
|-- php-fpm.d
|   `-- www.conf
|-- php.ini

Show installed version

# php -v 
PHP 8.0.3 (cli) (built: Mar 29 2021 07:45:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies

List modules

# php -m 
php -m
[PHP Modules]

Show all available modules:

# pkgin search '^php80\-'
php80-bz2-8.0.3      PHP extension for bzip2 compression
php80-calendar-8.0.3  PHP extension for calendar conversion support
php80-composer-2.0.11  Dependency Manager for PHP
php80-curl-8.0.3nb9  PHP extension for curl functions

To install a module execute:

# pkgin install php80-curl
calculating dependencies...done.

8 packages to install:
  php80-curl-8.0.3nb9 curl-7.76.0 nghttp2-1.43.0 libidn2-2.3.0 libunistring-0.9.10 python38-3.8.8
  libuuid-2.32.1 libffi-3.3nb4

0 to refresh, 0 to upgrade, 8 to install
39K to download, 105M to install

proceed ? [Y/n]

Manage the PHP-FPM service

In this section we learn how to start, restart and stop the php-fpm service, for this task we are going to use the excelent tools: init, rc and service.

Add init script

The php80-fpm package provides us and example script located under /usr/pkg/share/examples/rc.d/php_fpm and we can use it as our init script copying it to /etc/rc.d/php_fpm.

# cp -v /usr/pkg/share/examples/rc.d/php_fpm /etc/rc.d/
/usr/pkg/share/examples/rc.d/php_fpm -> /etc/rc.d/php_fpm

Automatic start

I love how *BSD handle services automatic start, simply add to the /etc/rc.conf file this line:


The above line instructs to the init system that the php_fpm will start automatically after a system reboot.

Check status

# service php_fpm status 
php_fpm is not running.


# service php_fpm start
Starting php_fpm.

Check the status again :

# service php_fpm status
php_fpm is running as pid 1995.


If you did any modification to the configuration files you need to refresh the changes with:

# service php_fpm restart
Stopping php_fpm.
Starting php_fpm.

In the next post we are going to show how to integrate PHP-FPM with NGINX.

YouTube video

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.