下载安装包
wget http://cn2.php.net/distributions/php-7.2.5.tar.gz
tar -zxvf php-7.2.5.tar.gz
安装依赖
yum -y 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
编译安装
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/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 \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--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-exif \
--enable-fileinfo \
--enable-calendar \
--enable-readline \
--enable-sodium \
--enable-sysvmsg \
--enable-sysvshm \
--enable-wddx
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/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 \
--disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-libmbfl --enable-ftp \
--with-gd --enable-gd-jis-conv --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-exif --enable-fileinfo --enable-calendar --enable-readline --enable-sodium \
--enable-sysvmsg --enable-sysvshm --enable-wddx
安装
make && make install
修改配置文件
cp php.ini-development /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp -a php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp -a www.conf.default www.conf
添加全局变量
ln -sf /usr/local/php/bin/php /usr/bin/php
ln -sf /usr/local/php/bin/phpize /usr/local/bin/phpize
#查看扩展信息
php -i
#查看已安装的扩展
php -m
添加www用户
#php-fpm默认的启动用户是www,如果没有www用户需要先添加
groupadd www
useradd www
useradd -g www www
使用systemctl管理php-fpm
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#重载配置
systemctl daemon-reload
systemctl 命令
systemctl status php-fpm
systemctl stop php-fpm
systemctl start php-fpm
systemctl retart php-fpm
第三方扩展(igbinary,psr,phalcon,redis,swoole)安装
#下载
wget https://pecl.php.net/get/igbinary-3.2.1.tgz
wget https://pecl.php.net/get/phalcon-4.1.0.tgz
wget https://pecl.php.net/get/psr-1.0.1.tgz
wget https://pecl.php.net/get/redis-5.3.2.tgz
wget https://pecl.php.net/get/swoole-4.5.10.tgz
#解压编译安装(以igbinary为例)
tar -zxvf igbinary-3.2.1.tgz
cd igbinary
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
#在php.ini添加扩展选项
extension=igbinary
#查看扩展
php -m
扩展问题
1.sodium扩展问题
checking for re2c… no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk… gawk
checking for sodium support… yes, shared
checking for pkg-config… /usr/bin/pkg-config
checking for libsodium… configure: error: Please install libsodium - See https://github.com/jedisct1/libsodium
解决办法
1. yum -y groupinstall "Development Tools"
2. wget https://github.com/jedisct1/libsodium/releases/download/1.0.11/libsodium-1.0.11.tar.gz
3. tar xf libsodium-1.0.11.tar.gz && cd libsodium-1.0.11
4. ./configure && make -j2 && make install
5. echo /usr/local/lib > /etc/ld.so.conf.d/usr_local_lib.conf
6. ldconfig
2.configure: error: Cannot find ldap libraries in /usr/lib
解决办法
cp -frp /usr/lib64/libldap* /usr/lib/