PHP mit FastCGI unter Apache

Author: | Posted in Solaris No comments

Es gibt ein paar gute Gründe, warum man man PHP über FastCGI benutzen möchte. Im folgenden Beispiel habe ich Apache 2.2.4 zusammen mit PHP 4.4.4 unter Solaris installiert. Die Anleitung kann man auch problemlos für PHP 5.2.x benutzen.

Als erstes muss man von Blastwave die Pakete apache2, ap2_worker, ap2_modfastcgi, php4_cgi und die je nach Bedarf benötigten PHP Module installieren. Danach kreieren wir im Verzeichnis /opt/csw/apache2/etc/extra ein config File für mod_fastcgi mit dem Namen httpd-fastcgi.conf und folgendem Inhalt:

FastCgiServer /var/www/foo/fcgi-bin/php4-fcgi-starter

Dieses File muss man dann in der httpd.conf includen:

# FastCGI settings
Include etc/extra/httpd-fastcgi.conf

Ãœber das File /var/www/foo/fcgi-bin/php4-fcgi-starter wir der FastCGI Server gestartet und sollte folgenden Inhalt haben:

#!/bin/sh
PHPRC="/opt/csw/lib"
export PHPRC
PHP_FCGI_CHILDREN=8
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
TZ=CET
export CET
exec /opt/csw/bin/php-cgi

Nachdem man auch noch in der /opt/csw/apache2/etc/extra/httpd-vhosts.conf folgende Einträge gemacht hat, ist man eigentlich schon fertig:

<VirtualHost foo:80>
DocumentRoot /var/www/foo/htdocs/
ServerName foo.bar.com
ServerAlias foo
ErrorLog /var/log/apache/foo/error_log
CustomLog /var/log/apache/foo/access_log combined
ScriptAlias /fcgi-bin/ "/var/www/foo/fcgi-bin/"
<Directory "/var/www/foo/fcgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/foo/htdocs/>
Order allow,deny
Allow from all
Options Indexes +ExecCGI
</Directory>

AddHandler php-fastcgi .php
Action php-fastcgi /fcgi-bin/php4-fcgi-starter
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
</VirtualHost>

Wichtig ist hier die Option +ExecCGI. Diese Option erlaubt es im entsprechenden Verzeichnis Programme über FastCGI auszuführen.

Jetzt kann man bereits den Apache starten:

# svcadm enable svc:/network/http:cswapache2

Mit ptree sieht das dann so aus:

7369  /opt/csw/apache2/sbin/httpd -k start	7370  /opt/csw/apache2/sbin/httpd -k start

7372  /opt/csw/bin/php-cgi

7375  /opt/csw/bin/php-cgi

7376  /opt/csw/bin/php-cgi

7377  /opt/csw/bin/php-cgi

7378  /opt/csw/bin/php-cgi

7379  /opt/csw/bin/php-cgi

7380  /opt/csw/bin/php-cgi

7381  /opt/csw/bin/php-cgi

7382  /opt/csw/bin/php-cgi

7371  /opt/csw/apache2/sbin/httpd -k start

7373  /opt/csw/apache2/sbin/httpd -k start

7374  /opt/csw/apache2/sbin/httpd -k start

Add Your Comment

Your email address will not be published. Required fields are marked *