Re: mod_fastcgi + php
Gasior <[email protected]>
| Newsgroups | gmane.comp.web.fastcgi.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi
First of all I want to run different PHP binary for every VirtualHost
(it is the same binary, but differs in location). My wrapper figures out
which binary to use from PATH_INFO and PATH_TRANSLATED env variables.
When I execute wrapper from mod_fastcgi, whole environment is empty
(except for variables set by FastCgiConfig -initial-vars).
For me it looks like, mod_fastcgi executes wrapper, before apache sets
env variables corresponding to request (like DOCUMENT_ROOT etc.). Even
if configured like this:
FastCgiConfig -initial-env DOCUMENT_ROOT (or any other env like
HTTP_HOST/REQUEST_URI)
when i read it with getenv in wrapper, it is empty (variable exists but
no value assigned)
I've solved it by defining different application inside VirtualHost
directive like this:
<VirtualHost>
ServerName vhost1.com
DocumentRoot /home/vhosts/vhost1.com/www
ScriptAlias /cgi-vhost/ /home/vhosts/vhost1.com/usr/bin
AddHandler php-fastcgi .php
<Location /cgi-vhost/php4-cgi>
SetHandler fastcgi-script
</Location>
Action php-fastcgi /cgi-vhost/php4-cgi
AddType application/x-httpd-php .php
</VirtualHost>
Wrapper can find inside which VirtualHost it is by calling getcwd()
(/home/vhosts/vhost1.com/usr/bin) and chroot("../../"). chroot does not
close open descriptors, so php can communicate through open Unix socket.
So there is one last thing to figure out. When apache gets reguest to
php file it forwards it to fastcgi application. So when calling
http://vhost1.com/info.php apache translates it to
/home/vhosts/vhost1.com/www/info.php and sends it to PHP binary
(allready running inside chroot).
So i have to find some way to strip this path to /www/info.php for this
to work.
Any suggestions ?
Regards
Gasior
David Birnbaum wrote:
> Gasior,
>
> It seems that you could simply run the wrapper as is. If you set up
> suexec for FastCGI (see the documentation) than the seteuid/gid is
> already done, as is the chdir, so you just need to chroot() and then
> exec. That should work fine.
>
> David.
>
> -----
>
> On Wed, 26 Oct 2005, Gasior wrote:
>
>> Hello to all
>>
>> I'm looking for a sollution to run php in a safe way in shared
>> environment.
>>
>> Currently I use PHP as a CGI which is executed by a wrapper. This
>> wrapper works like suexec (it does some checking about file permissions)
>> but just before executing PHP it chroot's to VirtualHosts "filesystem".
>> Every virtualhost has it's own "filesystem" for chroot purposes (/bin,
>> /etc/ and all nessecary lib's and bin's).
>> That approach works for me excellent, except its poor performance.
>>
>> My question is: is it possible to use FastCGI for executing PHP not only
>> under some UID/GID (suexec does that fine), but also in specified
>> chroot'ed environment (different for every VirtualHost) ?
>>
>> My idea is to use wrapper, that will find out for which virtualhost it
>> needs to spawn PHP, that:
>>
>> chdir('/vhost/path');
>> seteuid(UID);
>> setegid(GID);
>> chroot('./');
>> execv();
>>
>> I've done some tests with FastCGI wrappers, but inside wrapper i can't
>> get any informations about target virtualhost. Also setting some env
>> variables inside <VirtualHost> directive doesn't work. Maybe FastCGI app
>> is executed before apache process VirtualHost section ?
>>
>> Maybe you could point me how can i find inside the wrapper for which
>> VirtualHost is this request executed.
>>
>> If my aproach is a lost battle, please let me know. I'll just buy better
>> hardware :)
>>
>> Regards
>> Gasior
>>
>>
___________________________________
fastcgi-developers mailing list
http://fastcgi.com/fastcgi-developers/