CentOS7源码包编译安装php7.2完整版

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

一、安装准备

1、预备:PHP7.2源码包【PHP官网获取 http://php.net/downloads.php 】、确定安装位置

2、安装依赖

yum install openssl openssl-devel
yum -y install curl-devel
yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y
yum install libjpeg-devel
yum install bzip2-devel.x86_64 -y
yum install libXpm-devel
yum install gmp-devel
yum install -y icu libicu libicu-devel
yum install  postgresql-devel
yum install libxslt-devel
yum -y install ncurses ncurses-devel
yum -y install libxml2 libxml2-devel
yum -y install gd
yum -y install gd-devel
yum -y install flex
yum -y install zlib-devel
yum -y install freetype-devel
yum -y install libssl-dev
yum -y install gmp-devel
yum -y install unixODBC-devel
yum -y install pspell-devel
yum -y install net-snmp net-snmp-devel
yum -y install openldap-devel openldap-servers openldap-clients
yum -y install zlib-devel
yum install libc-client-devel
yum  install  php-mcrypt  libmcrypt  libmcrypt-devel

如上面的yum install出现 No package php-mcrypt available. 那么:

#扩展包更新包
yum  install epel-release
#编辑,注释掉原来的,使用新的base_url
/etc/yum.repos.d/epel.repo
#baseurl
mirrorlist
改成
baseurl
#mirrorlist

3、用户及用户组建立

groupadd www-data
useradd -g www-data www-data

二、编译安装 1、configure(建议先configure --help对着文档及网上资料一个个了解选项意义)

./configure --prefix=/usr/local/php \
--enable-fpm \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--with-pdo-pgsql \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock=/data/mysqldata/3306/mysql.sock \
--with-pgsql \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-soap \
--enable-calendar \
--with-curl \
--with-gd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-pdo-mysql \
--with-mysqli \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--with-libdir=/lib/x86_64-linux-gnu/ \
--enable-ftp \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-opcache \
--with-iconv \
--with-xpm-dir=/usr \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-iconv-dir \
--with-kerberos \
--with-pdo-sqlite \
--with-pear \
--enable-libxml \
--enable-shmop \
--enable-xml

2、如果在编译安装时,提示unrecognized options: –with-mcrypt, –enable-gd-native-ttf表示php7.2不支持这两个选项,把上面两个编译选项删除就可以了。

3、三步走(make和make test排错,最后再make install,切记,细心、耐心)

make
make test
make install

4、安装好之后的工作(如果在./configure选项中enable了pear需要执行下面命令)

/usr/local/php/bin/pear install channel://pear.php.net/PHP_Archive-0.12.0
/usr/local/php/bin/pear channel-update pear.php.net

5、设置用户变量

ln -s /usr/local/php/bin/php /usr/bin/php

6、配置php-fpm

#建立主配置文件:
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#次配置文件(被上方的php-fpm.conf中include):在其中可以配置php-fpm启动的端口、指定它的用户组及用户等
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
#拷贝php-fpm进程管理文件:
cp /usr/local/src/php-7.2.1/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#赋予增加php-fpm的可执行权限
chmod +x /etc/init.d/php-fpm
#为了方便将php-fpm加到管理员命令目录:
ln -s /etc/init.d/php-fpm /usr/sbin/php-fpm

7、开启php-fpm

php-fpm start/restart/stop

输出信息:

Starting php-fpm  done

8、顺便装下composer咯

  1. 先随便找个地方装composer.phar

  2. 安装

php -r "readfile('https://getcomposer.org/installer');" | php
  1. 放入bin并重命名
mv ./composer.phar /usr/bin/composer
  1. 运行composer,安装完成

  2. 官网扩展位置传送门:https://pecl.php.net/packages.php

转载于:https://my.oschina.net/cxgphper/blog/2050504

你可能感兴趣的:(php,运维,数据库)