环境
我使用的是Ubuntu14.04 LTS,安装PHP7.1.5过程记录,如下。
安装php过程
获取源码
wget http://am1.php.net/distributions/php-7.1.4.tar.gz
tar zxvf php-7.1.5.tar.gz
cd php-7.1.5
安装依赖
sudo apt-get update
sudo apt-get install libkrb5-dev \
libc-client2007e \
libc-client2007e-dev \
libcurl4-openssl-dev \
libbz2-dev \
libjpeg-dev \
libmcrypt-dev \
libxslt1-dev \
libxslt1.1 \
libpq-dev \
libpng12-dev \
libfreetype6-dev \
build-essential \
编译
./configure --prefix=/usr/local/php \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
configure过程中爆出缺什么的错误,就在上面安装依赖的命令中加一条 apt-get install lib<缺的东西名字>-dev(el)
// 根据机子cpu数,分配编译进程数,以加快编译
sudo make -j4
sudo make install
编译完成,返回一些执行文件路径、和配置文件位置
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
# PHP-FPM 配置文件
Installing PHP FPM defconfig: /usr/local/php/etc/
Installing PHP FPM man page: /usr/local/php/php/man/man8/
Installing PHP FPM status page: /usr/local/php/php/php/fpm/
Installing phpdbg binary: /usr/local/php/bin/
Installing phpdbg man page: /usr/local/php/php/man/man1/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/php/php/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
//php-fpm的执行文件位置
/usr/local/php/sbin/php-fpm
FPM启动前的配置
进入php-fpm.conf所在目录
cd /usr/local/php/etc
配上php-fpm.conf以及php.ini,具体配置可见: http://www.cnblogs.com/ahaii/p/5776809.html
sudo mv php-fpm.conf.default php-fpm.conf
sudo mv ./php-fpm.d/www.conf.default ./php-fpm.d/www.conf
sudo cp src/php-7.1.5/php.ini-development usr/local/php/lib/php.ini
配置pm的运行方式
- 以静态(static)方式运行
pm = static
// 启动指定数目的子进程
pm.max_children = 5
- 以动态方式运行
pm = dynamic
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
- 运行方式的选择
- 内存较小的机子通常使用动态方式,可以释放多余的进程,可以回收一定的内存
- 内存较大的机子可使用静态方式,指定静态的小数量,保证系统的平稳
配置pm进程重启
累计到500个请求之后自动重启该进程
pm.max_requests = 500
给fpm指定执行用户
- 修改php-fpm/www.conf
user = www
group = www
- 添加系统用户
sudo adduser www
启动/停止/重启fpm
//启动
sudo /usr/local/php/sbin/php-fpm
//停止
kill -INT pid
//重启
kill -USR2 pid