linux's docs

21.4.0: LAMP-PHP安装


0. 源码文件和安装包

github链接:https://github.com/xiaotuanyu120/install-lnmp


1. php5.6.21安装脚本

## VARIABLE SETTING
PHPDIR=/usr/local/php
CONFDIR=$PHPDIR/etc
APXS=/usr/local/apache2/bin/apxs

## USER CREATE
useradd -r -s /sbin/nologin php-fpm

## BASE PACKAGE INSTALLATION
yum install gcc gcc-c++ cmake ncurses-devel epel-release -y
yum groupinstall base "Development Tools" -y
yum install libxml2-devel libcurl-devel libjpeg-turbo-devel libpng-devel freetype-devel php-mcrypt libmcrypt-devel libevent-devel openssl-devel -y

## LIB PREPARE
[ -e "/usr/lib/libjpeg.so" ] || ln -s /usr/lib64/libjpeg.so /usr/lib/libjpeg.so
[ -e "/usr/lib/libpng.so" ] || ln -s /usr/lib64/libpng.so /usr/lib/libpng.so

## TARBALL INSTALL PHP
tar zxvf php-5.6.21.tar.gz
cd php-5.6.21
./configure --prefix=$PHPDIR --with-config-file-path=$CONFDIR --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd --with-apxs2=$APXS --with-libxml-dir  --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-curl --with-openssl
make
make install

## INI FILE AND DAEMON FILE PREPARE
mkdir $CONFDIR
cp php.ini-production $CONFDIR/php.ini
cp $CONFDIR/php-fpm.conf.default $CONFDIR/php-fpm.conf
cp sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm

sed -i 's/.*pm.max_children =.*/pm.max_children = 50/g' $CONFDIR/php-fpm.conf
sed -i 's/.*pm.start_servers =.*/pm.start_servers = 20/g' $CONFDIR/php-fpm.conf
sed -i 's/.*pm.min_spare_servers =.*/pm.min_spare_servers = 5/g' $CONFDIR/php-fpm.conf
sed -i 's/.*pm.max_spare_servers =.*/pm.max_spare_servers = 35/g' $CONFDIR/php-fpm.conf
sed -i "s#.*pid.*php-fpm.pid.*#pid = $PHPDIR/var/run/php-fpm.pid#g" $CONFDIR/php-fpm.conf


## SERVICE ENABLE AND START
chkconfig --add php-fpm
chkconfig php-fpm on

2. 脚本中PHP配置说明

## 脚本中所配置的选项及其说明
## 模式选择
pm = static/dynamic

## STATIC MODE
pm.max_children - 同一时间可存在的最大进程数

## DYNAMIC MODE
pm.start_servers - php启动时创建的进程数
pm.min_spare_servers - 处于idle状态下最少的进程数,少于此数会创建进程
pm.max_spare_servers - 处于idle状态下最多的进程数,多于此数会杀掉进程
pm.max_children - 同static中的效果,和pm.max_spare_servers区别在于,后者是设定的idel状态进程数,而前者是配置的所有状态下进程最大数目

Contents