php编译成httpd模块形式和php以fpm工作为独立守护进程的方式来支持httpd详细过程

php编译成httpd模块形式

略。。。。。。

php以fpm工作为独立守护进程的方式来支持httpd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
./configure –prefix=/opt/php5-fpm \
–with-mysql=mysqlnd \
–with-openssl \
–with-mysqli=mysqlnd \
–enable-mbstring \
–with-freetype-dir \
–with-jpeg-dir \
–with-png-dir \
–with-zlib \
–with-libxml-dir=/usr \
–enable-xml \
–enable-sockets \
–enable-fpm \
–with-mcrypt \
–with-config-file-path=/opt/php5-fpm/conf \
–with-config-file-scan-dir=/opt/php5-fpm/conf.d \
–with-bz2

添加了–enable-fpm选项 ,这是重点啊,各位记住。

1
make && make install

拷贝配置文件至/opt/php5-fpm/conf目录

1
cp php.ini-production /etc/php.ini

拷贝php-fpm配置文件,并同时取消pid选项的注释

1
2
3
cp /usr/local/php5/etc/php-fpm.conf.default  /usr/local/php5/etc/php-fpm.conf
vim /usr/local/php5/etc/php-fpm.conf
pid = /usr/local/php5/var/run/php-fpm.pid

添加服务脚本

1
2
3
4
5
6
7
8
#进入源码目录,拷贝开机启动服务文件
cp init.d.php-fpm /etc/rc.d/init.d/php-fp

#加上执行属性
chmod +x /etc/rc.d/init.d/php-fpm

#加入到开机启动服务
chkconfig –add php-fpm

启动php-fpm

service php-fpm start

配置httpd

1
2
3
4
5
6
7
# vim /etc/httpd24/httpd.conf

#启用这两个模块:

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

添加文件类型

1
2
3
4
5
6
7
8
9
10
11
12
13
#添加文件类型
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

添加php文件的访问通过fpm
ProxyRequests Off
ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/usr/local/apache24/htdocs/$1



找到 DirectoryIndex index.html
改为
DirectoryIndex index.php index.html

编辑php测试页并开启httpd进行测试

1
2
3
4
5
6
7
8
9
10
11
12
cd /usr/local/apache24/htdocs/

vim index.php


<h1>phpfpmtest</h1>

<?php

phpinfo();

?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@localhost htdocs]# apachectl start

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.

localdomain. Set the 'ServerName' directive globally to suppress this

[root@localhost htdocs]# ss -tnls


State Recv-Q Send-Q Local Address:Port Peer Address:Port

LISTEN 0 128 :::80 :::*

LISTEN 0 128 :::22 :::*

LISTEN 0 128 *:22 *:*

LISTEN 0 100 ::1:25 :::*

LISTEN 0 100 127.0.0.1:25 *:*

LISTEN 0 128 127.0.0.1:6010 *:*

LISTEN 0 128 ::1:6010 :::*

LISTEN 0 128 127.0.0.1:6011 *:*

LISTEN 0 128 ::1:6011 :::*

LISTEN 0 128 127.0.0.1:9000 *:*

此时的Server API为FPM/FastCGI

0%