|
1 | 1 | Using PHP4 with the Zeus Web Server
|
2 | 2 | -----------------------------------
|
3 | 3 |
|
4 |
| -Zeus fully supports running PHP in combination with our webserver. A |
5 |
| -significant improvement in PHP 4 is that you can now run PHP as an |
6 |
| -ISAPI module, giving great performance benefits over traditional CGI |
7 |
| -code. |
8 |
| - |
9 |
| -Note that you will need to be running at least version 3.3.8 of the |
10 |
| -webserver. If you are running an earlier version, please see our |
11 |
| -website (http://www.zeus.com) for upgrade instructions. |
12 |
| -Earlier versions of Zeus (3.3.6) can also run PHP, but it is |
13 |
| -suggested that you upgrade for full compatibility. |
14 |
| - |
15 |
| -You should compile PHP using the gcc compiler. Other compilers may |
16 |
| -cause build errors. |
17 |
| - |
18 |
| -To build the ISAPI version of PHP, start the configuration with: |
19 |
| - |
20 |
| -./configure --with-zeus=/usr/local/zeus |
21 |
| - |
22 |
| -Obviously, replace /usr/local/zeus with the location of where you have |
23 |
| -installed Zeus on your machine. For PHP to build successfully, you |
24 |
| -need to have 3.3.6 already installed, because the code relies on the |
25 |
| -presence of header files provided with the latest version. |
| 4 | +Zeus fully supports running PHP in combination with our |
| 5 | +webserver. There are three different interfaces that can be used to |
| 6 | +enable PHP: |
26 | 7 |
|
27 |
| -You may have to adjust the environment variable LDFLAGS and EXTRA_LIBS |
28 |
| -in order to link in extra libraries. This depends on the platform on |
29 |
| -which you are building and also on the compiler used (see below). A |
30 |
| -standard GNU/Linux install with GCC should build fine with no changes. |
| 8 | +* CGI |
| 9 | +* ISAPI |
| 10 | +* FastCGI |
31 | 11 |
|
| 12 | +Of the three, we recommend using FastCGI, which has been tested and |
| 13 | +benchmarked as providing the best performance and reliability. |
32 | 14 |
|
33 |
| -Configuring the webserver |
34 |
| -------------------------- |
| 15 | +Full details of how to install PHP are available from our |
| 16 | +website, at: |
35 | 17 |
|
36 |
| -After running 'make' and 'make install', you will have a 'libphp4.so' |
37 |
| -file. Copy this file into a directory reserved for ISAPI |
38 |
| -binaries. Now, perform the following steps for each virtual server |
39 |
| -that you wish to run PHP on: |
| 18 | +http://support.zeus.com/products/php.html |
40 | 19 |
|
41 |
| -1) On the Admin server, go to 'edit server->path mapping' |
42 |
| -2) Add an alias to the directory with libphp4.so in it, mapped to |
43 |
| - /isapi/ (or a location of your choice). Make sure you set the alias |
44 |
| - type to ISAPI. |
45 |
| -3) Click 'update' |
46 |
| -4) Add a handler for file extension 'php' to be run by /isapi/libphp4.so |
47 |
| -5) Click 'update', then go back to the previous page. |
48 |
| -6) Click on the 'module configuration' button, ensure that ISAPI |
49 |
| - support is ticked. |
50 |
| -7) Click on the ISAPI link. At the bottom of the page, click the |
51 |
| - checkbox for running ISAPI extensions 'out of process'. |
52 |
| -8) Click 'update'. Then restart the virtual server. Done! |
| 20 | +If you have any problems, please check the support site for more |
| 21 | +up-to-date information and advice. |
53 | 22 |
|
54 | 23 |
|
55 |
| -Troubleshooting |
56 |
| ---------------- |
| 24 | +Quick guide to installing FastCGI with Zeus |
| 25 | +------------------------------------------- |
57 | 26 |
|
58 |
| -*) Why does the compile fail at Zend/zend-scanner-cc.cc |
59 |
| - or Zend/zend-parser.c ? |
| 27 | +Step 1 - obtain and install FastCGI development kit. |
60 | 28 |
|
61 |
| -These source files are auto-generated from the corresponding .y files. |
62 |
| -The default distribution of PHP contains pre-generated versions of these |
63 |
| -files that have caused problems for some people. The simplest solution is |
64 |
| -to delete the files. They will then be rebuilt correctly. You must have the |
65 |
| -following GNU tools to do this: |
| 29 | +Grab the package from: |
| 30 | +http://www.fastcgi.com/dist/devkit_2.2.0.tar.gz |
66 | 31 |
|
67 |
| - bison 1.28 or later |
68 |
| - flex 2.5.4 or later |
| 32 | +Extract the package and follow the instructions: |
| 33 | + ./configure |
| 34 | + make |
| 35 | + make export |
| 36 | +(run the last as root) |
69 | 37 |
|
70 |
| -*) Why does my PHP library fail to load? |
| 38 | +This will install to /usr/local/lib/libfcgi.a |
| 39 | + and /usr/local/include/*fcgi* |
71 | 40 |
|
72 |
| -After configuring Zeus, if you get a '502 Bad Gateway' error when |
73 |
| -accessing a PHP page, there are problems loading the PHP |
74 |
| -library. Check the error log ($ZEUSHOME/web/log/errors) for errors. |
75 | 41 |
|
76 |
| -Failing to load the PHP ISAPI module is likely to be due to unresolved |
77 |
| -symbols in the module. A way to check for this is to visit our support |
78 |
| -page at http://support.zeus.com/faq/entries/isapi_error.html and run |
79 |
| -the program there on your libphp4.so. It will list any unresolved |
80 |
| -symbols. |
81 | 42 |
|
82 |
| -*) My libphp4.so has unresolved symbols. How do I fix this? |
| 43 | +Step 2 - Compile PHP as FastCGI. |
83 | 44 |
|
84 |
| -You must ensure that the PHP build process links in the appropriate |
85 |
| -libraries that contain these symbols! The libraries required will |
86 |
| -depend on the platform you are running PHP on. |
| 45 | +Compile as follows: |
| 46 | + ./configure --with-fastcgi |
| 47 | + make |
87 | 48 |
|
88 |
| -You may need to set one or two environment variables before running |
89 |
| -the 'configure' program to set up PHP; LDFLAGS and EXTRA_LIBS. Make |
90 |
| -sure that you also export these variables to the build process. |
91 |
| -(Type 'export LDFLAGS EXTRA_LIBS' in the shell to do this.) |
| 49 | +Note that PHP has many options to the configure script - |
| 50 | +e.g. --with-mysql. You will probably want to select your usual options |
| 51 | +before compiling; the above is just a bare minimum, for illustration. |
92 | 52 |
|
93 |
| -If you are using 3rd party tools and libraries which are installed |
94 |
| -in non-standard locations, you may need to set the environment |
95 |
| -variable LD_LIBRARY_PATH to point to the library's location, prior |
96 |
| -to running the Zeus Web Server. For example, if you have compiled |
97 |
| -external MySQL support, and mysql is installed in /usr/local/mysql, |
98 |
| -you should set LD_LIBRARY_PATH to '/usr/local/mysql/lib/mysql' |
99 |
| -and then 'export LD_LIBRARY_PATH'. For convenience, you should add |
100 |
| -this to the 'start-zeus' script provided. |
| 53 | +After compilation finishes, you will be left with an executable |
| 54 | +program called 'php'. Copy this into your document root, under a |
| 55 | +dedicated FastCGI directory (e.g. $DOCROOT/fcgi-bin/php) |
101 | 56 |
|
102 |
| -Yet another method of ensuring the linked libraries are found is to |
103 |
| -set the environment variable LD_RUN_PATH before compiling PHP. This |
104 |
| -works in a similar way to LD_LIBRARY_PATH, but at compile-time. |
105 |
| -Libraries produced with this envrionment variable set will have its |
106 |
| -value 'burned' into the resultant binary, specifying a runtime |
107 |
| -search pth to locate other required libraries such as MySQL. |
108 | 57 |
|
109 |
| -On Linux, you can also tell the dynamic linker where to find the |
110 |
| -libraries, by adding '/usr/local/mysql/lib/mysql' to the file |
111 |
| -/etc/ld.so.conf - after editting this file, run 'ldconfig' as root, |
112 |
| -to use the changes. |
| 58 | +Step 3 - configure Zeus |
113 | 59 |
|
| 60 | +Four stages: |
| 61 | + - enable FastCGI |
| 62 | + - configure FastCGI |
| 63 | + - setup alias for FastCGI |
| 64 | + - setup alias for PHP |
114 | 65 |
|
115 |
| -Specific examples: |
| 66 | +1) Using the admin server, go to the 'module configuration' page for |
| 67 | +your virtual server, and ensure that 'fastcgi' is enabled (select the |
| 68 | +tickbox to the left). |
116 | 69 |
|
117 |
| -Solaris + gcc: |
118 |
| -Ensure you run ./configure with the `--enable-libgcc' parameter. You |
119 |
| -may need to set LDFLAGS to '-L/usr/local/egcs/lib' (path depends on |
120 |
| -your gcc installation) |
| 70 | +2) While we can run FastCGI's locally, there are known problems with |
| 71 | +some OS's (specifically, the communication between web server and |
| 72 | +FastCGI happens over a unix domain socket, and some OS's have trouble |
| 73 | +sustaining high connection rates over these sockets). So instead, we |
| 74 | +are going to set up the PHP FastCGI to run 'remotely' over localhost |
| 75 | +(this uses TCP sockets, which do not suffer this problem). Go to the |
| 76 | +'fastcgi configuration' page, and under 'add remote fastcgi': |
| 77 | + Add Remote FastCGI |
| 78 | + Docroot path /fcgi-bin/php |
| 79 | + Remote machine localhost:8002 |
| 80 | +The first entry is where you saved PHP, above. |
| 81 | +The second entry is localhost:<any unused port> |
| 82 | +We will start the FastCGI listening on this port shortly. |
| 83 | +Click 'update' to commit these changes. |
121 | 84 |
|
122 |
| -FreeBSD 4: |
123 |
| -Some people may find they need to run ./configure with the |
124 |
| -'--enable-libgcc' compile option too. |
| 85 | +3) Go to the path mapping module and add an alias for FastCGI: |
| 86 | + Add Alias |
| 87 | + Docroot path /fcgi-bin |
| 88 | + Filesystem directory /path/to/docroot/fcgi-bin |
| 89 | + Alias type fastcgi |
| 90 | +Click 'update' to commit these changes |
125 | 91 |
|
| 92 | +4) Also on the path mapping module, add a handler for PHP: |
| 93 | + Add handler |
| 94 | + File extension php |
| 95 | + Handler /fcgi-bin/php |
| 96 | +Click 'update' to commit these changes |
126 | 97 |
|
127 |
| -Performance issues |
128 |
| -================== |
| 98 | +Finally restart your virtual server for these changes to take effect. |
129 | 99 |
|
130 |
| -To make PHP run fast under Zeus, check the following points: |
131 | 100 |
|
132 |
| -1) Run PHP as an ISAPI module, not a CGI - compile it with the --with-zeus=... |
133 |
| - flag! |
| 101 | +Step 4 - start PHP as a FastCGI runner |
134 | 102 |
|
135 |
| -2) Tune the ISAPI runner to your required workload. There are several |
136 |
| - tuneables that can be given. These are set by adding the appropriate |
137 |
| - lines to the $ZEUSHOME/web/global.cfg file. Changes to this file will only |
138 |
| - be picked up after the web server is restarted (run stop-zeus ; start-zeus) |
| 103 | +When you start PHP, it will pre-fork a given number of child processes |
| 104 | +to handle incoming PHP requests. Each process will handle a given |
| 105 | +number of requests before exiting (and being replaced by a newly |
| 106 | +forked process). You can control these two parameters by setting the |
| 107 | +following environment variables BEFORE starting the FastCGI runner: |
139 | 108 |
|
140 |
| - tuning!modules!isapi!external!maxthreads xxx |
| 109 | +PHP_FCGI_CHILDREN - the number of child processes to pre-fork. If not |
| 110 | +set, defaults to 8. |
141 | 111 |
|
142 |
| - - Sets the maximum number of threads that the ISAPI runner will spawn. If |
143 |
| - further PHP page requests arrive, they will be queued until a current |
144 |
| - page is finished. For busy websites, we suggest increasing this value |
145 |
| - (defaults to 16). Replace the 'xxx' in the above line with the required |
146 |
| - number of threads. Note that the threads are equally shared between |
147 |
| - ISAPI extensions and filters, so if you want to handle 100 concurrent |
148 |
| - PHP page requests, set this tuneable to 200. |
| 112 | +PHP_FCGI_MAX_REQUESTS - the number of requests each PHP child process |
| 113 | +handles before exiting. If not set, defaults to 500. |
149 | 114 |
|
150 |
| - tuning!modules!isapi!external!minthreads xxx |
| 115 | +To start the FastCGI runner, execute '$ZEUSHOME/web/bin/fcgirunner |
| 116 | +8002 $DOCROOT/fcgi-bin/php'. Substitute the appropriate values for |
| 117 | +$ZEUSHOME and $DOCROOT; also substitute for 8002 the port you chose, |
| 118 | +above. |
151 | 119 |
|
152 |
| - - Sets the minimum number of threads. Idle threads will be kept in a pool, |
153 |
| - which avoids costly thread creation/deletion. |
154 |
| - |
155 |
| - |
156 |
| -For more information and help with Zeus, please visit our website: |
157 |
| -http://support.zeus.com |
| 120 | +To stop the runner (e.g. to experiment with the above environment |
| 121 | +variables) you will need to manually stop and running PHP |
| 122 | +processes. (Use 'ps' and 'kill'). As it is PHP which is forking lots |
| 123 | +of children and not the runner, Zeus unfortunately cannot keep track |
| 124 | +of what processes are running, sorry. A typical command line may look |
| 125 | +like 'ps -efl | grep $DOCROOT/fcgi-bin/php | grep -v grep | awk |
| 126 | +'{print $4}' | xargs kill' |
0 commit comments