Apache2 MPM Worker with PHP-FPM
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.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
AWS 공식 문서 "Amazon ECS에서 Docker의 기본"을 참조하여 Docker로 웹 서버를 구축해 보았습니다.ECS는 쓰지 않습니다. 초보자 엔지니어의 비망록입니다. 공식 문서에 있는 Dockerfile(ubuntu 이미지)를 사용한다. 이 Dockerfile에 python3 설치를 추가합니다. /var/www/html/i...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.