PHP 8.0 on OpenBSD 6.9

Page content

OpenBSD 6.9 and PHP 8 is out … Why not give a try ?

list packages

what PHP Packages are available with Version 6.9 ?

root@host # pkg_info -Q php |grep '\-8'
php-8.0.3
php-apache-8.0.3
php-bz2-8.0.3
php-cgi-8.0.3
php-curl-8.0.3
php-dba-8.0.3
php-dbg-8.0.3
php-enchant-8.0.3
php-gd-8.0.3
php-gmp-8.0.3
php-imap-8.0.3
php-intl-8.0.3
php-ldap-8.0.3
php-mysqli-8.0.3
php-odbc-8.0.3
php-pcntl-8.0.3
php-pdo_dblib-8.0.3
php-pdo_mysql-8.0.3
php-pdo_odbc-8.0.3
php-pdo_pgsql-8.0.3
php-pdo_sqlite-8.0.3
php-pgsql-8.0.3
php-pspell-8.0.3
php-shmop-8.0.3
php-snmp-8.0.3
php-soap-8.0.3
php-sqlite3-8.0.3
php-tidy-8.0.3
php-xsl-8.0.3
php-zip-8.0.3

Install and Configure Nginx

add nginx, php8

add webserver, php8 and enable the services

pkg_add nginx php--%8.0
rcctl enable nginx php80_fpm

edit php.ini

set timezone and short_open_tags

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

nginx.conf

create directories and replace nginx.conf

# create folders
mkdir -p /etc/nginx/sites/
mkdir -p /var/www/virtual/add-your-server-here
mkdir -p /var/log/nginx{,-nossl}

# backup default config
mv /etc/nginx/nginx.conf{,.default}

# replace nginx.conf
cat << 'EOF' > /etc/nginx/nginx.conf
worker_processes  1;

worker_rlimit_nofile 1024;

events {
  worker_connections  800;
}

http {
  include       mime.types;
  default_type  application/octet-stream;
  index         index.php index.html index.htm;

  keepalive_timeout  65;

  server_tokens off;

  proxy_cache_valid any 0s;

  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

  # TLS Stuff, https://www.englert.one/tls1-3-nginx-debian-10-konfigurieren
  ssl_ciphers                 ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
  ssl_prefer_server_ciphers   on;
  ssl_protocols               TLSv1.2 TLSv1.3;
  ssl_session_cache           shared:SSL:10m;
  ssl_session_timeout         5m;

  include /etc/nginx/sites/*.conf;
}
EOF

Default Website (.conf)

add Website for Testing our PHP Setup

cat << 'EOF' > /etc/nginx/sites/default.conf
server {

  listen        80;
  listen        [::]:80;
  server_name   add-your-server-here www.add-your-server-here;

  access_log    /var/log/nginx-nossl/add-your-server-here.log main;
  error_log     /var/log/nginx-nossl/add-your-server-here-error.log;

  root          /var/www/virtual/add-your-server-here;

  index         index.php index.html index.htm;

  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;
  }
}
EOF

stop / disable php 7.4

if you upgraded from previous version

rcctl stop php74_fpm
rcctl disable php74_fpm

start / restart services

finally, start the services

nginx -t && rcctl restart nginx php80_fpm

phpinfo

create the famous phphinfo page

cat << 'EOF' > /var/www/virtual/add-your-server-here/index.php
<? phpinfo() ?>
EOF

Check Page

open your page: https://ip-of-your-server and you should get somethink like this:

php8

Install Module

pkg_add php-sqlite3-8.0.9

Activate Module

list all available modules and symlink all you want

# ls /etc/php-*
/etc/php-8.0.ini  /etc/php-fpm.conf

/etc/php-8.0:

/etc/php-8.0.sample:
opcache.ini sqlite3.ini

/etc/php-fpm.d:

# ln -sf /etc/php-8.0.sample/sqlite3.ini /etc/php-8.0/

Restart Service

nginx -t && rcctl restart nginx php80_fpm

and check Status Page again :)

php8

You should repeat this Step with all Modules you need …

for the lazy ones …

Install all Modules

for i in `pkg_info -Q php |grep 8.0.9|grep -v -E "debug-|installed"`; do pkg_add $i; done
cd /etc/php-8.0.sample
for i in *; do ln -sf /etc/php-8.0.sample/$i /etc/php-8.0/; done
nginx -t && rcctl restart nginx php80_fpm

Any Comments ?

sha256: f29d2e148164b6fe76f71a9736c2c90eabd5903066984f913afe37311f97a729