centos7.2下编译安装PHP7.1.1
浏览数 192391
赞
(0)
方法一、简单安装(通过yum)
1.安装epel-release
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
2.安装PHP7的rpm源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3.安装PHP7
yum install php70w
方法二、编译安装
1.下载php7
wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror
2.解压php7
tar -xvf php7.tar.gz
3.进入php目录
cd php-7.1.1
4.安装依赖包
yum install gcc 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=/DISKB/php711' '--with-pdo-pgsql' '--with-zlib-dir' '--with-freetype-dir' '--enable-mbstring' '--enable-soap' '--enable-calendar' '--with-mcrypt' '--with-gd' '--with-pgsql' '--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' '--enable-ftp' '--with-gettext' '--with-xmlrpc' '--with-xsl' '--enable-opcache' '--enable-fpm' '--with-iconv' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--with-openssl' '--with-fpm-user=www-data' '--with-fpm-group=www-data' '--with-libdir=/lib/x86_64-linux-gnu/' '--with-libxml-dir=/usr' '--with-curl' '--with-xpm-dir=/usr'
编译时出现错误按文章后面的解决办法安装相关依赖包,但是如果加上最后两个红色的项怎么也编译不成功,报错内容是:
configure: error: There is something wrong. Please check config.log for more information.
一直找不到原因,因为我机器上已经装好了curl,以为是不用再装了(其实curl和php的curl扩展是两回事),所以我就把红色的两项去掉了再安装。安装成功后在php中调用curl_init()果然报错了,提示没有这个函数,最后我再单独安装了php_curl的扩展,安装步骤见文章后面。
6.正式安装
make && make install
7.配置环境变量
vi /etc/profile
在末尾追加
PATH=$PATH:/usr/local/php/bin
export PATH
执行命令使得改动立即生效
source /etc/profile
8.配置php-fpm
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 /usr/src/php-7.0.2/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
9.启动php-fpm
/etc/init.d/php-fpm start
php-fpm关闭命令
pkill php-fpm
1、进入到PHP源码目录下的ext/curl目录(如果没有curl目录,那你就要重装下载一个PHP的源码包了)
cd /usr/local/php/ext/curl/
2、安装:
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-curl=DIR(默认路径时无需指定)
如果有自定义php的安装目录,则要先找到php-config路径,把上面的php-config路径修改成你机器上的实际路径
make&&make install
运行结果提醒我安装了共享扩展:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
3、修改php.ini文件
vi /usr/local/php/etc/php.ini
在其文件结尾加入下面的内容:
extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/"
extension=curl.so
4、安装完成后,重启php-fpm和web服务器。(我用的是nginx服务)
再运行curl就能正常运行了。
1.安装epel-release
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
2.安装PHP7的rpm源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3.安装PHP7
yum install php70w
方法二、编译安装
1.下载php7
wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror
2.解压php7
tar -xvf php7.tar.gz
3.进入php目录
cd php-7.1.1
4.安装依赖包
yum install gcc 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=/DISKB/php711' '--with-pdo-pgsql' '--with-zlib-dir' '--with-freetype-dir' '--enable-mbstring' '--enable-soap' '--enable-calendar' '--with-mcrypt' '--with-gd' '--with-pgsql' '--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' '--enable-ftp' '--with-gettext' '--with-xmlrpc' '--with-xsl' '--enable-opcache' '--enable-fpm' '--with-iconv' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--with-openssl' '--with-fpm-user=www-data' '--with-fpm-group=www-data' '--with-libdir=/lib/x86_64-linux-gnu/' '--with-libxml-dir=/usr' '--with-curl' '--with-xpm-dir=/usr'
编译时出现错误按文章后面的解决办法安装相关依赖包,但是如果加上最后两个红色的项怎么也编译不成功,报错内容是:
configure: error: There is something wrong. Please check config.log for more information.
一直找不到原因,因为我机器上已经装好了curl,以为是不用再装了(其实curl和php的curl扩展是两回事),所以我就把红色的两项去掉了再安装。安装成功后在php中调用curl_init()果然报错了,提示没有这个函数,最后我再单独安装了php_curl的扩展,安装步骤见文章后面。
6.正式安装
make && make install
7.配置环境变量
vi /etc/profile
在末尾追加
PATH=$PATH:/usr/local/php/bin
export PATH
执行命令使得改动立即生效
source /etc/profile
8.配置php-fpm
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 /usr/src/php-7.0.2/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
9.启动php-fpm
/etc/init.d/php-fpm start
php-fpm关闭命令
pkill php-fpm
如果出现错误:ERROR: [pool www] cannot get uid for user 'www-data'
则新建www-data 用户组:
- groupadd www-data
- useradd -g www-data www-data
然后再启动php-fpm
编译时出现错误的解决办法
上面说到编译PHP时没有安装curl扩展,因此我又单独安装curl的扩展,步骤如下:编译时出现错误的解决办法
出现报错 Cannot find OpenSSL's <evp.h>
则执行 yum install openssl openssl-devel
出现报错 Please reinstall the libcurl distribution
则执行 yum -y install curl-devel
出现报错 jpeglib.h not found
则执行 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
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
这是bzip2软件包没有安装
解决办法
yum install bzip2-devel.x86_64 -y
configure: error: xpm.h not found.
yum install libXpm-devel
error: Unable to locate gmp.h
Fix: yum install gmp-devel
现象:Unable to detect ICU prefix or /usr//bin/icu-config failed. Please verify ICU install
prefix and make sure icu-config works
解决办法:yum install -y icu libicu libicu-devel
错误:mcrypt.h not found. Please reinstall libmcrypt.
解决办法:yum install php-mcrypt libmcrypt libmcrypt-devel
错误: configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
解决办法:yum install postgresql-devel
错误 : configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解决: yum install libxslt-devel
1、进入到PHP源码目录下的ext/curl目录(如果没有curl目录,那你就要重装下载一个PHP的源码包了)
cd /usr/local/php/ext/curl/
2、安装:
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-curl=DIR(默认路径时无需指定)
如果有自定义php的安装目录,则要先找到php-config路径,把上面的php-config路径修改成你机器上的实际路径
make&&make install
运行结果提醒我安装了共享扩展:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
3、修改php.ini文件
vi /usr/local/php/etc/php.ini
在其文件结尾加入下面的内容:
extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/"
extension=curl.so
4、安装完成后,重启php-fpm和web服务器。(我用的是nginx服务)
再运行curl就能正常运行了。