jmhobbs

Making DCOP work with Apache and PHP

I've been working on a design for a web technology based media frame (think digital photo frame that you can program). I have my hardware ducks in a row (ripped apart a laptop, rewired some buttons and flipped the screen around) and now I'm working on software. I put together a reasonable frame work and then decided to add some integration with Amarok. That got hairy fast.

I found a PHP5 DCOP library but no explanation on how to get it to work. Google got me to the point where I knew it was an environment variable thing (the command line dcop has to have access to an X display since DCOP uses X's ICE protocol to do it's thing). Unfortunately trying to set the DISPLAY in the exec call doesn't work, never found out why. Neither did the next 100 things I tried.

Skipping past all that anger and frustration that brought me to a solution, and here it is.

BEWARE this isn't really a safe way to run a server. If you want to do this, be sure that it is on a machine that can't harm the rest of your network or files. If you know a better way or some tips on locking things down, please share!

This is all done assuming a Debian machine base.

1)
Make a full-fledged but restricted user. They must have an KDE login, and X must be running with them logged in. Let's call our user notagoodidea for this example.
2)
Make apache2 run as your user by editing /etc/apache2/envvars

# envvars - default environment variables for apache2ctl

# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.

#export APACHE_RUN_USER=www-data
#export APACHE_RUN_GROUP=www-data
export APACHE_RUN_USER=notagoodidea
export APACHE_RUN_GROUP=notagoodidea
export APACHE_PID_FILE=/var/run/apache2.pid


3)
Edit your run script to launch Apache with the DISPLAY variable set, so edit /etc/init.d/apache2 which will probably break on updates and makes me cringe.
...
# apache2               This init.d script is used to start apache2.
#                       It basically just calls apache2ctl.

ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin DISPLAY=:0.0"
...

4)
Restart everything and test it out.

It isn't pretty but it gets the job done.