summaryrefslogtreecommitdiff
path: root/sapi/fastcgi/README.Apache
blob: c7a21725807ef9474bd66acf407e7bb16ca4a87b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Using FastCGI PHP with Apache
=============================

First of all, you may well ask 'Why?'. After all, Apache already has mod_php.
However, there are advantages to running PHP with FastCGI. Separating the
PHP code from the web server removes 'bloat' from the main server, and should
improve the performance of non-PHP requests. Secondly, having one permanent
PHP process as opposed to one per apache process means that shared resources
like persistent database connections are used more efficiently.

First of all, make sure that the FastCGI module is enabled. You should have
a line in your config like:

    LoadModule fastcgi_module /usr/lib/apache/1.3/mod_fastcgi.so

Don't load mod_php, by the way. Make sure it is commented out!

    #LoadModule php4_module /usr/lib/apache/1.3/libphp4.so

Now, we'll create a fcgi-bin directory, just like you would do with normal
CGI scripts. You'll need to create a directory somewhere to store your
FastCGI binaries. We'll use /space/fcgi-bin/ for this example. Remember to
copy the FastCGI-PHP binary in there. (named just 'php')

    ScriptAlias /fcgi-bin/ /space/fcgi-bin/
    <Location /fcgi-bin/>
        SetHandler fastcgi-script
    </Location>

Next, we need to tell Apache to use the FastCGI binary /fcgi-bin/php to
deliver PHP pages. All that is needed is:

    AddType application/x-httpd-php .php
    Action application/x-httpd-php /fcgi-bin/php

Now, if you restart Apache, php pages should now be delivered!


Running PHP-FastCGI separately from the webserver
-------------------------------------------------

(Read README.FastCGI for why you might want to do this).
Easy! Add one more configuration line:

    FastCgiExternalServer /space/fcgi-bin/php -host localhost:8002

Then, start the PHP off with the following command:

    /space/fcgi-bin/php 8002

The number 8002 is the port that PHP will listen on for requests - change this
to anything suitable. And be sure to firewall it out so that external
connections are denied!