logo
  • About us
  • What we do
  • Our product
  • Recent work
  • Contact

News

  • Summer holiday internships
    April
  • Junior developer position
    April
  • Ecomonkey lives
    December
  • Calling Javascript from Actionscript
    December
  • Fun with PHP permissions
    December
Site Foci
  • Flash XML slideshow
    May
  • Database training
    May

Fun with PHP permissions

PHP has the exec function. exec('whoami') returns the name of the user who is running the web server (e.g. apache/root/fred). However commands executed with exec() (running as fred) do not behave the same as command executed from a shell (e.g. SSH) session. When you login via SSH, your shell (e.g. bash) instantiates a number of environment variables that shape the context in which you run commands.

exec()

When you run a command via exec, you don't have access to any of your user's environment variables. This becomes painfully obvious when you have a command that runs perfectly in via SSH, but not via exec, e.g.

svnadmin create 'absolute-repo-path'

svn looks for the user's home directory, then for a .subversion directory within that. When calling from exec(), you can force svn to find the right directory by using the config-dir argument.

svnadmin create 'absolute-repo-path' --config-dir=/home/fred/.subversion/

Even if you surmount the problem of running in a 'clean' by explicitly filling in the missing environment data, beware your friendly webserver. Apache by default doesn't allow access for web processes (think commands executed by exec() in PHP) to the /home directories. You can copy the subversion setup data (.subversion/servers) to an accessible directory

svnadmin create 'absolute-repo-path' --config-dir=/var/www/nested/.subversion/

but I recommend keeping it out of the document root(s).

  • Company update
 

 

 

Copyright 2007 Lightenna Limited

  • About us
  • What we do
  • Our product
  • Recent work
  • Contact