# Problems with mod_fastcgi and apache2 [SOLVED]

## KWhat

The Error:

```
FastCGI: invalid (dynamic) server "/var/www/htdocs/index.php": access for server (uid 81, gid 81) not allowed: execute not allowed
```

The Config:

```

FastCgiWrapper Off

FastCgiIpcDir /var/run/fastcgi

FastCgiConfig -maxClassProcesses 5 -maxProcesses 1000 -restart -killInterval 10

FastCgiServer /usr/bin/php-cgi -socket /var/run/fastcgi/fastcgi.socket -processes 1 -initial-env PHPRC=/etc/php/cgi-php5.3

AddHandler fastcgi-script .php

```

I think apache is trying to execute /var/www/htdocs/index.php as a shell script instead of passing it to /usr/bin/php-cgi which appears to start correctly.Last edited by KWhat on Thu Feb 10, 2011 1:14 am; edited 1 time in total

----------

## Dagger

if you want to use apache with fastcgi, why not to use php-fpm? It was designed to be used with mod_fastcgi.

----------

## KWhat

Thats the end goal, I would just like to see if i can get fastcgi working by its self first.  This configuration was a pain but I think I finally got it working.  I have attached a few spinets for each configuration in hopes that it will be useful for someone at some point.

/etc/apache2/modules.d/20_mod_fastcgi.conf 

```

<IfDefine FASTCGI>

LoadModule fastcgi_module modules/mod_fastcgi.so

FastCgiWrapper Off

FastCgiIpcDir /var/run/fastcgi

FastCgiConfig -maxClassProcesses 4 -maxProcesses 10000 -restart -killInterval 10

FastCgiServer /usr/bin/php-cgi -socket /var/run/fastcgi/fastcgi.socket -processes 1 -initial-env PHPRC=/etc/php/cgi-php5.3

AddHandler php-fastcgi .php

Action php-fastcgi /cgi-bin/php-fastcgi

<Location /cgi-bin/php-fastcgi>

        Order Deny,Allow

        Deny from All

        # Prevent accessing this path directly

        Allow from env=REDIRECT_STATUS

        SetHandler fastcgi-script

        Options +ExecCGI

</Location>

AddType application/x-httpd-php .php

DirectoryIndex index.php

</IfDefine>

```

/etc/apache2/modules.d/20_mod_fpm.conf 

```

<IfDefine FPM>

LoadModule fastcgi_module modules/mod_fastcgi.so

#FastCgiWrapper Off

#FastCgiIpcDir /var/run/fastcgi

#FastCgiConfig -maxClassProcesses 4 -maxProcesses 10000 -restart -killInterval 10

#FastCgiServer /usr/bin/php-cgi -socket /var/run/fastcgi/fastcgi.socket -processes 1 -initial-env PHPRC=/etc/php/cgi-php5.3

AddHandler php-fpm .php

Action php-fpm /cgi-bin/php-fpm

<Location /cgi-bin/php-fpm>

        Order Deny,Allow

        Deny from All

        # Prevent accessing this path directly

        Allow from env=REDIRECT_STATUS

        SetHandler fpm-script

        Options +ExecCGI

</Location>

AddType application/x-httpd-php .php

DirectoryIndex index.php

</IfDefine>

```

/etc/apache2/vhosts.d/00_http_siteroot.conf

```

...

        DocumentRoot "/var/www/siteroot/htdocs"

        # Directive to enabled FASTCGI PHP

        <IfDefine FASTCGI>

                ScriptAlias /cgi-bin/ /var/www/siteroot/htdocs/

                FastCgiExternalServer /var/www/siteroot/htdocs/php-fastcgi -socket /var/run/fastcgi/fastcgi.socket

        </IfDefine>

        # Directive to enabled FPM PHP

        <IfDefine FPM>

                ScriptAlias /cgi-bin/ /var/www/siteroot/htdocs/

                FastCgiExternalServer /var/www/siteroot/htdocs/php-fpm -socket /var/run/php-fpm.socket

        </IfDefine>

...

```

Note: The cgi-bin folder and the php-fastcgi / php-fpm files do not exist on the filesystem.

----------

## kosovafan

Hello,

thats a configuration what i search. Only one question, how can use FPM for Virtuelle Server? 

Great when someone can help.

Regards

Silvio

----------

## KWhat

 *Quote:*   

> how can use FPM for Virtuelle Server?

 

That configuration snip-it should be all you need to use it in a virtual host configuration with apache.  Make sure you add -D FPM to APACHE2_OPTS= in your /etc/conf.d/apache2 folder.

This goes in the virtual host:

```

<VirtualHost *:80>

        ServerName www.myhost.com

...

        # Directive to enabled FPM PHP 

        <IfDefine FPM> 

                ScriptAlias /cgi-bin/ /var/www/siteroot/htdocs/ 

                FastCgiExternalServer /var/www/siteroot/htdocs/php-fpm -socket /var/run/php-fpm.socket 

        </IfDefine>

        DocumentRoot "/var/www/siteroot/htdocs"

        <Directory /var/www/siteroot/htdocs>

...

        </Directory>

</VirtualHost>

```

----------

