添加的库文件路径一定要和系统平台arch一致,32bit的系统直接添加【/usr/local/lib】即可,64bit系统要填加【/usr/local/lib64.】否则依旧会报错,本文将详细介绍centos7下如何安装PHP7。
一、官网安装方法:
http://php.net/manual/zh/install.unix.nginx.php
相关学习推荐:PHP 编程从入门到精通
二、编译安装
1.下载php7
wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.20.tar.gz/from/this/mirror
或者直接网页下载
http://php.net/get/php-7.1.20.tar.gz/from/a/mirror
2.解压php7
tar -xvf php7.tar.gz
3.进入php目录
cd /usr/local/src/php-7.1.20
4.安装依赖包
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
5.编译配置(如果出现错误,基本都是上一步的依赖文件没有安装所致)
./configure
–prefix=/software/php
–with-config-file-path=/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
报错解决
最实用的解决办法如下:
问题:
1: wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
2: tar zxf libmcrypt-2.5.7.tar.gz
3: ./configure –prefix=/usr/local
4: make && make install
问题:configure: error: Don't know how to define struct flock on this system, set –enable-opcache=no
解决:解决办法:
vim /etc/ld.so.conf.d/local.conf # 编辑库文件
/usr/local/lib # 添加该行
ldconfig -v # 使之生效
注意事项:
这里添加的库文件路径一定要和你系统平台arch一致,32bit的系统直接添加/usr/local/lib即可,64bit系统要填加/usr/local/lib64.否则依旧会报错,我当时就是添加了/usr/local/lib死活编辑不了,后来更改为/usr/local/lib64才可以。
6.正式安装
make && make install
7.配置环境变量
vi /etc/profile
PATH=$PATH:/usr/local/php/bin
export PATH
source /etc/profile
8.配置php-fpm
cp php.ini-production /usr/local/php/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 /usr/local/php/etc/php-fpm
chmod +x /usr/local/php/etc/php-fpm
ln /usr/local/php/etc/php.ini /etc/php.ini
9、创建www用户
useradd www
10、配置启动项参数
vim /usr/local/php/etc/php-fpm.d/www.conf
pm.max_children = 500
pm.start_servers = 105
pm.min_spare_servers = 10
pm.max_spare_servers = 200
11.启动php-fpm
/usr/local/php/etc/php-fpm start
设置 php-fpm开机启动
cp /usr/local/src/php-5.5.14/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录
chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
chkconfig php-fpm on #设置开机启动
service php-fpm start
pkill php-fpm 强制关闭