部署平台:ceontos7
物理机:Dell R430
注意:
php在于nginx和httpd结合时,有不同的工作模式;
在php+httpd(apache)结合时,php是作为httpd的一个模块存在的;
在php+nginx结合时,php只能使用php-fpm模式,才能与其结合工作;
所以,当使用nginx时,php应该使用fpm机制;
安装依赖:
]# yum install -y libxml2-devel libmcrypt-devel bzip2-devel
]# tar -xf php-5.6.30.tar.gz -C /usr/local/
编译:
]# ./configure --prefix=/usr/local/php-5.6.0 --with-mysql=/usr/local/mysql --with-mysql-sock --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-fpm --enable-soap --with-libxml-dir --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --with-libmbfl --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear
WARNING: unrecognized options: --with-ncurses, --with-XMLrpc, --enable-sqlite-utf8
表示此项已经不用;无需关心,继续编译既可;
]# make -j 2 && make install
复制配置文件:
]# cd /usr/local/php-5.6.0/etc/
]# cp php-fpm.conf.default php-fpm.conf
根据需要修改FPM 配置文件php-fpm.conf
启动php-fpm:
]# /usr/local/php-5.6.0/sbin/php-fpm
命令导出:
ln -s /usr/local/php-5.6.0/sbin/php-fpm /bin/php-fpm
制作启动服务器脚本:
]# vim /etc/init.d/php-fpm
#! /bin/sh
#chkconfig: 2345 60 90
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="php-fpm daemon"
NAME=php-fpm
INSTALLDIR=/usr/local/php-5.6.0
DAEMON=$INSTALLDIR/sbin/$NAME
CONFIGFILE=$INSTALLDIR/etc/$NAME.conf
PIDFILE=$INSTALLDIR/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -D || echo -n "php-fpm already running"
}
do_stop() {
kill -INT `cat $PIDFILE` || echo -n "php-fpm not running"
}
do_test() {
$DAEMON -t || echo -n "php-fpm can't test"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
test)
echo -n "Testing $DESC: $NAME"
do_test
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|test}" >&2
exit 3
;;
esac
exit 0
添加权限:
]# chmod +x /etc/init.d/php-fpm
添加自动启动:
]# chkconfig --add php-fpm
设置启动运行级别:
]# chkconfig --level 2345 php-fpm on
查看验证自启动服务:
]# chkconfig --list
有研发要求再准备一台php7.2的服务器用来做测试,下一步准备全部把php5.6更新为php7:
php7.2.4编译:
centos7编译安装php7.2.4:
安装依赖:
]$ sudo yum install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
创建用户和组,并下载php安装包解压:(此前创建过www用户,可忽略此步骤)
]$ cd /tmp
]$ groupadd www
]$ useradd -g www www
]$ wget http://am1.php.net/distributions/php-7.2.1.tar.gz
编译:
]$ tar xvf php-7.2.4.tar.gz -C /tmp
]$ cd /tmp/php-7.2.4
]$ cp -frp /usr/lib64/libldap* /usr/lib/
]$ ./configure --prefix=/usr/local/php7.2.4 --with-config-file-path=/usr/local/php7.2.4/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --enable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-libmbfl --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm
注意:–enable-gd-jis-conv 此参数会导致Zabbix中文字符乱码,建议取消。
编译时可能会报错,不支持几个扩展参数,删除即可;
安装:
make -j 4 && make install
安装后配置php.ini文件:
参考文档:https://renwole.com/archives/29
说明:
mysql做了别名,可直接使用mysql命令登陆;
grant all on *.* to root@'localhost' identified by 'root';
grant all on *.* to root@'127.0.0.1' identified by 'root';