Install PHP Hypertext Preprocessor, MOD_PHP & PHP Extensions

Synopsis:

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. PHP 5.6 and 7.0 became EoL (end of life) at the end of 2018. Version 7.1 was supported until the end of 2019. PHP 7.2 was supported until the end on 2020. PHP 7.4 became EoL at the end of 2021. PHP 8.0 became EoL in Nov. 2022. PHP 8.1 became end of active support in Nov. 2023. PHP 8.2 will still have security updates until the end of 2026, while PHP 8.3 will have security updates until the end of 2027. It is therefore suggested to install PHP 8.2 or 8.3 and this example will install 8.2.

I. Install PHP

Package Method:

#
# pkg install -y php82
#

Ports Method:

#
# cd /usr/ports/lang/php82 && make install clean
#
The options screen will be displayed.
┌───────────────────────┤php82-8.2.20├────────────────────────┐
│ 'F1' for Ports Collection help.                             │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │new [X] CGI     Build CGI version                        │ │
│ │new [X] CLI     Build CLI version                        │ │
│ │new [ ] DEBUG   Build with debugging support             │ │
│ │new [X] DTRACE  Build with DTrace probes                 │ │
│ │new [X] EMBED   Build embedded library                   │ │
│ │new [X] FPM     Build FPM version                        │ │
│ │new [X] IPV6    IPv6 protocol support                    │ │
│ │new [X] LINKTHR Link thread lib (for threaded extensions)│ │
│ │new [X] MYSQLND Build with MySQL Native Driver           │ │
│ │new [X] PCRE    Use system pcre instead of bundled one   │ │
│ │new [ ] PHPDBG  Interactive PHP debugger                 │ │
│ │new [ ] ZTS     Force Zend Thread Safety (ZTS) build     │ │
│ └─────────────────────────────────────────────────────────┘ │
├─────────────────────────────────────────────────────────────┤
│                    [  OK  ]     [Cancel]                    │
└─────────────────────────────────────────────────────────────┘
Leave all options as is. B>II. Install MOD_PHP

Package Method:

#
# pkg install -y mod_php82
#

Ports Method:

#
# cd /usr/ports/www/mod_php82 && make install clean
#
The options screen will be displayed.
 ┌─────────────────────────┤mod_php82-8.2.20├─────────────────────────┐
 │ 'F1' for Ports Collection help.                                    │
 │ ┌────────────────────────────────────────────────────────────────┐ │
 │ │new [ ] AP2FILTER Use Apache 2.x filter interface (experimental)│ │
 │ │new [ ] DEBUG     Build with debugging support                  │ │
 │ │new [X] DTRACE    Build with DTrace probes                      │ │
 │ │new [X] IPV6      IPv6 protocol support                         │ │
 │ │new [X] LINKTHR   Link thread lib (for threaded extensions)     │ │
 │ │new [X] MYSQLND   Build with MySQL Native Driver                │ │
 │ │new [X] PCRE      Use system pcre instead of bundled one        │ │
 │ │new [ ] PHPDBG    Interactive PHP debugger                      │ │
 │ │new [ ] ZTS       Force Zend Thread Safety (ZTS) build          │ │
 │ └────────────────────────────────────────────────────────────────┘ │
 ├────────────────────────────────────────────────────────────────────┤
 │                        [  OK  ]     [Cancel]                       │
 └────────────────────────────────────────────────────────────────────┘
Use the up/down arrow keys to select or deselect an option, press [space] to modify the option. Press [tab] to select 'OK' and press [Enter].
Leave options:

Now the actual installation will proceed. The process takes around 40 minutes to compile and install the program on a Celeron 1.6G system.

Remember to enable PHP in Apache by creating the php.conf file, with the below contents, and placing the file in the /usr/local/etc/apache24/Includes/ folder.

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>
III. PHP.INI configuration
#
# cd /usr/local/etc
# cp php.ini-production php.ini
#

IV. Install PHP82 Extensions

Ports Method:

#
# cd /usr/ports/lang/php82-extensions && make install clean
#

Add the following compile options that support most common CMS such as Wordpress, Joomla, Drupal, Gallery, etc.

BZ2 CTYPE CURL DOM EXIF FILEINFO FILTER GD GETTEXT ICONV INTL JSON LDAP MBSTRING MYSQLI OPCACHE OPENSSL PDF PDO PDO_MYSQL PDO_SQLITE PHAR POSIX SESSION SIMPLEXML SOCKETS SODIUM SQLITE3 TIDY TOKENIZER XML XMLREADER XMLWRITER ZIP ZLIB (support phpMyAdmin, Joomla and other CMS)

The compile process for PHP extensions will take well over one hour to compile and install the programs on the Celeron 1.6G system. In a FAMP (FreeBSD Apache MySQL PHP) system, this compile will be the longest and most stressful on the hardware.


Package method:

Each extension must be individually installed, one-by-one. Follow this example:
#
# pkg install -y php82-bz2
#