centos 安装 php7

centos6.5 安装php7:
我采用的是编译安装方式。步骤如下:
1.安装依赖包
2.下载源码包
3.解压
4.配置configure
5.编译执行
6.配置
7.运行

1.安装依赖包
安装php7前需要安装所有的依赖,可参考如下(我需要用到postgresql,所以需要安装 postgresql-devel):

# 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 pcre-devel postgresql-devel -y

2.下载源码包:

# wget http://cn2.php.net/get/php-7.0.6.tar.gz/from/this/mirror php-7.0.6.tar.gz

3. 解压:

$ tar zxvf php-7.0.6.tar.gz

进入解压目录:

# cd php-7.0.6

4. 创建编译配置文件: 我使用的是postgresql 数据 ,因此需要加载 pdo-pgsql  

# ./configure

--prefix=/usr/local/php7.0.12
--with-config-file-path=/usr/local/php7.0.12/etc
--enable-fpm
--with-fpm-user=nginx
--with-fpm-group=nginx
--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-pdo-pgsql=/usr/pgsql-9.5
--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
--with-pear
--enable-opcache
--with-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config
--with-pdo-mysql=/usr/local/mysql


安装可能会出现异常的报错,一般是依赖导致的,根据报错信息安装和修复相关依赖:

比如:

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

这种情况就需要编译安装libmcrypt,因为yum安装的内容没有mcrypt.h文件。】

下载源代码:

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

解压:

tar xvf libmcrypt-2.5.7.tar.gz

配置:

cd libmcrypt-2.5.7

./configure

编译

make

make install

完毕后,我们发现多了文件

/usr/local/include/mcrypt.h

如果出现“configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no”之类的错误
解决办法:
ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/libmysqlclient.so
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

在/etc/ld.so.conf.d中添加local.conf文件:

# echo "/usr/local/lib">> /etc/ld.so.conf.d/local.conf

更新动态库:

# ldconfig -v

  

 5.编译执行

# make  &&  make install

编译错误会有日志信息。有错误一般是依赖没有安装或者依赖的配置路径不对,比如要引入pdo_pgsql  ,需要在配置中添加且后面要指定已经安装的pgsql数据的安装路径:  --with-pdo-pgsql=/usr/pgsql-9.5/

编译成功后建议将php的路径添加到环境变量path中,这样每次登陆都会自动匹配到php的路径。

# vim /etc/profile

在末尾加入

PATH=$PATH:/usr/local/php/bin

export PATH

要使改动立即生效执行

# ./etc/profile

或 

# source /etc/profile

查看php版本
# php -v

6.配置php-fpm

配置主要是启动的配置加载文件

# cp php.ini-production /etc/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/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

 7.运行

# /etc/init.d/php-fpm
# ps -ef | grep php // 可以查看启动的进程, netstat -an -tcp | grep php 可以查看网络端口9000已经启动。
原文地址:https://www.cnblogs.com/mywebnumber/p/5534171.html