第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > event mpm php CentOS 7 安装 PHP-FPM 及使用 mod_mpm_event

event mpm php CentOS 7 安装 PHP-FPM 及使用 mod_mpm_event

时间:2021-04-04 04:03:50

相关推荐

event mpm php CentOS 7 安装 PHP-FPM 及使用 mod_mpm_event

Apache 配置 PHP 一般会默认用 mod_php 的方法安装, 安装 Nginx 便会使用 PHP-FPM。但如果在 Apache 不想使用默认的 prefork 作为 MPM (通常基于效能因素), 想使用 worker 或 event, 便需要使用 PHP-FPM 的方法安装 PHP。

本文会示范在 CentOS 7 安装 Apache 及 PHP-FPM 的方法。

首先用 yum 安装 httpd 及 php-fpm:

[root@opencli ~]# yum install httpd httpd-tools mod_ssl php-fpm

Apache 默认使用 mod_mpm_prefork, 改用 mod_mpm_event, 开启 /etc/httpd/conf.modules.d/00-mpm.conf:

[root@opencli ~]# vi /etc/httpd/conf.modules.d/00-mpm.conf

将 mpm_prefork_module 一行, 在前面加上注解:

# LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

然后将 mpm_event_module 一行前的注解删除:

LoadModule mpm_worker_module modules/mod_mpm_worker.so

修改好上面的设定后, 现在设定 PHP-FPM, 将所有 PHP 的请求传送给 PHP-FPM:

[root@opencli ~]# vi /etc/httpd/conf.d/php.conf

以下是 php.conf 的内容:

# Tell the PHP interpreter to handle files with a .php extension.

# Proxy declaration

# we must declare a parameter in here (doesn't matter which) or it'll not register the proxy ahead of time

ProxySet disablereuse=off

# Redirect to the proxy

SetHandler proxy:fcgi://php-fpm

#

# Allow php to handle Multiviews

#

AddType text/html .php

#

# Add index.php to the list of files that will be served as directory

# indexes.

#

DirectoryIndex index.php

#

# Uncomment the following lines to allow PHP to pretty-print .phps

# files as PHP source code:

#

#

# SetHandler application/x-httpd-php-source

#

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

31

# Tell the PHP interpreter to handle files with a .php extension.

# Proxy declaration

# we must declare a parameter in here (doesn't matter which) or it'll not register the proxy ahead of time

ProxySetdisablereuse=off

# Redirect to the proxy

SetHandlerproxy:fcgi://php-fpm

#

# Allow php to handle Multiviews

#

AddTypetext/html.php

#

# Add index.php to the list of files that will be served as directory

# indexes.

#

DirectoryIndexindex.php

#

# Uncomment the following lines to allow PHP to pretty-print .phps

# files as PHP source code:

#

#

# SetHandler application/x-httpd-php-source

#

默认的 php-fpm 设定档会使用 TCP 连线, 为了有更佳的效能, 改用 socket, 开启 PHP-FPM 设定档 /etc/php-fpm.d/www.conf:

[root@opencli ~]# vi /etc/php-fpm.d/www.conf

以下是需要修改的内容:

; listen = 127.0.0.1:9000

listen = /var/run/php-fpm/default.sock

1

2

;listen=127.0.0.1:9000

listen=/var/run/php-fpm/default.sock

listen.allowed_clients = 127.0.0.1

listen.owner = apache

listen.group = apache

listen.mode = 0660

user = apache

group = apache

1

2

3

4

5

6

listen.allowed_clients=127.0.0.1

listen.owner=apache

listen.group=apache

listen.mode=0660

user=apache

group=apache

设定完成后, 现在启动 httpd 及 php-fpm, 并设定开机自动启动:

[root@opencli ~]# systemctl enable php-fpm

[root@opencli ~]# systemctl enable httpd

[root@opencli ~]# systemctl start php-fpm

[root@opencli ~]# systemctl start httpd

现在需要设定 firewalld, 开放 port 80 及 443 对外连线:

[root@opencli ~]# firewall-cmd –zone=public –permanent –add-service=http

[root@opencli ~]# firewall-cmd –zone=public –permanent –add-service=https

[root@opencli ~]# firewall-cmd –reload

最后可以测试一下 PHP 是否可以透过 PHP-FPM 正常执行, 执行以下指令建立 PHP 测试页面:

[root@opencli ~]# echo “<?php phpinfo(); ?>” > /var/www/html/info.php

用浏览器开启上面的页面 (http://xxx.xxx.xxx.xxx/info.php), 如果可以看到 phpinfo 的画面, 并看到 Server API 是 “FPM/FastCGI”, 便表示安装成功了:

你可能感兴趣的内容:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。