tomclegg.net |
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_httpdcd /usr/ports/www/mini_httpd make install clean Install phpTo 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 daemontoolscd /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 serviceIn 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 servicecd /service ln -s /var/service/mini_httpd sleep 6 svstat /service/mini_httpd sockstat | grep mini_httpd Install your web appYour web files go in Files ending in .cgi or .php are expected to be CGI programs. PHP programs should have Your web app runs at mini_httpd supports HTTP authentication. Beware: putting If your programs don't need to run as root then you should pick a different user (eg. nobody) and change two things:
|