centos7手动安装php7

编译环境
阿里源

# 安装编译环境
yum -y install gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel mcrypt mhash
yum -y install php-mcrypt libmcrypt libmcrypt-devel
# 当然常用的软件还是要安装的
yum -y install wget git
# 如果提示:mcrypt.h not found. Please reinstall libmcrypt
## 备份源
cd  /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
# 下载阿里源
# http://mirrors.aliyun.com/repo/
wget http://mirrors.aliyun.com/repo/Centos-7.repo
# 使用源
mv Centos-7.repo CentOS-Base.repo
# 更新源
yum clean all
yum makecache
yum update
# 如果还是不行
# 直接编译libmcrypt源码
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure --prefix=/usr/local
make && make install

编译

# 下载
wget http://cn2.php.net/distributions/php-7.1.0.tar.gz
tar zxvf php-7.1.0.tar.gz
cd php-7.1.0
# 配置(centos6直接执行)
./configure \
--prefix=/usr/local/php7 \
--exec-prefix=/usr/local/php7 \
--bindir=/usr/local/php7/bin \
--sbindir=/usr/local/php7/sbin \
--includedir=/usr/local/php7/include \
--libdir=/usr/local/php7/lib/php \
--mandir=/usr/local/php7/php/man \
--with-config-file-path=/usr/local/php7/etc \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mcrypt=/usr/include \
--with-mhash \
--with-openssl \
--with-mysql=shared,mysqlnd \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache \
--enable-redis \
--enable-fpm \
--enable-fastcgi \
--with-fpm-user=www \
--with-fpm-group=www \
--without-gdbm \
--disable-fileinfo
# 常见错误
## error: Don't know how to define struct flock on this system, set --enable-opcache=no
## 编辑nano /etc/ld.so.conf最后添加/usr/local/lib,再执行ldconfig -v
## WARNING: unrecognized options: --with-mysql, --enable-redis, --enable-fastcgi
## centos7 去掉这先参数
./configure \
--prefix=/usr/local/php7 \
--exec-prefix=/usr/local/php7 \
--bindir=/usr/local/php7/bin \
--sbindir=/usr/local/php7/sbin \
--includedir=/usr/local/php7/include \
--libdir=/usr/local/php7/lib/php \
--mandir=/usr/local/php7/php/man \
--with-config-file-path=/usr/local/php7/etc \
--with-mcrypt=/usr/include \
--enable-opcache \
--with-mhash \
--with-openssl \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--without-gdbm \
--disable-fileinfo
# 开始编译
make
# 安装
make install
# 找到php-cgi的位置
# 在/usr/local/php7里面
php-cgi -v
# 完成
# 关于扩展
# 新建/usr/local/php7/etc/php.ini,添加(mysqli为例)
# 已经编译好的so扩展文件在/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303目录里面
extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/mysqli.so
extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/pdo_mysql.so
# 或者
extension_dir = /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/
# kangle服务器>扩展>命令>环境变量 添加ini文件位置
/usr/local/php7/etc/php.ini
# 重启kangle可

方案二
直接安装

# 版本很老5.4
yum -y install php php-cgi

方案三(推荐,但是就是国外源很慢)
SCL安装

# 荐用SCL(Software Collections)软件库安装高版本的PHP
yum install centos-release-scl-rh
# 搜索版本
yum search php
# 安装
yum install rh-php70
# 安装完之后,PHP实际会安装在/opt/rh目录下,php和php-cgi目录
/opt/rh/rh-php71/root/bin
# 查看SCL安装了哪些软件
scl -l
# 可以先启用它并执行命令
scl enable rh-php71 "php -v"
# 执行 bash 命令,那么新开的shell就能自动识别php
scl enable rh-php71 bash
php -v
# 扩展和ini配置,例如mysqli
yum install -y rh-php71-php-mysqlnd
# 查看30-mysqli.ini
/etc/opt/rh/rh-php71/php.d/

php扩展安装详情
blog

你可能感兴趣的:(php,centos)