opt-php · PHP 5.6–8.6 for FreeBSD

A signed pkg repository with every PHP branch from 5.6 to 8.6, built from the deb.sury.org patch series and installed side by side under /opt/php/X.Y.

Provided as is, without warranty of any kind; builds and updates are best effort. See the disclaimer.

Ondřej Surý maintains, at deb.sury.org, PHP packages for Debian and Ubuntu that keep receiving security backports long after upstream end of life, plus the fixes needed to build old PHP against current OpenSSL 3, ICU and libxml2. opt-php takes those source packages and builds them for FreeBSD, so that legacy applications can run on a supported FreeBSD release next to current PHP.

Quick start

1. Fetch the repository signing key and check its fingerprint:

fetch -o /usr/local/etc/ssl/certs/opt-php.pub https://pkg.indeax.com/opt-php/opt-php.pub
sha256 /usr/local/etc/ssl/certs/opt-php.pub
# SHA256 = 1f307fb7616ea91db4be2dc6ee2108f9ba04a58f348262ef39a4df1d5de4bd93

2. Add the repository:

cat > /usr/local/etc/pkg/repos/opt-php.conf <<'EOF'
opt-php: {
  url: "https://pkg.indeax.com/opt-php/${ABI}/quarterly",
  signature_type: "pubkey",
  pubkey: "/usr/local/etc/ssl/certs/opt-php.pub",
  enabled: yes
}
EOF
pkg update

3. Install a PHP version with the extensions you need, and start PHP-FPM:

pkg install opt-php84 opt-php84-opcache opt-php84-mysqli opt-php84-pdo_mysql \
    opt-php84-mbstring opt-php84-intl opt-php84-gd opt-php84-curl opt-php84-zip

sysrc opt_php84_fpm_enable=YES
service opt_php84_fpm start

php8.4 -v
As on pkg.FreeBSD.org, the URL ends with the package branch: use the same branch as your FreeBSD-ports repository, so that opt-php is linked against the same library versions you get from FreeBSD. That is quarterly on a default FreeBSD install (as above); if you switched to latest, use /opt-php/${ABI}/latest instead. You can check yours with pkg -vv | grep url.

Versions

FreeBSD:15:amd64 · quarterly

URL https://pkg.indeax.com/opt-php/${ABI}/quarterly · 326 packages · full list

BranchPackageVersion (sury revision)ExtensionsFPM service
5.6opt-php565.6.40 (110)25opt_php56_fpm
7.0opt-php707.0.33 (98)24opt_php70_fpm
7.1opt-php717.1.33 (86)24opt_php71_fpm
7.2opt-php727.2.34 (71)25opt_php72_fpm
7.3opt-php737.3.33 (42)25opt_php73_fpm
7.4opt-php747.4.33 (38)25opt_php74_fpm
8.0opt-php808.0.30 (32)25opt_php80_fpm
8.1opt-php818.1.34 (15)25opt_php81_fpm
8.2opt-php828.2.36 (3)25opt_php82_fpm
8.3opt-php838.3.37 (3)25opt_php83_fpm
8.4opt-php848.4.28 (3)25opt_php84_fpm
8.5opt-php858.5.13 (3)24opt_php85_fpm
8.6opt-php868.6.0 (2)16opt_php86_fpm

FreeBSD:15:amd64 · latest

URL https://pkg.indeax.com/opt-php/${ABI}/latest · 326 packages · full list

BranchPackageVersion (sury revision)ExtensionsFPM service
5.6opt-php565.6.40 (110)25opt_php56_fpm
7.0opt-php707.0.33 (98)24opt_php70_fpm
7.1opt-php717.1.33 (86)24opt_php71_fpm
7.2opt-php727.2.34 (71)25opt_php72_fpm
7.3opt-php737.3.33 (42)25opt_php73_fpm
7.4opt-php747.4.33 (38)25opt_php74_fpm
8.0opt-php808.0.30 (32)25opt_php80_fpm
8.1opt-php818.1.34 (15)25opt_php81_fpm
8.2opt-php828.2.36 (3)25opt_php82_fpm
8.3opt-php838.3.37 (3)25opt_php83_fpm
8.4opt-php848.4.28 (3)25opt_php84_fpm
8.5opt-php858.5.13 (3)24opt_php85_fpm
8.6opt-php868.6.0 (3)16opt_php86_fpm

The fourth field of the package version is the deb.sury.org revision it was built from (for example 8.4.28.2 is PHP 8.4.28, sury revision 2). Both branches are built from the same deb.sury.org sources; they only differ in the FreeBSD libraries they are linked against.

PHP 5.6, 7.x, 8.0 and 8.1 are past their upstream end of life. Their security fixes are the backports published by deb.sury.org, on a best-effort basis and without any guarantee; plan to migrate those applications.

Packages

