hi zoli,
As far as your first question that PHP should run under the user's UID/GID , yes it is possible.
For this to work you should have to install PHP as a CGI binary (compile with --enable-force-cgi-redirect),
it means that PHP will no longer run as Apache module.On high rate of hits this may slow down the speed.You may find its advantages/disadvantages at this url
<a href='http://www.php.net/manual/en/security.cgi-bin.php' target='_blank'>http://www.php.net/manual/en/security.cgi-bin.php</a>
Secondly you want to compile the apache with
suExec enabled (if it is not already)
you can find how to compile apache with suExec option and its configuration settings here
<a href='http://httpd.apache.org/docs/suexec.html' target='_blank'>http://httpd.apache.org/docs/suexec.html</a>
Once apache is compiled with suExec wrapper you have to make some changes to your httpd.conf file,you have to change the Options directive as
Options MultiViews Indexes SymLinksIfOwnerMatch ExecCGIThe main thing about this is now all the PHP scripts should have
executable permissions to work.
To avoid the downside of writing
#!/usr/bin/phpat top of each php script , I think you can avoid this by creating a sym link in your /cgi-bin/ directory of Apache .Make this link point to php binary installed in the system, and add the following lines in the
httpd.conf files
AddHandler php4-script .php
Action php4-script /cgi-bin/php
A complete article article for configuraing Linux Debian in this way is available here
<a href='http://www.debianhowto.de/howtos/en/php_cgi/c_php_cgi.html' target='_blank'>Debian HowTo</a>
Now the resluting scripts will run under the requested user's UID/GID
Your second question is about disabling the mail and socket functions.
Unfortuantely there is no good way to do this neatly ( there are poor tricks which are also resource consuming).One suggestion is to make some changes in the source code and re-compile PHP for yourself ,since now PHP will run under UID of user you can consider what functions would be allowed to this user.Another one is to re-load different php.ini file for each user call so that each user can have different settings(this is worst).
Although I have not tested it anywhere but I hope this will work for at least mail() function.
That is change the
sendmail_path in php.ini or httpd.conf and place some shell script which will check whether the caller has rights (means a shell user) and then direct it to the correct sendmail path, otherwise just to /dev/null etc..This way at least the user cannot send mails.
or let me give some time if i can put some better suggestion