PHP-FPM (FastCGI Process Manager) is a great alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.
1 | vim /etc/apt/sources.list |
Add source for php5-fpm:
1 2 | # PHP-FPM deb http://packages.dotdeb.org stable all |
1 | aptitude install apache2 apache2-mpm-worker libapache2-mod-fastcgi php5-fpm |
Enable apache modules after installation:
1 | a2enmod actions fastcgi |
Replace your content of fastcgi with this one:
1 | vim /etc/apache2/mods-enabled/fastcgi.conf |
1 2 3 4 5 6 7 8 9 | <ifmodule mod_fastcgi.c=""> AddHandler php5-fcgi .php Action php5-fcgi /cgi-bin/php5.external <location "="" cgi-bin="" php5.external"=""> Order Deny,Allow Deny from All Allow from env=REDIRECT_STATUS </location> </ifmodule> |
Example of apache virtual host:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <virtualhost *:80=""> ServerName dev.zeldor.biz ServerAdmin webmaster@zeldor.biz DocumentRoot /var/www/vhosts/dev.zeldor.biz/public_html/ Options None # Fast CGI + FPM FastCgiExternalServer /var/www/vhosts/dev.zeldor.biz/cgi-bin/php5.external -socket /var/run/php5-fpm/dev.soc Alias /cgi-bin/ /var/www/vhosts/dev.zeldor.biz/cgi-bin/ Alias /phpguru /usr/share/phpmyadmin <directory var="" www="" vhosts="" dev.zeldor.biz="" public_html=""> Options SymLinksIfOwnerMatch AllowOverride All Order allow,deny Allow from all </directory> ErrorLog ${APACHE_LOG_DIR}/dev.zeldor.biz/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/dev.zeldor.biz/access.log combined </virtualhost> |
Now edit your php5-fpm.conf (/etc/php5/fpm/php5-fpm.conf)
Find section Pool Definitions add add this include for your separated domains.
1 | include=/etc/php5/fpm/pools/*.conf |
Every modification will be made strictly in your pool config like this one.
1 | vim /etc/php5/fpm/pools/dev.zeldor.biz.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [dev.zeldor.biz] listen = /var/run/php5-fpm/dev.zeldor.biz.soc listen.owner = www-dev listen.group = www-dev listen.mode = 0666 user = www-dev group = www-dev pm = dynamic pm.max_children = 20 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 10 php_admin_value[open_basedir]=/var/www/vhosts/dev.zeldor.biz/public_html :/usr/share/phpmyadmin php_admin_value[session.save_path]=/var/www/vhosts/dev.zeldor.biz/tmp php_admin_value[upload_tmp_dir]=/var/www/vhosts/dev.zeldor.biz/tmp php_admin_value[memory_limit] = 128M php_admin_value[upload_max_filesize] = 100M php_admin_value[post_max_size] = 100M |
That means each domain may have different configuration types!
Add user for each domain and disable shell access
1 | adduser www-dev |
Dieter says
Not working, got:
FastCGI: server “/var/htdocs/www.test.de/cgi-bin/php5.external” stderr: Primary script unknown
cgi-bin exists
all rights set to www-data.www-data, chmod 777 everything
Josh says
Figured out the 404. The cgi-bin directory has to exist.
Josh says
I keep getting 404s.
The requested URL /cgi-bin/php5.external/index.php was not found on this server.
Web Hosting says
Thanks for the small tutorial. Just wanted to point out here that thanks for the separate PHP-FPM pool files it is finally possible to run the PHP interpreter under different user accounts.