基于UDS模式的php-fpm的LAMP

本文档详细介绍了如何在LAMP环境中配置基于UDS(Unix Domain Socket)模式的php-fpm。从环境搭建开始,包括编译安装httpd-2.4.41,创建用户,配置httpd服务,安装mariadb并进行授权,将discuz程序挂载到网站根目录,以及在Windows和Linux客户端进行访问。同时,还涉及到通过端口配置Apache的mod_proxy_fcgi模块来支持php-fpm。

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

环境

linux、apache、php-fpmlinux、mariadblinux client
192.168.43.17192.168.43.7192.168.43.6
apache_php-fpmmariadbab工具测试

配置 httpd 服务器

编译安装 httpd-2.4.41

创建用户
[apache_php-fpm]#

useradd -r -s /sbin/login apache

配置文件
[apache_php-fpm]#

mkdir /app/httpd24/conf.d/
echo "IncludeOptional conf.d/*.conf" >> /app/httpd24/conf/httpd.conf
cat <<EOF > /app/httpd24/conf.d/httpd_php.conf
User apache
Group apache
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
AddType application/x-httpd-php .php
AddType application/x-httpd-source .phps
proxyrequests off
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php5-fpm.sock|fcgi://localhost/app/httpd24/htdocs/"
EOF

httpd服务的启动脚本
[apache_php-fpm]#

vim /usr/lib/systemd/system/httpd24.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/app/httpd24/bin/httpd $OPTIONS -k start
ExecReload=/app/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

安装相关软件
[apache_php-fpm]#

yum install php-fpm php-mysql -y

配置php-fpm

[apache_php-fpm]#

cat <<EOF > /etc/php-fpm.d/optimization.conf
pm.start_servers = 30
pm.min_spare_servers = 20
pm.max_spare_servers = 60
pm.max_children = 500
pm = dynamic
pm.max_requests = 500
pm.status_path = /status
ping.path = /ping
ping.response = pong
EOF
cat <<EOF > /etc/php-fpm.d/httpd_php.conf
listen.owner = apache
listen.group = apache
listen = /var/run/php5-fpm.sock
listen.mode = 0666
EOF

启动服务

[apache_php-fpm]#

systemctl start httpd24
systemctl start php-fpm

安装 mariadb,配置授权

[mariadb]#

yum install mariadb-server -y
systemctl start mariadb
mysql -e "create database discuz;grant all on discuz.* to discuz@'192.168.43.%'  identified by 'discuz';flush privileges;"

将 discuz 程序挂载到网站的根目录

[apache_php-fpm]#

cd /app/httpd24/htdocs/
unzip Discuz_X3.2_SC_UTF8.zip
ls
Discuz_X3.2_SC_UTF8.zip  index.html  readme  upload  utility
mv upload/ forum
setfacl -Rm u:apache:rwx forum/

windows中的浏览器访问

http://192.168.43.17/forum/install/
在这里插入图片描述
在这里插入图片描述

linux客户端访问

[client]#

ab -c1000 -n 1000 http://192.168.43.17/forum/

基于端口httpd支持php-fpm的配置

vim /etc/httpd/conf.d/fcgi.conf
directoryindex index.php
proxyrequests off
proxypassmatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1

官方文档

Apache Module mod_proxy_fcgi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值