设为首页 收藏本站 订阅本站

blogger

DEBIAN 下apache 切换prefork模式到worker模式运行php

cache 发布于 WWW 2014-06-05 [ 1119 ] 次浏览 [ 0 ] 条评论

标签: DEBIAN apache worker prefork

因为一直需要长时间运行脚本,一直用的PREFORK模式运行的PHP,配合APC使用一直不错,但是现在服务器内存不够了,负载居高不下,内存吃尽,无奈,只有切换到WORKER模式下。(换完以后内存肯定是省了一多半)

安装apache-mpm-worker和php-cgi

apt-get install apache2-mpm-worker libapache2-mod-fcgid php5-cgi php5-cli

 修改fcgid配置文件以映射php

 vi /etc/apache2/mods-available/fcgid.conf

增加(默认只有两行,可以删除)

 AddHandler fcgid-script .php
 FCGIWrapper /usr/lib/cgi-bin/php5 .php
 IPCConnectTimeout 300
 IdleTimeout 600
 ProcessLifeTime 600
 MaxProcessCount 100
 DefaultMinClassProcessCount 10
 DefaultMaxClassProcessCount 1000
 IPCConnectTimeout 300
 IPCCommTimeout 300
 MaxRequestLen 104857600 

启用 fcgid 模块

a2enmod fcgid

在相应的站点启用fcgid

 

修改站点配置文件,在<Directory /var/www>中的Options选项后,添加+ExecCGI。如:

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews +ExecCGI
AllowOverride None
Order allow,deny
allow from all
< /Directory>
重新加载apache配置文件
service apache2 force-reload
 
我是到这里就可以了。
 
先前看一老外写的文档,我根据操作没有成功,和这个差不多,只是配置文件不同,但是我切换后发现使用APC没有用了,缓存不到内存,负载很大,APC里显示的启动时间总是几分钟,直接换的XCACHE。不再研究了。
 
附上老外的方法,有时间再研究吧。
Here is how to change from apache2-mpm-prefork to apache2-mpm-worker, , when having used mpm-prefork before, and php5, on Debian Squeeze.

Step1. Stop Apache2:


# /etc/init.d/apache2 stop

Step2. Install apache2-mpm-worker:
 That will remove some packages, like apache2-mpm-prefork and libapache-mod-php5, and install apache2-mpm-worker, and php5-cgi instead.


# apt-get install apache2-mpm-worker

Step3. Set Apache2 to use php5-cgi:


 Activate CGI using the command:


a2enmod cgid

Step4. Activate mod_actions: (That is the module that provides for executing CGI scripts based on media type or request method.)


a2enmod actions

Step5. Add the following to mod_actions config:


vim /etc/apache2/mods-enabled/actions.conf

and paste the following:




Action application/x-httpd-php /cgi-bin/php5


Step6. Start apache2:


/etc/init.d/apache2 start

Now the amount of memory used on your machine is a lot less.
 PHP now runs as its own process for the requests.
 

 

DEBIAN 下apache 切换prefork模式到worker模式运行php:等您坐沙发呢!

发表评论