Core: opt-phpXY

CLI and PHP-FPM, with these extensions built in: bcmath, bz2, calendar, ctype, dom, exif, fileinfo, filter, ftp, hash, iconv, json, libxml, mysqlnd, openssl, pcre, pdo, phar, posix, session, shmop, simplexml, sockets, sysvmsg, sysvsem, sysvshm, tokenizer, xml, xmlreader, xmlwriter and zlib. PHP 8.5 and later also include opcache, which is no longer optional upstream.

Extensions: opt-phpXY-<name>

ExtensionNotes
opcacheUp to 8.4 (built into the core since 8.5).
mysqli, pdo_mysqlOn mysqlnd; default socket /tmp/mysql.sock.
mysqlThe old mysql_* API, PHP 5.6 only.
mbstring, intl, gd, curl, zip, soap, xslThe usual set for WordPress, PrestaShop and Magento (Magento 2 requires xsl).
sodiumPHP 7.2 and later.
gettext, gmp, sqlite3, pdo_sqlite
pcntl, readlineEnabled for the CLI only, never in PHP-FPM.
mcryptBundled up to 7.1, PECL from 7.2 (needed by Magento 1 and some PrestaShop 1.6 shops).
imapBundled up to 8.3, PECL from 8.4.
igbinary, redis, memcachedredis and memcached are built with igbinary support; redis also with lzf, lz4 and zstd (5.6: lzf only).
apcu, imagickimagick uses the official ImageMagick7-nox11 package.
xdebugFor development: it is enabled as soon as it is installed.

PECL extensions come from the deb.sury.org source package for each branch, so every PHP version gets the extension release that sury ships for it (for example phpredis 4.3 for 5.6 and 6.3 for 8.x).

Using it

Layout

/opt/php/8.4/bin/php                    CLI (also /usr/local/bin/php8.4, phpize8.4, php-config8.4)
/opt/php/8.4/sbin/php-fpm               PHP-FPM
/opt/php/8.4/etc/cli/php.ini            php.ini for the CLI
/opt/php/8.4/etc/cli/conf.d/*.ini       extensions loaded by the CLI
/opt/php/8.4/etc/fpm/php.ini            php.ini for PHP-FPM
/opt/php/8.4/etc/fpm/conf.d/*.ini       extensions loaded by PHP-FPM
/opt/php/8.4/etc/fpm/php-fpm.conf       global PHP-FPM settings
/opt/php/8.4/etc/fpm/pool.d/*.conf      pools (www.conf by default)
/usr/local/etc/rc.d/opt_php84_fpm       rc service
/var/run/php/php8.4-fpm.sock            default pool socket (owner www, mode 0660)
/var/log/php/php8.4-fpm.log             PHP-FPM log
/var/db/php/8.4/sessions                session.save_path

Configuration files are installed as samples (@sample): your changes are kept on upgrades. To disable an extension for one SAPI, comment out its line in etc/<sapi>/conf.d/NN-<name>.ini (deleting the file is undone by the next upgrade).

Web server

Point each site at the socket of the version it needs, for example with nginx:

location ~ \.php$ {
    fastcgi_pass   unix:/var/run/php/php8.4-fpm.sock;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

Several versions can run at once: enable opt_php56_fpm, opt_php74_fpm, opt_php84_fpm… and give each site the matching socket. The rc script also supports reload, configtest and logrotate.

Building other PECL extensions

Each version ships its phpize and php-config (phpize8.4, php-config8.4); use ./configure --with-php-config=/opt/php/8.4/bin/php-config. PHP 5.6–7.3 also need devel/libtool and devel/autoconf installed.

How it is built

Disclaimer

This repository is a best-effort service, without any warranty. The packages are provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non-infringement. In no event shall the authors or operators of opt-php be liable for any claim, damages or other liability arising from the use of these packages or of this repository.

Licenses and credits

PHP is distributed under the PHP License 3.01 and the Zend Engine under the Zend Engine License 2.00 (up to 8.5); since 8.6 both are under a single BSD-3-Clause license. This product includes PHP software, freely available from http://www.php.net/software/. This product includes the Zend Engine, freely available at http://www.zend.com/. The deb.sury.org packaging and patches are under the Expat (MIT) license. PECL extensions keep their own licenses (PHP 3.01; igbinary BSD-3-Clause; xdebug, the Xdebug License). Every package installs its licenses under /opt/php/X.Y/share/licenses/, and a NOTICE plus the Debian copyright file under /opt/php/X.Y/share/doc/<package>/.

opt-php is not an official deb.sury.org project and is not endorsed by Ondřej Surý, sury.org, The PHP Group or Zend Technologies. Please report problems with these packages to GitHub or [email protected], not to the deb.sury.org tracker. Many thanks to Ondřej Surý for maintaining the backports that make this possible; consider supporting his work.