Preface
Zeus is a very good Web Server running in Unix, while PHP is the next very good background scripting language in Unix. Both products are very popular. Why do we need to write such a Howto? Because a large number of website scripts are developed using PHP, and these programs run under Zeus is also a good choice. The purpose of writing this document is to make everyone's PHP system run well on the Zeus server.
I wrote a very early article about integrating Zeus and PHP. It mainly talks about how to use FastCGI's local call method to run PHP In Zeus, this document describes how to run PHP In the Remote Responders mode. This provides higher scalability and running efficiency than local.
Preparations
First, you should install Zeus, and do not talk too much about how to install and configure the Zeus server itself, because it is too easy to install and configure.
If possible, use cvsup to upgrade ports.
Install software related to PHP dependencies in advance from ports. Such as MySQL and GD. Install fastcgi
Note: If you install a PHP version earlier than 4.3.0, you need this step. The new PHP version has a built-in fastcgi library. The fastcgi installation method is very simple:
Root @~ $ Cd/usr/ports/www/fcgi/
Root @/usr/ports/www/fcgi $ make; make install; make clean
After compilation, we can see the libfcgi. a file in the/usr/local/lib directory, and all the header files of fastcgi will be included in the/usr/local/include directory.
Compile PHP
To compile PHP, you can use the common PHP compilation options. Below is a configuration I used:
./Configure -- prefix =/usr/local/php -- enable-fastcgi -- with-mysql =/usr/local
Note that the -- enable-fastcgi option is used in PHP 4.3.0 and later versions. The -- with-fastcgi parameter should be used in PHP 4.3.0 and earlier versions.
Then install PHP to the system:
Make
Make install
After compilation, let's test whether the installed php can run correctly:
Root @~ $ Cd/usr/local/php/bin/
Root @/usr/local/php/bin $./php
Enter the php code input status.
<? Phpinfo ();?>
Press ctrl-d to run the command and the information returned by php is correct.
Configure FastCGI/PHP
Configure FastCGI
Go to the Zeus console and open the VHost configuration to be configured. Go to FastCGI settings in API Support. Set in:
Enabling Support for FastCGI Programs: Enable
In the processing ing FastCGI Remote Responders, set:
Directory name:/usr/local/php/bin/php
Location: Machine name: localhost
Additional methods supported? : None
If your PHP application is not on the local machine, even if PHP is not installed on the local machine, you need to set the Docroot path parameter, which may not exist in the corresponding directory.
Click Apply. Configure php dns pointing
Go to the Handlers settings in URL Handling. Set the following parameters in Adding a Handler:
File Extension: php
Specify the path and filename of the handler, relative to the document root:/usr/local/php/bin/php
HTTP 404 errors are handled by: The handler
Note that the Specify the path and filename of the handler and relative to the document root here should be the same as the Directory name value you set in the previous step.
Click Apply.
After all the settings are complete, use the commit function of vhost to submit and apply them. In this way, Zeus has configured relevant parameters for Fastcgi and PHP.
Configure FastCGI/PHP to start
Create a new S05php file in the rc. d directory of Zeus with the following content:
#! /Bin/sh
# Script to start and stop the persistent PHP runner for FastCGI.
# Please check paths before use.
# FastCGI PHP binary
FPHPBIN =/usr/local/php/bin/php
# Location to place semaphore
SEMFILE =/tmp/php. pid
PHP_FCGI_CHILDREN = 100
PHP_FCGI_MAX_REQUESTS = 1000
Export PHP_FCGI_CHILDREN
Export PHP_FCGI_MAX_REQUESTS
# This is Linux-use/proc to increase the local (ephemeral) port range
# Echo 1024 65000>/proc/sys/net/ipv4/ip_local_port_range
If [-z "$ ZEUSHOME"]
Then
Cd 'dirname $0 '/..
ZEUSHOME = 'pwd'
Export ZEUSHOME
Fi
Case "$1" in
'Start ')
If [-e $ SEMFILE]
Then
Echo FastCGI PHP error: already running. Restart FastCGI PHP now
Kill 'cat $ semfile'
Sleep 5
Fi
If [! -X $ FPHPBIN]
Then
Echo FastCGI PHP error: please check that $ FPHPBIN is executable and exists.
Exit 1
Fi
Echo Starting FastCGI PHP.
$ ZEUSHOME/web/bin/fcgirunner -- user = 65534 -- group = 65534 -- pidfile = $ SEMFILE 8002 $ FPHPBIN
;;
'Stop ')
If [-e $ SEMFILE]
Then
Echo Stopping FastCGI PHP.
Kill 'cat $ semfile'
Rm $ SEMFILE
Exit 0
Fi
'Restart ')
If [-e $ SEMFILE]
Then
Echo Stopping FastCGI PHP.
Kill 'cat $ semfile'
Sleep 5
Fi
Echo Starting FastCGI PHP.
$ ZEUSHOME/web/bin/fcgirunner -- user = 65534 -- group = 65534 -- pidfile = $ SEMFILE 8002 $ FPHPBIN
*)
Echo "usage: $0 {start | stop | restart }"
;;
Esac
Exit 1
In this script, the following content needs to be modified according to the system conditions:
FPHPBIN =/usr/local/php/bin/php should be set to the php path
SEMFILE =/tmp/php. pid: the path for generating php. pid. This directory must be writable.
PHP_FCGI_CHILDREN = 100 php process count
PHP_FCGI_MAX_REQUESTS = 1000 number of requests that each php process can respond to before exiting. These two requests are used to release resources. The default value is 8,500. In general, PHP_FCGI_CHILDREN> maximum access concurrency + 10
If PHP_FCGI_MAX_REQUESTS is set to too small, websites with a high access volume will frequently increase the load due to the restart of the php process.
# Echo 1024 65000>/proc/sys/net/ipv4/ip_local_port_range is only used in linux
-- User = 65534 -- group = 65534 is the php process running user and group. Generally, it is set to nobody user and group FreeBSD to 65534/65534, and Linux to 99/99.
Finally, set the S05php file to an executable file and run FastCGI/PHP:
Chmod 755 S05php
./S05php start
Once started, the PHP_FCGI_CHILDREN + 1 php process is displayed in the ps-ax list.
Create an info. php file in the Docroot directory corresponding to your vhost. The content is:
<?
Phpinfo ();
?>
Use a browser to access the info. PHP file in vhost. You can see the info page of PHP.
Notes
Thanks to the S05php script written by hunreal, the dashboard of CCF, which is really useful!
For more information, go to the Zeus PHP support page.
Note: Please indicate the source of any reprinted or excerpted article (Chinese FreeBSD user group http://www.cnfug.org)