OpenBSD - PHP 8.2

Page content

Running PHP on OpenBSD

yes, i know … it’s not rocket science .. but why not make a short post so other (or myself) can have a quick look if needed ?

pkg_info -Q php
pkg_add php--%8.2
pkg_add php-sqlite3--%8.2
pkg_add php-curl--%8.2

Set TimeZone

and allow short open tags

sed -i s'#date.timezone = UTC.*#date.timezone = Europe/Zurich#'  /etc/php-8.2.ini
sed -i s'#short_open_tag = Off.*#short_open_tag = On#'  /etc/php-8.2.ini

Install all Modules

if needed .. does not make sense for me :(

# get latest Version for 8.2
ver=$(pkg_info -Q php |grep "^php-8.2" |cut -d" " -f 1 |cut -d "-" -f 2); echo $ver

# add all Packages
for i in $(pkg_info -Q php |grep "${ver}" |grep -E -v "^debug-|installed"); do pkg_add $i; done

Enable Modules

cd /etc/php-8.2.sample
for i in *; do ln -sf /etc/php-8.2.sample/${i} /etc/php-8.2/; done

Enable and Start Service

rcctl enable php82_fpm
rcctl restart php82_fpm

Update nginx.conf

you should add something like this to your nginx.conf


    location ~ \.php$ {
        try_files      $uri $uri/ =404;
        fastcgi_pass   unix:run/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

PHP info

and the famous php info

cat << 'EOF' > info.php
<? phpinfo() ?>
EOF

Finally running …


Any Comments ?

sha256: 7d8197cafae41f82711440785e9366be476803d4fe83747d6b4b4f11448d8a4a