WebServer and PHP

WebServer and PHP

  • mdo  DigitalBox
  •   Dev
  •   November 2, 2024

Having a WebServer and PHP on Haiku can be useful if you would like to use this system as a testing or development platform.

This part is not really well documented, that's why I've decided to propose this article.

Pre-requisites

You will need two applications before starting :

  • lighttpd installed
  • PHP installed

Let's start to install lighttpd server via HaikuDepot. Type "web server" in search terms and select the "all packages" tab :

Select the "lighttpd" item and click on "Install". Proceed the same way with PHP :

The package to install is php8.

Configuration

In order to make lighttpd recognize PHP, we need to edit the "fastcgi.conf" file.

In a Terminal, open it via Pe editor :

lpe /boot/system/settings/lighttpd/conf.d/fastcgi.conf &

You should see the below file content :

Now paste the below lines to indicate how ".php" pages need to be handled :

fastcgi.server = ( ".php" =>
((
"socket" => "/tmp/php.socket",
"bin-path" => "/bin/php-cgi",
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"min-procs" => 1,
"max-procs" => 1,
"idle-timeout" => 20
))
)

The next configuration file is "modules.conf".

Edit this file with Pe :

lpe /boot/system/settings/lighttpd/modules.conf &

The below content is displayed :

Uncomment the include line below by removing the # character :

#/
#/ FastCGI (mod_fastcgi)
#/
include "conf.d/fastcgi.conf"

Now that "fastcgi.conf" file will be used, let's edit it with Pe :

lpe /boot/system/settings/lighttpd/lighttpd.conf &

The content is as per below :

Indicate "/boot/home/www" as the web directory (server_root) by replacing the corresponding lines by the below :

var.log_root = "/boot/system/var/log/lighttpd"
var.server_root = "/boot/home/www"
var.state_dir = "/boot/system/var/run"
var.home_dir = "/var/lib/lighttpd"
var.conf_dir = "/boot/system/settings/lighttpd"

Move until the line with "server.document-root" :

And replace it with : server.document-root = server_root + "/" Then, create the "www" directory in "/boot/home" :

Last, create inside this directory an "index.php" file :

You can copy/paste the below code :

<?php
phpinfo();
?>

This PHP code will provide some information on the PHP version used.

It will be also the test page to confirm everything is working fine :)

Server launch

To launch the web server, open a Terminal and type the command :

/bin/lighttpd -f /system/settings/lighttpd/lighttpd.conf

Once done, the server will be launched in the background :

We can now check if the web server is running fine.

Type in WebPositive the URL http://127.0.0.1

Great, PHP is now recognized on our web server !

In case you need to stop the server, just type :

kill `pidof lighttpd`

Quick alternative

PHP includes a built-in server which can be called via the below command:

php -S 127.0.0.1:8080

In the Terminal the output will be like below :

Please note, in the example the "/boot/home/www/" directory is containing the PHP pages.

Now if you indicate in WebPositive the URL http://127.0.0.1:8080, it will display the same page than with lighttpd server :

I hope you find this information useful, and you are now able to setup a web server with PHP on Haiku.


Powered by Bludit - Hosted by Planet Hoster
© 2025 Haiku Insider