`
hongtoushizi
  • 浏览: 379085 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

Apache2 MPM Worker with PHP-FPM

阅读更多

(转载:)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.

分享到:
评论

相关推荐

    how configure php-fpm 5.x and apache 2.4.x for virtualmin on centos 6

    ./configure --prefix=/opt/apache2 --with-mpm=prefork --enable-rewrite --enable-ssl --enable-proxy-fcgi --with-included-apr make sudo make install ``` #### 三、配置Apache 2.4.x 1. **创建初始化...

    nairn-mpm-fea:nairn-mpm-fea计算力学项目

    《奈恩-mpm-fea:计算力学的开源探索》 奈恩-mpm-fea是一个专注于计算力学的开源项目,其核心在于提供一个强大的有限元分析(FEA)工具。项目的名称“nairn-mpm-fea”可能是以项目创始人或主要贡献者的名字命名,...

    apache2的worker工作模式配置及MaxClients不足问题解决

    Apache2 的 Worker 工作模式配置及 MaxClients 不足问题解决 Apache 服务器是当前最流行的 Web 服务器之一,它提供了多种工作模式,包括 Prefork、Worker 和 Event 等。其中,Worker 工作模式是 Apache 2.x 版本中...

    docker-www:基于 CentOS 7 构建的可靠现货 Apache2PHP-FPM 基础映像

    不人道的人/www 这是一个基本的 CentOS7/Apache/PHP-FPM Docker 镜像。 它可以通过在 /var/www 上安装主机卷来单独使用,但它旨在成为更复杂设置的模型。使用docker run -d -p 80:80 -v /path/to/site/files:/var/...

    php-5.3.1-Win32-VC6-x86+apache2.2.25

    2. 配置Apache:编辑Apache的配置文件`httpd.conf`,添加PHP模块的加载指令,例如`LoadModule php5_module "path/to/php5apache2_2.dll"`。 3. 设置PHP路径:在`httpd.conf`中,指定PHP解析器的位置,例如`...

    MPM.rar_MPM matlab_The Method Method_mpm_mpm-i-sph_saleh model

    《MPM方法在MATLAB中的实现——以MPM-i-SPH Saleh模型为例》 在计算机模拟领域,MPM(Material Point Method)作为一种强大的数值计算方法,被广泛应用于固体力学、流体力学以及多物理场问题的研究。MPM通过结合...

    Apache-2.4.37-x64-vc11

    在维护和优化Apache服务器的过程中,你可以利用Apache的特性,如多进程模型(MPM,Multi-Process Module)、模块化的架构、以及丰富的日志功能来提高性能和安全性。此外,通过结合其他开源软件,如PHP、MySQL,你...

    centos6.5编译安装LAMP环境.doc

    --with-mpm=worker \ --enable-rewrite make && make install ``` 4. 启动Apache并检查是否成功: ``` cd /usr/local/apache/bin apachectl restart ps -ef | grep httpd ``` ### 四、安装MySQL 1. 创建...

    Apache_2.4.23-x86-openssl-1.0.2h.zip

    8. **性能优化**: Apache 2.4引入了多项性能提升特性,如事件模型(Event MPM)和多线程工作进程模型(Worker MPM),这些可以帮助服务器更有效地处理高并发请求。 9. **与其他技术的集成**: Apache常与PHP、Perl、...

    apache2.4 (httpd-2.4.23-win64-VC14)

    性能方面,Apache2.4引入了新的事件模型(Event MPM),它能更好地处理高并发连接,提高服务器响应速度。此外,还支持多线程处理,通过更有效地管理进程和线程,减少了资源消耗。 **配置改进** 配置文件结构和语法...

    apache-httpd-2.4.58-win64-VS17.zip

    - **MPM(多进程模块)**:Apache 2.4支持多种MPM,如`prefork`、`worker`和`event`,分别对应于不同的进程/线程模型,以适应不同的服务器负载需求。 - **HTTP/2支持**:相比于HTTP/1.1,HTTP/2提供了更高效的连接...

    apache_2.2.3-win32-x86-no_ssl.rar

    4. **多线程支持**:在Windows环境下,Apache使用多线程模型(WinNT MPM)提供服务,提高响应速度。 5. **日志记录**:Apache可以详细记录服务器活动,为故障排查和性能分析提供数据。 6. **URL重写**:通过mod_...

    linux下安装配置apache+php (2).pdf

    - 运行配置命令,例如:`./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=most --with-mpm=worker` - 编译和安装:`make`,然后`make install`。 - 配置项解释: - `--prefix`:指定...

    LAMP安装配置

    prefix=/data/sys/apache2 --enable-so --enable-deflate=shared --enable-ssl=shared --enable-expires=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support --with-included-apr --...

    Apache.HTTPServer-2.4.33-win64-win32-VC15

    2. **高性能和稳定性**:2.4系列的Apache引入了多路复用(MPM,Multi-Processing Module)机制,如Event MPM和Worker MPM,提高了并发处理能力,降低了CPU占用,增强了服务器稳定性。 3. **安全性**:Apache支持...

    Apache-2.4.2交叉编译

    ./configure --host=arm-linux --prefix=/usr/local/cross-apache --enable-so --with-mpm=prefork --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-mysql=/path/to/mysql --...

    Apache Prefork、Worker和Event三种MPM详解

    ### Apache Prefork、Worker 和 Event 三种 MPM 的详解 #### 一、Prefork MPM **Prefork MPM** 是 Apache 提供的一种多处理模块(MPM),它实现了非线程化的、预分叉的 Web 服务器架构,类似于 Apache 1.3 的工作...

    麦克 MPM180/MPM185 TO-8封装压阻式压力敏感元件.pdf

    麦克MPM180/MPM185系列TO-8封装压阻式压力敏感元件,是压电压力传感器的一种,主要特点在于它们能够实现压力到电压的线性转换,并具有良好的温度补偿性能。该系列传感器广泛应用于医疗、航空航天和通讯等多个领域,...

Global site tag (gtag.js) - Google Analytics