How to switch prefork mode to FastCGI Process Manager(FPM) in Apache2 server
It works on Apache FastCGI module and php7.x-fpm module to make Apache2.4
server to be an event-base server. FPM (FastCGI Process Manager) is an
alternative PHP FastCGI implementation with some additional features
(mostly) useful for heavy-loaded sites.
How to install php7.0-fpm & make Apache server works with it?
>> $ vim /etc/apache2/apache2.conf
add a ServerName = [DNS or IP] if it is not existed.
>> $ apt-get install libapache2-mod-fastcgi php7.0-fpm
>> $ a2dismod mpm_prefork (disable apache mpm default mudule)
>> $ a2enmod mpm_event (enable apache mpm event module)
>> $ a2enmod proxy_fcgi setenvif (important for fpm)
>> $ a2dismod php7.0 (VERY important to close php module in Apache)
>> $ a2enconf php7.0-fpm (enable the config-file for php-fpm module)
>> $ vim /etc/apache2/conf-available/php7.0-fpm.conf
>> $ touch /usr/lib/cgi-bin/ php7.fcgi (Add file, php7.fcgi, to
directory /usr/lib/cgi-bin)
>> $ chown –R www-data:www-data /usr/lib/cgi-bin (change permission)
>> $ systemctl start php7.0-fpm
>> $ systemctl enable php7.0-fpm
>> $ systemctl restart php7.0-fpm
>> $ apachectl –V | grep –I mpm (check apache switch to event already)
>> $ vim /etc/php/7.0/fpm/php.ini
Edit php.ini working for fpm as php.ini mapping to Apache2(in folder
/etc/php/7.0/apache2), and uncomment a line in php.in file for cgi
setting:
cgi.fix_pathinfo=0 (good for security).
>> $ service apache2 restart && service php7.0-fpm restart (restart all
service related with each other)
At the last step, to use phpinfo() function to check the Server API is switched.
TIP:
Write a shell script file as below, and execute it for anytime you need(especially, after Ubuntu system upgrade, it may make Apache2 prefork mode back automatically.):
#!/bin/bash
echo "apache2 event model start enable..."
service apache2 stop
serivce php7.0-fpm stop
a2dismod mpm_prefork
a2enmod mpm_event
a2dismod php7.0
a2enconf php7.0-fpm
systemctl start php7.0-fpm
systemctl enable php7.0-fpm
systemctl restart php7.0-fpm
service apache2 restart
serivce php7.0-fpm restart
echo "apache2 event model are completed!"
apachectl -V | grep -i mpm
Congratulations! You finish it.
server to be an event-base server. FPM (FastCGI Process Manager) is an
alternative PHP FastCGI implementation with some additional features
(mostly) useful for heavy-loaded sites.
How to install php7.0-fpm & make Apache server works with it?
>> $ vim /etc/apache2/apache2.conf
add a ServerName = [DNS or IP] if it is not existed.
>> $ apt-get install libapache2-mod-fastcgi php7.0-fpm
>> $ a2dismod mpm_prefork (disable apache mpm default mudule)
>> $ a2enmod mpm_event (enable apache mpm event module)
>> $ a2enmod proxy_fcgi setenvif (important for fpm)
>> $ a2dismod php7.0 (VERY important to close php module in Apache)
>> $ a2enconf php7.0-fpm (enable the config-file for php-fpm module)
>> $ vim /etc/apache2/conf-available/php7.0-fpm.conf
>> $ touch /usr/lib/cgi-bin/ php7.fcgi (Add file, php7.fcgi, to
directory /usr/lib/cgi-bin)
>> $ chown –R www-data:www-data /usr/lib/cgi-bin (change permission)
>> $ systemctl start php7.0-fpm
>> $ systemctl enable php7.0-fpm
>> $ systemctl restart php7.0-fpm
>> $ apachectl –V | grep –I mpm (check apache switch to event already)
>> $ vim /etc/php/7.0/fpm/php.ini
Edit php.ini working for fpm as php.ini mapping to Apache2(in folder
/etc/php/7.0/apache2), and uncomment a line in php.in file for cgi
setting:
cgi.fix_pathinfo=0 (good for security).
>> $ service apache2 restart && service php7.0-fpm restart (restart all
service related with each other)
At the last step, to use phpinfo() function to check the Server API is switched.
TIP:
Write a shell script file as below, and execute it for anytime you need(especially, after Ubuntu system upgrade, it may make Apache2 prefork mode back automatically.):
#!/bin/bash
echo "apache2 event model start enable..."
service apache2 stop
serivce php7.0-fpm stop
a2dismod mpm_prefork
a2enmod mpm_event
a2dismod php7.0
a2enconf php7.0-fpm
systemctl start php7.0-fpm
systemctl enable php7.0-fpm
systemctl restart php7.0-fpm
service apache2 restart
serivce php7.0-fpm restart
echo "apache2 event model are completed!"
apachectl -V | grep -i mpm
Congratulations! You finish it.
留言
張貼留言