在Ubuntu上使用php5和apache2-mpm-worker

本文详细介绍了如何使用mod_fcgid模块配置Apache2与PHP5,以提升整体性能。通过安装必要的软件包、设置配置文件及启用相关选项,实现了Apache2下PHP5的快速CGI支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The article Installing Apache2 and PHP5 using mod_fcgid shows how to run php5 with apache2-mpm-worker. The advanage of apache2-mpm-worker over apache2-mpm-prefork is better overall apache2 performance.

1. Install apache2-mpm-worker and the fastcgi apache module libapache-mod-fcid

Code:
# apt-get install apache2-mpm-worker  libapache2-mod-fcgid

2. Enable the Fastcgi apache module mod_fcgid

Code:
# sudo a2enmod fcgid

3. Install php5-cgi and the command-line version php5-cli

Code:
# sudo aptitude install php5-cgi php5-cli

4. Add the following to /etc/apache2/httpd.conf or place these basic configuration settings in a file under /etc/apache2/conf.d. For example, /etc/apache2/conf.d/00-myconf ("00-" will help insure it is read first before other /etc/apache2/conf.d files, which is necessary).

Code:
<Directory /var/www>
AddHandler fcgid-script .php
FCGIWrapper /usr/lib/cgi-bin/php5 .php
Options +ExecCGI
</Directory>
# If you have Aliases provide php support for them (Here we provide php support for scripts in /usr/share's subdirectories)
Alias /aptitude /usr/share/doc/aptitude/html/en
Alias /apt /usr/share/doc/apt-doc

<Directory /usr/share>
AddHandler fcgid-script .php
FCGIWrapper /usr/lib/cgi-bin/php5 .php
Options ExecCGI FollowSymlinks Indexes
</Directory>

5. Then, for each virtual host configuration file you have in /etc/apache2/sites-available, add ExecCGI within a <Directoy /path-to-site> block (placed within your <VirtualHost> block). For example,

# cat /etc/apache2/sites-availabe/yourdomain.com

Code:
<VirtualHost *:80>
ServerAdmin youremail@yourdomain.com
ServerName yoursite.tld
ServerAlias www.yourdomain.tld *.yourdomain.tld

DocumentRoot /var/www/yourdomain.com

ErrorLog        /var/log/apache2/yourdomain.tld-error.log
CustomLog       /var/log/apache2/yourdomain.tld-access.log combined

<Directory /var/www/yourdomain.com>
Options +ExecCGI 

AllowOverride All
Order Allow,Deny
allow from all
</Directory>
LogLevel warn
ServerSignature On
</VirtualHost>

Note: ExecCGI was turned on in /etc/apache2/sites-available/default for /var/www and its subdirectories, so it is not strictly necessary within the <VirtualHost > block shown here. Using +ExecCGI adds fastcgi support to the Options in force. Options don't merge with prior options (they replace them) unless + is used. You can specify entirely different Options , but you must at a minmum have ExecCGI , if you want php support for your virtual host.

6. For any other <Directory /some/other/path> blocks you have, say, for virtual hosts, which are not subdirectories of /var/www or /usr/share, add

<Directory /some/other/path>
AddHandler fcgid-script .php
FCGIWrapper /usr/lib/cgi-bin/php5 .php
Options +ExecCGI
# add other Options you might need, but ExecCGI is required
# . . .
</Directory>

7. Enable your virtual host

Code:
#sudo a2ensite yourdomain.com

7. And reload the apache configuration

Code:
# sudo /etc/init.d/apache2 force-reload

or just restart apache2

Code:
# sudo /etc/init.d/apache2 restart
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值