tomclegg.net


Diary
Examples
    256-router
    adzap
    debian-quota
    diskonmodule
    dynip
    ezmlm-linux
    fbsdhabits
    freebsdclone
    maildirpop3d-awfulhak
    mandy
    md
    mrtg
    net-snmp
    oracle9i
    oracle9i-bsd5
    oracle9i-client
    oracle9i-nat
    php-cgi
    php-commandline
    php-image
    php-kics
  >php-mini_httpd<
    pinouts
    plesk-symlink-php
    pxe
    qmail-linux
    qmail-qfilter
    racoon-sonicwall
    redundant-vpn
    rewriterule
    smalldog
    spamassassin
    squid-tproxy
    supfile
    suse73
    svc-nmbd
    svc-smbd
    svc-smtpd
    toyotastereo
    vm
    vn-file
    wmp-invalid
    xcode-remote-install
    xen-eth0-renamed
    xen3-ubuntu-dapper
Hire Tom
Mostly Mozart
Patches
School
Scrapbook
Software
Telephones




colocation
comments
davidireland
edsgranola
faq
funsites
goodlooking
goodmovies
houserules
liberating
nodefaultroute
resume
resume2
scratch
shopping
snacks
todo
university
warisbogus

PHP CGI with mini_httpd
Posted January 26, 2006

mini_httpd + PHP is an easy way to write a web app with root access.

Install mini_httpd

cd /usr/ports/www/mini_httpd
make install clean

Install php

To use PHP with mini_httpd, you need to fix an outstanding PHP bug #28227 with a patch by Luke Mewburn.

cd /usr/ports/lang/php4
make fetch
cd /tmp
tar xyf /usr/ports/distfiles/php-4.4.2.tar.bz2
cd php-4.4.2
fetch http://tomclegg.net/software/patch-php4-script_filename
patch <patch-php4-script_filename
./configure --prefix=/usr/local/php-cgi
mkdir /usr/local/php-cgi
make install

Install daemontools

cd /usr/ports/sysutils/daemontools
make install clean
echo >>/etc/rc.conf 'svscan_enable="YES"'
echo >>/etc/rc.conf 'svscan_servicedir="/service"'
mkdir /service /var/service
/usr/local/etc/rc.d/svscan.sh start

Set up a supervised mini_httpd service

In this example, mini_httpd will listen on port 808. Change the port number to suit.

cd /var/service
mkdir mini_httpd
cd mini_httpd
chmod +t .
mkdir root log log/main
cat <<EOF >run
#!/bin/sh
exec \
 env - PATH=/bin:/sbin:/usr/bin:/usr/sbin:\
/usr/local/bin:/usr/local/sbin:/var/qmail/bin \
 mini_httpd -D -p 808 -u root -d root/ -c '**.php|**.cgi' 2>&1
EOF

cat <<EOF >log/run
#!/bin/sh
exec multilog t ./main/
EOF

cat <<EOF >root/index.php
#!/usr/local/php-cgi/bin/php
<? echo "ok"; ?>
EOF

chmod +x run log/run root/index.php
chmod 700 .

Start the mini_httpd service

cd /service
ln -s /var/service/mini_httpd

sleep 6
svstat /service/mini_httpd
sockstat | grep mini_httpd

Install your web app

Your web files go in /var/service/mini_httpd/root/. If you don't like it, remove that directory and replace it with a symlink to your preferred location.

Files ending in .cgi or .php are expected to be CGI programs. PHP programs should have #!/usr/local/php-cgi/bin/php on the first line. PHP (and other) programs must be executable.

Your web app runs at http://your.host.name.here:808/. Change 808 to your port number if you used a different one.

mini_httpd supports HTTP authentication. Beware: putting .htpasswd in the web root doesn't protect lower level directories.

If your programs don't need to run as root then you should pick a different user (eg. nobody) and change two things:

  1. Change "-u root" to "-u nobody" in /var/service/mini_httpd/run
  2. chmod 755 /var/service/mini_httpd/root