search
HomeBackend DevelopmentPHP TutorialInstalling PHP language support in Zeus Web Server_PHP Tutorial

Installing PHP language support in Zeus Web Server_PHP Tutorial

Jul 21, 2016 pm 04:09 PM
phpserverunixwebDownPrefaceexistInstallsupportyesoflanguage

前言
Zeus是一个运行于Unix下的非常优秀的Web Server,而PHP则是Unix下一个非常优秀的后台脚本语言。 这两个产品都是为非常喜欢的产品。为什么要写这样的一个Howto呢?是因为有大量的网站脚本是使用PHP开发的, 而这些程序运行在Zeus下也是一个非常好的选择。写这份文档的目的在于能让大家的PHP系统良好的运行于Zeus服务器上。
很早的时候我写过一份整合Zeus和PHP的文章,它主要是讲如何将PHP以FastCGI的本地调用方式来运行于Zeus中的, 本份Howto主要是来讲如何让PHP运行于Remote Responders方式下。因为这样会比以local方式有更高的可扩展性和运行效率。

准备工作
首先你应该Zeus安装完成,也不会过多的讲如何安装和配置Zeus服务器本身,因为它的安装和配置实在是太简单了。
如果有可能,最好将ports使用cvsup来升级一下。
对于PHP依赖的相关软件如果能提前装,则从ports中安装好。如MySQL、GD等。 安装fastcgi
注意,如果你安装的PHP的版本会低于4.3.0哪么你才需要这步。新的PHP版本已经内置了fastcgi的库。安装fastcgi的方法非常的简单:

root@~$cd /usr/ports/www/fcgi/
root@/usr/ports/www/fcgi$make;make install;make clean
编译完成后我们可以在/usr/local/lib目录中看到有libfcgi.a文件,同时在/usr/local/include目录中会有fastcgi的所有头文件。

 

编译PHP
编译PHP可以使用通常的PHP编译选项,下面是我使用的一个配置:

./configure --prefix=/usr/local/php --enable-fastcgi --with-mysql=/usr/local
需要注意的是在PHP 4.3.0以上版本是使用的 --enable-fastcgi 选项,而PHP 4.3.0以前的版本应使用--with-fastcgi参数。
接着就是安装PHP到系统中:
make
make install
编译完成后,我们来测试一下安装的php是能正确运行:

root@~$cd /usr/local/php/bin/
root@/usr/local/php/bin$./php
这时将进入php代码输入状态,输入

phpinfo(); ?>
按ctrl-d运行后会见到php返回的信息则为正确。

配置FastCGI/PHP
配置FastCGI
进入Zeus管理控制台,打开需要配置的VHost配置。进入 API Support 中的 FastCGI 设置。在其中设置:
Enabling Support for FastCGI Programs : Enable
在Configuring FastCGI Remote Responders中设置:
Directory name : /usr/local/php/bin/php
Location: Machine name: localhost
Additional methods supported?:None
如果你的PHP应用不在本机,即使PHP没有安装在本机上,哪么也要设置 Docroot path 参数,它可以不存在于相应的目录下。
都设置完成后,点击 Apply 按钮。 配置PHP解析指向
进入 URL Handling 中的 Handlers 设置。在 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
注意,这里的 Specify the path and filename of the handler, relative to the document root 应和你上一步设置的 Directory name 值相同。
都设置完成后,点击 Apply 按钮。
所有的设置完成后使用vhost的commit功能将更 改提交并应用。这样Zeus就设置好了Fastcgi和PHP的相关参数。

配置FastCGI/PHP启动
在Zeus的rc.d目录中新建一个S05php的文件,内容为:

#!/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 there are the following contents which need to be changed according to the system conditions Modification:

FPHPBIN=/usr/local/php/bin/php should be set to the path of php
SEMFILE=/tmp/php.pid to generate the path of php.pid, the directory must be writable
PHP_FCGI_CHILDREN=100 Number of php processes
PHP_FCGI_MAX_REQUESTS=1000 The number of requests each php process can respond to before exiting, used to release resources. The above two settings are based on hardware configuration and website visits. The default value is 8,500. Generally speaking, PHP_FCGI_CHILDREN > Maximum concurrent access + 10
PHP_FCGI_MAX_REQUESTS If the setting is too small, websites with a large number of visits will frequently increase the load due to restarts of the PHP process.
#echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range only for linux
--user=65534 --group=65534 is the user and group for the php process to run, generally set to the nobody user FreeBSD is 65534/65534, Linux is 99/99
Finally, set the S05php file as an executable file and run FastCGI/PHP:

chmod 755 S05php
./S05php start
Once started, PHP_FCGI_CHILDREN+1 php processes will be 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 vhost. info.php file, you should be able to see the PHP info page.

Notes
Thanks to CCF forum owner hunreal for writing the S05php script, it is really easy to use!
If you want to know anything else, you can go to the Zeus PHP support page to get more information.

Note: Please indicate the source of any reprint or excerpt (Chinese FreeBSD User Group http://www.cnfug.org)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314467.htmlTechArticleForeword Zeus is an excellent Web Server running under Unix, and PHP is the next excellent one under Unix. background scripting language. Both of these products are very popular products. Why...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.