PHP 8.3.4 Released!

Installationshinweise für OpenBSD

Dieser Abschnitt enthält Hinweise und Tipps zur Installation von PHP unter » OpenBSD.

Verwendung von Paketen

Binärpakete zu verwenden, um PHP auf OpenBSD zu installieren, ist die empfohlene und zugleich einfachste Methode. Die verschiedenen Module sind vom Kernpaket getrennt und können unabhängig voneinander installiert und entfernt werden. Die benötigten Dateien finden Sie auf Ihrer OpenBSD-CD oder auf der FTP-Seite.

Das wichtigste Paket, das Sie installieren müssen, ist php; es enthält die Basissoftware (plus fpm, gettext und iconv) und steht möglicherweise in mehreren Versionen zur Auswahl. Weiter geht es mit den Modulpaketen, wie php-mysqli oder php-imap. Um diese Module in Ihrer php.ini zu aktivieren oder zu deaktivieren, müssen Sie den Befehl phpxs verwenden.

Beispiel #1 Beispiel für die Installation von OpenBSD-Paketen

# pkg_add php
# pkg_add php-apache
# pkg_add php-mysqli
  (Installation der PEAR-Bibliotheken)
# pkg_add pear

Befolgen Sie die Anweisungen, die bei jedem Package angegeben werden!

  (um Pakete zu entfernen)
# pkg_delete php
# pkg_delete php-apache
# pkg_delete php-mysqli
# pkg_delete pear

Weitere Informationen über OpenBSD-Binärpakete finden Sie in der Manpage » packages(7).

Verwendung von Ports

Sie können PHP auch aus dem Quelltext kompilieren, indem Sie den » Ports-Tree verwenden. Dies ist jedoch nur für Benutzer empfehlenswert, die mit OpenBSD vertraut sind. Der PHP-Port ist in core und extensions aufgeteilt. Die extensions erzeugen Unterpakete für alle unterstützten PHP-Module. Wenn Sie manche dieser Module nicht erstellen wollen, verwenden Sie den FLAVOR no_*. Um zum Beispiel die Erstellung des imap-Moduls zu überspringen, setzen Sie den FLAVOR auf no_imap.

Häufige Probleme

  • Apache und Nginx sind unter OpenBSD nicht mehr die Standard-Server, können aber beide problemlos über Ports und Pakete installiert werden. Der neue Standard-Server wird einfach als "httpd" bezeichnet.
  • Die Standardinstallation von httpd läuft in einem » chroot(2)-Jail, das den Zugriff von PHP-Skripten auf Dateien unter /var/www beschränkt. Sie müssen daher das Verzeichnis /var/www/tmp erstellen, in dem PHP-Session-Dateien gespeichert werden, oder ein alternatives Session-Backend verwenden. Außerdem müssen die Datenbank-Sockets innerhalb des Jails platziert werden oder auf der localhost-Schnittstelle lauschen. Wenn Sie Netzwerkfunktionen verwenden, müssen einige Dateien aus /etc wie /etc/resolv.conf und /etc/services nach /var/www/etc kopiert werden. Das PEAR-Paket von OpenBSD installiert sich automatisch in die richtigen chroot-Verzeichnisse.
  • Das OpenBSD-Paket für die Erweiterung » gd benötigt Xorg, um installiert zu werden. Wenn es nicht bereits bei der Basisinstallation durch Hinzufügen des xbase.tgz-Dateisets installiert wurde, kann es auch nachträglich hinzugefügt werden (siehe » OpenBSD FAQ#4).
add a note

User Contributed Notes 6 notes

up
18
Anonymous
2 years ago
UPDATE: OpenBSD 6.9:

- The package "php-fpm" no longer exists. It's the default, so you can just install "php".
- The /var/www/tmp directory will be created automatically when you install PHP.
- PHP 8 is available :D as well as older versions. pkg_add will ask you which version to install.
up
20
pete att shitnami.net
8 years ago
A brief update: As of OpenBSD 5.7 (2015) the installation process is extremely easy. Apache httpd was replaced by Nginx, which has since been further replaced by OpenBSD's own server, aptly named 'httpd'.

'httpd' is installed by default, everything else you can still get from packages, with a couple name changes (including Apache and Nginx.) You will be asked which version to install - at the time of writing, versions 5.3.29p1 thru 5.6.5 are available.

#pkg_add php
#pkg_add php-fpm
#pkg_add pear

----
OpenBSD disables most services by default; a blank '_flags' line overrides default 'NO' value. pkg_scripts are located in /etc/rc.d/
To start at boot, edit "/etc/rc.conf.local":

httpd_flags=
pkg_scripts=php_fpm

----
Example /etc/httpd.conf
#
# paths are relative to chroot - e.g, '/var/www/run/php-fpm.sock'
server "default" {
listen on * port 80
location "*.php" {
fastcgi socket "/run/php-fpm.sock"
}
directory index index.php
root "/htdocs"
}

----
For date, timezone issues, copy /etc/localtime:
$cp /etc/localtime /var/www/etc/localtime

If 'localhost' DNS name fails to resolve, copy /etc/hosts
$cp /etc/hosts /var/www/etc/hosts
up
7
ameen(at)dausha(dot)net
20 years ago
I just finished spinning my wheels with PHP/Apache on OpenBSD 3.3, and it took a Google to fix my problem. I followed the instructions by (0429196301 at netcabo dot pt) written on Sep 19, 2003 and kept being fed a segmentation fault when I tried to start httpd.

Then I read the page cited below that suggested playing with the order of the LoadModules, and put the PHP first. I followed that recommendation and httpd started without problems!

Page that saved me:
http://archives.neohapsis.com/archives/openbsd/2002-04/3074.html

"Change around the order of the Apache modules, this is one of the
drawbacks to the module API for Apache 1.3 is that the order is very
important. I would try making the PHP 4 module first, Perl module second
and FP module last. "
up
6
openbsd-fanatic
18 years ago
I am user that is just migrating to open source and thought I would take openbsd for a spin. This article, by Gregory L. Magnusson, really helped me to get a working apache-php-mysql server going on openbsd.
http://www.devx.com/security/Article/28059/0/page/1
up
3
sanchero [at] gvsu [dot] edu
20 years ago
On OpenBSD 3.2, given the steps outlined above using pre-built packages you will get a new "/var/www/conf/httpd.conf" that contains a section like this:

<IfDefine SSL>
AddModule mod_ssl.c
AddModule mod_php4.c
</IfDefine>

This causes mod_php4 to load only when starting Apache w/SSL, so if this isn't what you want add the mod_php4 line again above (or below) this section, like so:

AddModule mod_php4.c <<------ SEE? - now should load normally.
<IfDefine SSL>
AddModule mod_ssl.c
AddModule mod_php4.c
</IfDefine>

I also added this for good measure:

<IfModule mod_php4.c>
AddType application/x-httpd-php .php [blah blah]
</IfModule>

Seems to work.
up
-2
hg at ostc dot de
18 years ago
Also you should add "-a /var/www/dev/log" to the syslogd_flags
for propper logging of php-extensions like imap.so and create
a /var/www/etc/master.passwd with an www-user-entry and run
pwd_mkdb -d /var/www/etc /var/www/etc/master.passwd for propper
use of libc-client.a functions in imap.so.
To Top