在 OpenBSD 系统下的安装

本章节的内容和提示仅限于将 PHP 安装到 » OpenBSD 3.6 系统上。

使用二进制包安装

使用二进制包安装 PHP 到 OpenBSD 系统上是被推荐的同时也是最简单的方法。PHP 核心包已经从其他模块中分离出来了并且每个模块可以被独立的安装/卸载而不影响其他模块。所有这些安装 PHP 需要的文件可以在 OpenBSD 光盘或者在 FTP 站点上找到。

需要安装的 PHP 核心包的文件是 php4-core-4.3.8.tgz,它包含了基本的引擎(包括 gettext 和 iconv)。其次,可能还需要安装一些模块包,如:php4-mysql-4.3.8.tgzphp4-imap-4.3.8.tgz。需要使用命令 phpxs 去激活它,并且再通过修改 php.ini 文件来屏蔽他们。

Example #1 在 OpenBSD 系统下的软件包的安装示例

# pkg_add php4-core-4.3.8.tgz
# /usr/local/sbin/phpxs -s
# cp /usr/local/share/doc/php4/php.ini-recommended /var/www/conf/php.ini
  (加入 mysql 包)
# pkg_add php4-mysql-4.3.8.tgz
# /usr/local/sbin/phpxs -a mysql
  (加入 imap 包)
# pkg_add php4-imap-4.3.8.tgz
# /usr/local/sbin/phpxs -a imap
  (测试一下删除 mysql 包)
# pkg_delete php4-mysql-4.3.8
# /usr/local/sbin/phpxs -r mysql
  (安装 PEAR 库)
# pkg_add php4-pear-4.3.8.tgz

阅读用户手册中的 » packages(7) 部分,可以得到更多 OpenBSD 系统下有关二进制软件包的信息。

使用软件包

同样可以使用» 软件包目录(ports tree)来编译 PHP 的源代码。然而,这样的安装方式仅仅是建议对 OpenBSD 非常熟悉的高级用户去做。PHP4 的软件包被分别分为了两个子目录:core 和 extensions。其中 extensions 目录产生了所有 PHP 所支持的子模块。如果不希望创建并且使用这些模块中的某些模块,请使用 FLAVOR no_* 参数。例如,如果希望跳过编译 imap 模块,设置 FLAVOR 为 no_imap即可。

常见问题

  • 默认安装的 Apache 运行于 » chroot(2) jail 内,将限制 PHP 脚本只能访问 /var/www下面的文件。需要建立 /var/www/tmp 目录来存放 PHP session 文件,或使用其它的 session 后端。此外,数据库套接字需要被放入 jail 或者侦听 localhost接口。如果使用网络函数,某些 /etc 下面的文件例如 /etc/resolv.conf/etc/services 需要被移动到 /var/www/etc 中去。OpenBSD PEAR 包会自动安装到正确的 chroot 目录中,因此不需要作特殊改动。有关 OpenBSD Apache 的更多信息见 OpenBSD FAQ。
  • 对应于 » gd 扩展的 OpenBSD 3.6 包需要预先安装 XFree86。如果不想使用那些需要 X11 的字体特性,则安装 php4-gd-4.3.8-no_x11.tgz 包来替代之。

早期发布版本

早期的 OpenBSD 系统使用 FLAVORS 系统把 PHP 连接为静态模式。自从使用这种方法编译就造成了问题:很难制作二进制软件包。仍然可以使用早期稳定的 ports trees,但这种方式已经不被 OpenBSD 小组所支持。如果对此有任何建议和意见,软件包当前的维护人是 Anil Madhavapeddy(avsm at openbsd dot org)。

add a note add a note

User Contributed Notes 5 notes

up
9
pete att shitnami.net
2 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
1
openbsd-fanatic
12 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
1
ameen(at)dausha(dot)net
14 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
0
sanchero [at] gvsu [dot] edu
14 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
-3
hg at ostc dot de
12 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