apache - Specify PHP ini file per vhost, with FastCGI/PHP-fpm configuration -
okay, going crazy trying figure out. (i have read hundreds of questions/answers, , google articles, none have answered it)
i have changed using mod_php
using php through fastcgi , fpm, using method described in this question, purely because under impression 'easy' specify php.ini files individual vhosts using set-up.
what i'm pulling hair out over, how can specify custom php ini file each vhost uses?
luckily, it's on test rig far ... hoping same on production server if can ever figure out
i thought may as-well post whole process took configure fpm pools, @christianm mentioned, because i've not yet found full explanation on how it.
the first part of copy of askubuntu post: https://askubuntu.com/questions/378734/how-to-configure-apache-to-run-php-as-fastcgi-on-ubuntu-12-04-via-terminal/527227#comment905702_527227
the last part how configure pools, , vhost use relevent pool settings
here goes:
install apache mpm worker (explanation of prefork/wroker , event @ http://www.vps.net/blog/2013/04/08/apache-mpms-prefork-worker-and-event/):
sudo apt-get install apache2-mpm-worker
install fastcgi , php5-fpm:
sudo apt-get install libapache2-mod-fastcgi php5-fpm
now enable mods need, , disable don't:
sudo a2dismod php5 mpm_prefork sudo a2enmod actions fastcgi alias mpm_worker
create php5.fcgi file , give webserver permission use it.
sudo touch /usr/lib/cgi-bin/php5.fcgi sudo chown -r www-data:www-data /usr/lib/cgi-bin
create global config php5-fpm
sudo nano /etc/apache2/conf-available/php5-fpm.conf
paste in following (we'll use socket instead of ip address)
<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 -idle-timeout 3600 <directory /usr/lib/cgi-bin> require granted </directory> </ifmodule>
note: ensure configs follow same new 'require granted'/'require denied' syntax ... otherwise you'll feel pain after restarting ...
enable php5-fpm conf
sudo a2enconf php5-fpm
restart apache , fpm
sudo service apache2 restart && sudo service php5-fpm restart
this setup creates global fastcgi configuration php, uses file /etc/php5/fpm/php.ini file.
if have multiple vhosts, going need different php configurations, continue example below
first, within /etc/php5/fpm/pool.d dir, find default www.conf file. copy this, naming relevent:
sudo cp /etc/php5/fpm/pool.d/www.conf /etc/php5/fpm/pool.d/domain2.conf
edit file, changing pool name:
[...] [domain2] [...]
and change name of listen socket relevent:
[...] listen = /var/run/php5-fpm-domain2.sock [...]
then copy /usr/lib/cgi-bin/php5.fcgi file, again naming relevent:
cp /usr/lib/cgi-bin/php5.fcgi /usr/lib/cgi-bin/php5-domain2.fcgi
now you're ready add mod_fastcgi module domain2 vhost. it's same 1 described above, notice changes 'alias','fastcgiserver' , '-socket'
<virtualhost *:80> servername domain2.com [...] <ifmodule mod_fastcgi.c> addhandler php5.fcgi .php action php5.fcgi /php5.fcgi alias /php5.fcgi /usr/lib/cgi-bin/php5-domain2.fcgi fastcgiexternalserver /usr/lib/cgi-bin/php5-domain2.fcgi -socket /var/run/php5-fpm-domain2.sock -pass-header authorization -idle-timeout 3600 <directory /usr/lib/cgi-bin> require granted </directory> </ifmodule> [...] </virtualhost>
restart apache , fpm
sudo service apache2 restart && sudo service php5-fpm restart
now test changes.
in new /etc/php5/fpm/pool.d/domain2.conf file, add php value change (i've chosen session.name value):
[...] php_admin_value[session.name] = 'domain2' [...]
now test configuration before restarting fpm:
sudo php5-fpm -t
it tell if configuration fails, more importantly tell if configuration fine. can go ahead , restart fpm:
sudo service php5-fpm restart
and finally, if want super sure php value has been set, create info.php within site, , add:
<?php phpinfo(); ?>
Comments
Post a Comment