4.27 php编译安装
官网:www.php.net
下载php
# cd /usr/local/src# wget http://cn2.php.net/distributions/php-7.3.0.tar.bz2
解压文件,如果没有安装bzip2,则不能解压tar.bz2包,需要先安装bzip2包
# yum install -y bzip2 #安装bzip2包# tar jxvf php-7.3.0.tar.bz2 #解压
编辑安装一个软件包的步骤大致分为三步
1)第一步:./configure 编译参数 2)第二部:make 编译 3)第三部:install 安装
编译参数:
# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-openssl --with-curl --enable-sockets
编译报错1如下:
checking for cc... nochecking for gcc... noconfigure: error: in `
原因是没有安装gcc编译工具,先安装gcc包
# yum install -y gcc
安装完成后重新编译参数,报错2如下
configure: error: libxml2 not found. Please check your libxml2 installation.
原因是缺少开发包libxml2,需要装libxml2开发包
# yum list | grep libxml2 #查找到包名为libxml2-devel.x86_64# yum install -y libxml2-devel
安装完成后继续重新再次执行编译参数,出现第3个报错,内容如下:
configure: error: Cannot find OpenSSL's# yum list | grep -i OpenSSL #同样的方式查找安装包,i选项忽略大小写# yum install -y openssl-devel
继续编译参数报错4如下:
checking for cURL 7.15.5 or greater... configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
安装包: # yum list | grep -i cURL # yum install -y libcurl-devel 继续编译,报错5
configure: error: jpeglib.h not found.
安装libjpeg包:
# yum list | grep -i jpeg# yum install -y libjpeg-turbo-devel
继续编译,报错6
configure: error: png.h not found.
安装软件包
# yum list | grep -i png# yum install -y libpng-devel
继续编译,报错7:
configure: error: freetype-config not found.
安装包:
# yum list | grep freetype# yum install -y freetype-devel
继续编译,报错8
configure: error: wrong mysql library version or lib not found. Check config.log for more information.
先下载mysql 5.6,64位的二进制包到/usr/local/src下
# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz# tar zxvf http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz# mv mysql-5.6.42-linux-glibc2.12-x86_64 /usr/local/mysql5.6 #移动解压文件
修改编译参数,将mysql路径改为mysql5.6后,继续重新编译:
# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql5.6 --with-mysqli=/usr/local/mysql5.6/bin/mysql_config --with-pdo-mysql=/usr/local/mysql5.6 --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-openssl --with-curl --enable-sockets
将源码包变成二进制包
# make# echo $? #查看是否执行成功# make install# echo $? #查看是否执行成功
拷贝配置文件
# cd /usr/local/php-fpm/etc/# cp php-fpm.conf.default php-fpm.conf #复制拷贝配置文件改名一下# cd /usr/local/src/php-7.3.0# diff php.ini-development php.ini-production #查看并对比两个文件的差异,;号表示注释
php.ini-development是开发测试用的,php.ini-production是生产用的,我们测试拷贝php.ini-development即可
# cp php.ini-development /usr/local/php-fpm/etc/php.ini
拷贝完配置文件后,配置启动脚本,将启动脚本拷贝到init.d目录下
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
将php-fpm添加到服务列表中
# chkconfig --add php-fpm #添加到服务列表# chmod 755 /etc/init.d/php-fpm #设置执行权限# chkconfig --list #查看服务列表# chkconfig php-fpm on #设置开启启动# service php-fpm start #开启服务
启动服务时报错如下
Starting php-fpm [25-Jan-2019 20:40:27] WARNING: Nothing matches the include pattern '/usr/local/php-fpm/etc/php-fpm.d/*.conf' from /usr/local/php-fpm/etc/php-fpm.conf at line 143.[25-Jan-2019 20:40:27] ERROR: No pool defined. at least one pool section must be specified in config file[25-Jan-2019 20:40:27] ERROR: failed to post process the configuration[25-Jan-2019 20:40:27] ERROR: FPM initialization failedfailed
查看报错所在目录
# ll /usr/local/php-fpm/etc/php-fpm.d/ #查看所在目录发现没有.conf配置文件# cp www.conf.default www.conf #拷贝配置文件service php-fpm start #再次启动服务
再次启动报错如下,原因是因为没有增加相应的用户:
Starting php-fpm [25-Jan-2019 20:48:11] ERROR: [pool www] cannot get uid for user 'php-fpm'[25-Jan-2019 20:48:11] ERROR: FPM initialization failed
增加用户并启动
# useradd php-fpm #添加用户# service php-fpm start #启动服务Starting php-fpm done
至此php编译安装完成。