[PHP] apache在worker模式配置fastcgi使用php-fpm

1.准备:

dpkg -L apache2查看所有安装的apache2的应用

a2query -M查看apache2使用的模式

httpd -l旧版本查看当前apache模式

 

2.查看apache的进程数:

ps aux|grep httpd|grep -v grep|wc -l //查看prefork模式的

pstree |grep httpd //查看worker模式的

 

3.prefork, worker, event 三种模式的区别:

1. prefork 中没有线程的概念,是多进程模型,一个进程处理一个连接;稳定;响应快。其缺点是在连接数比较大时就非常消耗内存。

2. worker 是多进程多线程模型,一个进程有多个线程,每个线程处理一个连接。与prefork相比,worker模式更节省系统的内存资源。不过,需要注意worker模式下的Apache与php等程序模块的兼容性。

3. event 是worker模式的变种,它把服务进程从连接中分离出来,在开启KeepAlive的场合下相对worker模式能够承受更高的并发负载,不能很好的支持https的访问

4.apache使用mod_php的话,不能使用worker模式,不是线程安全的

 

4.apache配置fastcgi:

复制代码
apt-get install apache2-mpm-worker//使用apache的worker模式,多进程多线程

apt-get install libapache2-mod-fastcgi php5-fpm//安装apache的fastcgi模块,和php-fpm

touch /usr/lib/cgi-bin/php5.fcgi//创建一个文件

chown -R www-data:www-data /usr/lib/cgi-bin//赋值权限

vim /etc/apache2/conf-available/php5-fpm.conf//配置apache和php-fpm的文件

<IfModule mod_fastcgi.c>

   AddHandler php5.fcgi .php

   Action php5.fcgi /php5.fcgi

   Alias /php5.fcgi /usr/lib/cgi-bin/php5.fcgi

   FastCgiExternalServer /usr/lib/cgi-bin/php5.fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization -idle-timeout 3600

   //如果是使用端口的话

   FastCgiExternalServer /usr/lib/cgi-bin/php5.fcgi -host 127.0.0.1:9000 -pass-header Authorization -idle-timeout 3600

   <Directory /usr/lib/cgi-bin>

       Require all granted

   </Directory>

</IfModule>

 

service apache2 restart && sudo service php5-fpm restart
复制代码

 

posted @   唯一客服系统开发笔记  阅读(436)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示
1
chat with us