未加星标

How to install PHP 7 (PHP-FPM & FastCGI) for ISPConfig 3 on Debian 8

字体大小 | |
[开发(php) 所属分类 开发(php) | 发布者 店小二04 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

The first Beta ofphp 7 is available for download now, PHP 7 isup to 2timesfaster then php 5.6 and 14 times faster then php 5.0 according to the release notes. The new PHP version is not 100% compatible with PHP 5.x as some deprecated API's have been removed, so it is a good idea to start testing your websites for compatibility with this new release. This can be done easily and without affecting all sites on your server by using the multi PHP version feature in ISPConfig 3. The PHP version can be selected in the ISPConfig 3 website settings for each site individually. This feature works with PHP-FPM and FastCGI. This tutorial shows how to build the new PHP 7 (Beta) as a PHP-FPM and a FastCGI version on a Debian Jessieserver. These PHP 7 builds include Zend OPcache.

Preliminary Note

I will install PHP 7 that is currently in Beta at the time of this writing. Please note that PHP-FPM can be used on both Apache and nginx servers, while FastCGI is available only for Apache servers.

With older PHP versions, PHP-FPM and FastCGI had beenmutually exclusive so that a fpm and FastCGI binary hadbeen build separately. With PHP 7, both binaries can be build together, so we will have to do just one PHP build now.

CompilePHP 7 with PHP-FPM and Fastcgi

Download and extract PHP 7:

mkdir -p /opt/php-7.0.0

mkdir /usr/local/src/php5-build

cd /usr/local/src/php5-build

wget https://downloads.php.net/~ab/php-7.0.0beta1.tar.bz2-O php-7.0.0.tar.bz2

tar jxf php-7.0.0.tar.bz2

cd php-7.0.0beta1/

Install the prerequisites for building PHP 7 and the nano editor that I will use to edit the config files:

apt-get install build-essential nano

apt-get install libfcgi-dev libfcgi0ldbl libjpeg62-turbo-dbg libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-devlibxml2-devlibbz2-devlibcurl4-openssl-devlibjpeg-devlibpng12-devlibfreetype6-devlibkrb5-devlibpq-dev libxml2-devlibxslt1-dev

ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a

(The last command is needed if you build PHP with --with-imap , because otherwise ./configure will stop with the following error:

checking for crypt in -lcrypt... yes

configure: error: Cannot find imap library (libc-client.a). Please check your c-client installation.

[email protected]:/usr/local/src/php5-build/php-7.0.0#

)

Configure and build PHP 7.0.0 as follows (you can adjust the ./configure command to your needs, take a look at

./configure --help

to see all available options; if you use a different ./configure command, it is possible that additional libraries are required, or the build process will fail):

./configure --prefix=/opt/php-7.0.0 --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --with-mcrypt --with-zlib --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-mysqli --with-pdo-mysql --with-mysqli --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu --enable-ftp --with-imap --with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm

The last switch ( --enable-fpm ) makes sure this PHP version will work with PHP-FPM.

makemake install

Copy php.ini and php-fpm.conf to the correct locations:

cp /usr/local/src/php5-build/php-7.0.0beta1/php.ini-production /opt/php-7.0.0/lib/php.ini

cp /opt/php-7.0.0/etc/php-fpm.conf.default /opt/php-7.0.0/etc/php-fpm.confcp/opt/php-7.0.0/etc/php-fpm.d/www.conf.default/opt/php-7.0.0/etc/php-fpm.d/www.conf

Open /opt/php-7.0.0/etc/php-fpm.conf and adjust the following setting (remove the # in front of the pid line):

nano /opt/php-7.0.0/etc/php-fpm.conf

[...]
pid = run/php-fpm.pid
[...]

Then open /opt/php-7.0.0/etc/php-fpm.conf and adjust the listen line, you must use an unused port (e.g. 8999 ; port 9000 might be in use by Debian's default PHP-FPM already):

nano/opt/php-7.0.0/etc/php-fpm.d/www.conf

[...]
listen = 127.0.0.1:8999
[...]

Debian supports Systemd as well as the traditional init scripts. First I will create an init script for the php-fpm service and then I will create a systemd unit.

First create an init script for PHP-FPM:

nano /etc/init.d/php-7.0.0-fpm

#! /bin/sh
### BEGIN INIT INFO
# Provides: php-7.0.0-fpm
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-7.0.0-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO
php_fpm_BIN=/opt/php-7.0.0/sbin/php-fpm
php_fpm_CONF=/opt/php-7.0.0/etc/php-fpm.conf
php_fpm_PID=/opt/php-7.0.0/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm "
$php_fpm_BIN $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed. Use force-exit"
exit 1
else
echo " done"
echo " done"
fi
;;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload}"
exit 1
;;
esac

Make the init script executable and create the system startup links:

chmod 755 /etc/init.d/php-7.0.0-fpminsserv php-7.0.0-fpm

And now create the systemd unit file

nano/lib/systemd/system/php-7.0.0-fpm.service

with the follwoing content:

[Unit]
Description=The PHP 7 FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/opt/php-7.0.0/var/run/php-fpm.pid
ExecStart=/opt/php-7.0.0/sbin/php-fpm --nodaemonize --fpm-config /opt/php-7.0.0/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target

And reload systemd:

systemctl daemon-reload

Finally start PHP-FPM.

For systems with traditional init system, run:

/etc/init.d/php-7.0.0-fpm start

The result should be:

/etc/init.d/php-7.0.0-fpm startStarting php-fpm

本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师

主题: PHPDebianCGSPC
分页:12
转载请注明
本文标题:How to install PHP 7 (PHP-FPM & FastCGI) for ISPConfig 3 on Debian 8
本站链接:http://www.codesec.net/view/480111.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(php) | 评论(0) | 阅读(37)