Install Mod-FastCGI and PHP5-FPM on Ubuntu
Installation
1 2 |
$ sudo apt-get install apache2-mpm-worker libapache2-mod-fastcgi php5-fpm $ sudo a2enmod actions alias fastcgi |
Configuration
edit /etc/apache2/mods-enabled/fastcgi.conf
:
1 2 3 4 |
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 |
Restart Apache2 and PHP5-FPM
1 |
$ sudo service apache2 restart && sudo service php5-fpm restart |
— Updated 2014-01-09 (Ubuntu 13.10)–
mkdir /var/www/cgi-bin
touch /var/www/cgi-bin/php5.fcgi
chown -R www-data:www-data /var/www/cgi-bin
edit /etc/apache2/mods-enabled/fastcgi.conf
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<IfModule mod_fastcgi.c> AddHandler fastcgi-script .fcgi #FastCgiWrapper /usr/lib/apache2/suexec FastCgiIpcDir /var/lib/apache2/fastcgi Alias /php5.fcgi /var/www/cgi-bin/php5.fcgi AddType application/x-httpd-fastphp5 .php Action application/x-httpd-fastphp5 /php5.fcgi FastCGIExternalServer /var/www/cgi-bin/php5.fcgi -socket /var/run/php5-fpm.sock <Directory "/var/www/cgi-bin"> Order allow,deny <Files "php5.fcgi"> Order deny,allow </Files> </Directory> </IfModule> |
Virtual host setting example :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<VirtualHost *:80> # Admin email, Server Name (domain name), and any aliases ServerAdmin webmaster@email.com ServerName www.example.com # ServerAlias example.com # Index file and Document Root (where the public files are located) DirectoryIndex index.php index.html index.htm DocumentRoot /var/www/example <Directory /var/www/example> Options Indexes FollowSymLinks MultiViews AllowOverride all Order allow,deny Allow from all Require all granted </Directory> # Log file locations LogLevel warn ErrorLog ${APACHE_LOG_DIR}/error.example.com.log CustomLog ${APACHE_LOG_DIR}/access.example.com.log combined </VirtualHost> |
References
- Apache + mod_fastcgi + php-fpm 設定
- Quick Setup: Apache Worker, FastCGI, PHP-FPM and APC
- Setup Apache 2.4 and Php FPM with mod proxy fcgi on Ubuntu 13.10
- INSTALLING APACHE + MOD_FASTCGI + PHP-FPM ON UBUNTU SERVER MAVERICK
- Setting up Apache with PHP-FPM