设为首页 收藏本站
查看: 585|回复: 0

[经验分享] Apache2 MPM Worker with PHP-FPM

[复制链接]

尚未签到

发表于 2017-3-29 09:50:29 | 显示全部楼层 |阅读模式
(转载:)http://www.garron.me/en/blog/ubuntu-lamp-apache2-mpm-worker-and-php-fpm.html

Apache2 MPM Worker with PHP-FPM

Written by Guillermo Garron .

Date: 2012-12-26 15:13:00 +0000


Spanish version
In the previous post I have talked about Apache MPM worker and prefork mode
Today in this post I will show you how to install and configure a LAMP stack under Ubuntu using Apache MPM Worker instead of Prefork.
This is the list of what we are going to install


  • Apache 2.2 MPM Worker
  • PHP-FPM
  • MySQL server

We will assume you already have an Ubuntu server running, in my case is an Ubuntu server version 12.10 running on a Linode VPS.
Installing Apache
If you install Apache alone, it seems that Ubuntu install the worker pre-build version by default. So this line should install Apache.

sudo apt-get install apache2
Check that this package is being installed: apache2-mpm-worker. Or you can force Ubuntu to install it by running:

sudo apt-get install apache2-mpm-worker
Installing PHP

sudo apt-get install libapache2-mod-fastcgi php5-fpm php5 php5-curl php5-gd php5-imagick php-apc php5-mysql
This packages php5-curl php5-gd php5-imagick php-apc are needed to install Wordpress in the next post, if you do not need for your installation you can leave them out.
Enable Apache modules

sudo a2enmod actions fastcgi alias
Restart Apache

sudo service apache2 restart
Installing MySQL

sudo apt-get install mysql-server mysql-client
We now have the LAMP stack installed, time to configure it.
Configuring Apache to use PHP
I am hosting static and dynamic sites on the same Apache server, because of that I am going to configure PHP in a per-virtual-site basis instead of having it configured system-wide. You can choose whatever method you prefer.
PHP-FPM on Apache per Virtual Site
Just edit the coresponding configuration file in /etc/apache2/sites-enabled/ folder and add this line just before the closing </VirtualHost> tag.

<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
</IfModule>
PHP-FPM on Apache system-wide
To have PHP enabled for the whole server and all virtual sites, add the same above lines in a file in this folder /etc/apache2/conf.d/. You will need to create a file there named something like php-fpm.conf, anything you may want is good, as long as it has the .conf extension.
Conclusion
You now have a very efficient Apache server, capable to manage big loads of traffic to static files, and still able to manage PHP. Why not to use NGINX and PHP-FPM instead? That is up to you, I have gone this way because I wanted to be able to use .htaccess, and be able to follow standard instructions to install software like Wordpress, Wiki, Drupal and others, without the need to adapt everything to Nginx.
If you prefer NGINX is OK, I love NGINX too, and is the server I usually choose for my setups, I just like playing with other options.
Final note
In case you get errors while running PHP, check that this file /etc/php5/fpm/pool.d/www.conf Have this line:

listen = /var/run/php5-fpm.sock
That is the default in Ubuntu 12.10, but may change in future versions.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-356870-1-1.html 上篇帖子: 一个比较隐蔽的php马 下篇帖子: php更改最大可上传文件大小
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表