准备
# 下载
wget [https://www.php.net/distributions/php-7.2.22.tar.gz](https://www.php.net/distributions/php-7.2.22.tar.gz)
# 解压
tar -zxvf php-7.2.22.tar.gz
# 进度php解压包
cd php-7.2.22
# 安装依赖库
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel autoconf
# 配置编译
/***********************************重点*************************************************/
./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--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 \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--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 \
--enable-opcache
注意:--prefix=[php安装路径]
注意:例如没有加
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
那么mysql扩展就无法安装成功
/***********************************重点*************************************************/
# 编译
make
# 安装
make install
安装后的配置
# 执行完安装命令后php7就已经安装在到了/usr/local/php7目录下了。
/usr/local/php7/bin/php -v
# 添加环境变量
vim /etc/profile
在文件的最后面添加下面两行代码
PATH=$PATH:/usr/local/php7/bin
export PATH
# 更新环境变量
source /etc/profile
# 查看环境变量
echo $PATH
# 查看php版本
php -v
配置PHP-FPM
cp php.ini-production /etc/php.ini
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
# 启动php-fpm
/etc/init.d/php-fpm start
或者
service php-fpm start
# 如果报错
Starting php-fpm [12-May-2018 20:09:45] ERROR: [pool www] cannot get uid for user 'www'
# 说明没有该用户,直接执行
groupadd www
useradd -g www www
进程等状态查看
# php 启动状态
ps -ef|grep php
网友评论