# apache2 and php to run as cgi

## matttah

I am trying to get my php to run as a cgi rather than just regularly, however it seems i cannot get this to work properly.  Currently I have the following for the vhost:

```

<VirtualHost MyIP:80>

        ServerAdmin contact@myname.com

        DocumentRoot /home/dev/public_html

        ServerName dev.myserver.com

        ErrorLog /home/dev/logs/error_log

        CustomLog /home/dev/logs/access_log combined

        SuexecUserGroup "dev" "dev"

        ScriptAlias /cgi-bin/ /home/dev/public_html/cgi-bin/

        Alias /sf /usr/share/php/data/symfony/web/sf

        <Directory "/usr/share/php/data/symfony/web/sf">

                AllowOverride All

                Allow from All

        </Directory>

</VirtualHost>

```

Then i have in my modules the following settings being loaded in additional to the normal

```

Listen 80

# Anyone who has a public html directory we allow access to

<Directory /home/*/public_html>

  Order allow,deny

  Allow from all

</Directory>

<Location /cgi-bin/>

    Options +ExecCGI

    SetHandler fastcgi-script

</Location>

AddType application/x-httpd-fastphp .php

Action application/x-httpd-fastphp /php.fcgi

#end fastcgi stuff

```

However it appears this isn't working at all.  Any suggestions on how to get my php executing as cgi?

Thanks

Daum

----------

## erik258

I wonder whether you should include allow/deny options?

----------

## matttah

Tried:

```

<Location /cgi-bin/>

    Order allow,deny

    Allow from all

    Options +ExecCGI

    SetHandler fastcgi-script

</Location>

```

Still not running as the user, any other ideas?

----------

## tgR10

if you want to run php script as a user why don't you try mod_suphp ?

and you should consider to compile apache with "apache2_mpms_peruser" instead of the default

----------

## matttah

I am not only trying to get it to run as a user, I have modified this a bit and it is now all the same for the vhost file, however my modules include is now:

```

Listen 80

# Anyone who has a public html directory we allow access to

<Directory /home/*/public_html>

  Order allow,deny

  Allow from all

</Directory>

<Location /cgi-bin/>

    Allow from all

    Options ExecCGI

    SetHandler fcgid-script

</Location>

AddType application/x-httpd-fastphp .php

Action application/x-httpd-fastphp /php.fcgi

```

I have mod_fcgid installed, however it still is just running as the apache user.

Any other ideas?

----------

## matttah

Alright now I have it trying to run mod_fcgid however 99% of the time i get [Sun Mar 22 20:14:07 2009] [warn] mod_fcgid: can't apply process slot for

The other 1% of the time I get a 500 error and 

```

[Sun Mar 22 20:08:17 2009] [warn] (104)Connection reset by peer: mod_fcgid: read data from fastcgi server error.

[Sun Mar 22 20:08:17 2009] [error] [client 24.61.13.49] Premature end of script headers: php.fcgi

```

Any ideas what iis occuring?  I looked at the permissions on /var/run/fcgidsock and it is 

```
drwx------ 2 apache root     48 Mar 22 20:20 fcgidsock
```

A fwe things I saw online said it might be due to that it can't get to read to that directory, however i checked /var and /var/run and they allow others to view the directory.

Thanks again,

Daum

----------

