运行环境与准备工作
运行环境概述
- 操作系统版本为 CentOS 7.2。
- Web 服务采用 Nginx。
下载解压与编译前检查
第一步:获取 PHP 7.0.2 安装包并进行解压、编译及安装操作。
$ cd /usr/src/
$ wget http://cn2.php.net/distributions/php-7.0.2.tar.gz
$ tar -xzxvf php-7.0.2.tar.gz
$ cd php-7.0.2
1.1 编译前的依赖检查
首先确认系统中是否已安装 gcc 编译器,若未安装,请执行命令 yum install gcc 进行安装。
接着检查 libxml2 库是否存在,如果缺失,需执行 yum install libxml2 命令补全。
同时需要确认 libxml2-devel 开发包是否就绪,若无则执行 yum install libxml2-devel 安装。
注意:由于本方案选用 Nginx 作为 Web 服务器,因此编译参数中移除了 --with-apxs2=/usr/bin/apxs 选项。若计划搭配 Apache 使用,请在安装 PHP 之前先完成 Apache 的安装。*
Configure 参数配置详解
第二步:配置编译参数
复制代码 代码如下: './configure' '--prefix=/usr/local/php' '--with-pdo-pgsql' '--with-zlib-dir' '--with-freetype-dir' '--enable-mbstring' '--with-libxml-dir=/usr' '--enable-soap' '--enable-calendar' '--with-curl' '--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' '--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/' '--enable-ftp' '--with-gettext' '--with-xmlrpc' '--with-xsl' '--enable-opcache' '--enable-fpm' '--with-iconv' '--with-xpm-dir=/usr'
常见编译错误与解决
第三步:处理编译过程中可能出现的错误集合
报错 Cannot find OpenSSL's
执行 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
错误: Unable to locate gmp.h
执行 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
执行编译与安装
第四步:执行编译操作
make clean && make && make install
PHP 配置文件与环境变量设置
第五步:PHP 基础配置
5.1 安装完成后,需将源码包内的配置文件复制到 PHP 安装目录。源码包提供 php.ini-development 和 php.ini-production 两个文件,分别对应开发与生产环境,此处建议复制开发环境配置文件。
cp php.ini-development /usr/local/php/lib/php.ini
5.2 此外还需配置环境变量,通过修改 /etc/profile 文件使其永久生效且对所有系统用户有效,在文件末尾追加以下两行代码。
PATH=$PATH:/usr/local/php/bin
export PATH
5.3 随后执行生效命令使配置立即起作用。
source /etc/profile
5.4 最后查看 PHP 版本信息以验证安装结果。
php -v
PHP-FPM 用户配置与服务启动
第六步:配置 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
6.1 启动 php-fpm 服务。
/etc/init.d/php-fpm start
6.2 若启动时遇到报错:ERROR: [pool www] cannot get uid for user 'www-data'。
则需要新建 www-data 用户组及相关用户。
groupadd www-data
useradd -g www-data www-data
6.3 重启 php-fpm 服务以应用更改。
/etc/init.d/php-fpm restart
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持本站。