I use OpenBSD and PHP for my private homepage. For the purpose of education (don't use this in production), I have to tried to execute a simple Hello World program in a chroot. Linked the binary statically. But I always get the result 127 (command not found).
How I execute the command in PHP:
<?php
$output = null;
$result = null;
echo getcwd();
exec("./foo", $output, $result);
var_dump($output);
var_dump($result);
?>
The program ./foo definitely resides in the current working directory. Also the file permissions are correct.
The program in C:
#include <stdio.h>
int main(int argc, char *argv[])
{
fprintf(stdout, "foo: stdout");
fprintf(stderr, "foo: stderr");
return 42;
}
Compiled with:
$ cc -static -o foo foo.c
The output from PHP:
htdocs/example.org/www
array(0) {
}
int(127)
I would understand this behavior if the program is linked dynamically (missing shared libraries).
Is there a specific security feature enabled in the default configuration from OpenBSD which doesn't allow PHP to execute binaries or can somebody explain why this isn't working?
Also haven't disabled the function exec() in /etc/php-8.0.ini.