Solved Use php72 with obhttpd (OpenBSD HTTPD)

I have www/obhttpd installed and working with static files, it serve index.html correctly.

Since obhttpd is using chroot(8), php need to be inside the chroot?

What I need to do to accomplish this?

I am using the next configuration (/usr/local/etc/obhttpd.conf), but does not work

Code:
chroot "/usr/local/www"
server "default" {
        listen on * port 80
        location "*.php"{
                fastcgi socket "/run/php-fpm.sock"
        }
}

I am trying to display a simple index.php file which only invoke phpinfo()
 
I created the directory /usr/local/www/run so the socket can be created.

Both files (index.html and index.php) are in /usr/local/www, is strange that index.html works, I will create htdocs and move the files in.

I was used to configure Apache to load PHP as a module to parse your PHP scripts (trying to learn something new), I am not familiar with FastCGI.

I found a service "php-fpm" installed, I suppose it was installed with php72, I am looking information on internet about it (I suppose it must create php-fpm.sock )

Edited: When I tested index.html, I was using the option root "/", that's why it worked; I create htdocs, move the files in, but php files still doesn't work.
 
Last edited:
I am going to document here what I did to use php-fpm with obhttpd

Install lang/php72 with pkg install php72 and enable php-fpm with sysrc php_fpm_enable="YES", to configure it, change the next variables in /usr/local/etc/php-fpm.d/www.conf

Code:
prefix = /usr/local/$pool
listen = run/php-fpm.sock
access.log = logs/php-fpm.access.log
slowlog = logs/php-fpm.slow.log
chroot = .
chdir = /htdocs

Next, install www/obhttpd with pkg install obhttpd and enable at startup with sysrc obhttpd_enable="YES", then create the chroot environment

Code:
mkdir -p /usr/local/www/{htdocs,logs,run,tmp,dev}
chown -R root:wheel /usr/local/www
cd /usr/local/www
chown www:www htdocs
chmod 555 dev
chmod 1777 tmp
mount -t devfs devfs /usr/local/www/dev

Create the configuration file /usr/local/etc/obhttpd.conf with

Code:
chroot "/usr/local/www"
server "default" {
        listen on * port 80
        directory index "index.php"
        location "*.php"{
                fastcgi socket "/run/php-fpm.sock"
        }
}

Last, launch php-fpm with service php-fpm start and obhttpd with service obhttpd start

Now put your php code (index.php) in /usr/local/www/htdocs and browse it with http://server-ip/index.php
 
Last edited:
Back
Top