(转载:)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
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.
相关推荐
不人道的人/www 这是一个基本的 CentOS7/Apache/PHP-FPM Docker 镜像。 它可以通过在 /var/www 上安装主机卷来单独使用,但它旨在成为更复杂设置的模型。使用docker run -d -p 80:80 -v /path/to/site/files:/var/...
--with-mpm=worker \ --enable-rewrite make && make install ``` 4. 启动Apache并检查是否成功: ``` cd /usr/local/apache/bin apachectl restart ps -ef | grep httpd ``` ### 四、安装MySQL 1. 创建...
[root@Liuqf root]# ./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=all --enable-cgi --enable-rewrite --enable-deflate --with-mpm=worker ``` 3. 编译和安装Apache: ``` [root@...
2. **线程支持**:在Linux系统上,Apache可以配置为多线程模式(MPM worker或MPM event),以提高高并发情况下的性能。 3. **更好的安全性和稳定性**:2.2.22版本修复了一些已知的安全漏洞,提高了服务器的稳定性,...
- Apache:Apache Web服务器最初由美国伊利诺伊大学香槟分校开发,具有Prefork、Worker和Event三种多进程处理模块(MPM)。 - - Prefork模型:适用于低并发场景,稳定但占用较多系统资源,每个进程有独立线程,...
在 PHP 的上下文中,ZTS 版本是为了在 Apache 的多线程 MPM(比如 Worker MPM)或 PHP 运行在 CGI 或 FPM(FastCGI 进程管理器)并配置为多进程时使用。 Swoole 扩展的核心功能包括: 1. **异步事件驱动**:Swoole...
- **MPM模块**:选择合适的多进程模块,如Prefork或Worker,调整相关配置以平衡性能和内存占用。 - **KeepAlive**:根据服务器和网络状况,调整KeepAliveTimeout和MaxKeepAliveRequests参数。 - **模块优化**:...
包括Prefork、Worker、Event等,配置文件调整MPM以适应PHP。 8. PHP在Apache的运行方式: 有mod_php、FastCGI、SSI等,FastCGI通过`php-fpm`服务运行。 9. PHP命令行运行: 配置时添加`--enable-cli`,命令行...
Apache通常使用两种多进程模型:传统的Prefork MPM(Multi-Processing Module)和Worker MPM。Prefork模型创建多个独立的进程来处理请求,而Worker模型则使用线程模型,每个进程可以处理多个并发连接。这两种模型在...