添加的库文件路径一定要和系统平台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/profilePATH=$PATH:/usr/local/php/binexport PATHsource /etc/profile
8.配置php-fpm
cp php.ini-production /usr/local/php/etc/php.inicp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confcp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.confcp sapi/fpm/init.d.php-fpm /usr/local/php/etc/php-fpmchmod +x /usr/local/php/etc/php-fpmln /usr/local/php/etc/php.ini /etc/php.ini
9、创建www用户
useradd www
10、配置启动项参数
vim /usr/local/php/etc/php-fpm.d/www.confpm.max_children = 500pm.start_servers = 105pm.min_spare_servers = 10pm.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 startpkill php-fpm 强制关闭
以上就是centos7下如何安装PHP7?的详细内容,更多请关注24课堂在线网其它相关文章!