centos7系統源碼編譯安裝PHP7.3.5版本詳細步驟

新增系統用戶組和用戶:php

[root@localhost ~]# groupadd webg
[root@localhost ~]# useradd -g webg webupython

 下載 PHP7.3.5mysql

[root@localhost ~]# mkdir devdir
[root@localhost ~]# cd devdir/
[root@localhost devdir]# wget https://www.php.net/distributions/php-7.3.5.tar.gz
  -bash: wget: 未找到命令
[root@localhost devdir]# rpm -qa|grep wget
[root@localhost devdir]# yum -y install wget
[root@localhost devdir]# rpm -qa|grep wget
wget-1.14-18.el7.x86_64

下載PHP7 解壓 編譯c++

wget -c https://downloads.php.net/~cmb/php-7.3.4.tar.gzgit

編譯參數解釋github

--with-fpm-user=webu --with-fpm-group=webg  添加PHP運行用戶和用戶組web

./configure --prefix=/usr/local/php --with-fpm-user=webu --with-fpm-group=webg --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-fpm

配置信息出錯:sql

configure: error: in `/root/devdir/php-7.3.4':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
[root@localhost php-7.3.4]# vim config.log

下載gcc軟件編譯器 yum install -y gccbootstrap

configure: error: libxml2 not found. Please check your libxml2 installation.vim

checking for pkg-config... /usr/bin/pkg-config
configure: error: libxml2 not found. Please check your libxml2 installation.
[root@localhost php-7.3.4]# rpm -qa|grep libxml2
libxml2-2.9.1-6.el7_2.3.x86_64
[root@localhost php-7.3.4]# 
[root@localhost php-7.3.4]# yum install -y libxml2-devel
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>
[root@localhost php-7.3.4]# rpm -qa|grep openssl
openssl-1.0.2k-16.el7.x86_64
openssl-libs-1.0.2k-16.el7.x86_64
[root@localhost php-7.3.4]# yum install -y openssl-devel
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.nwsuaf.edu.cn
 * extras: mirror.lzu.edu.cn
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
[root@localhost php-7.3.4]# yum install -y bzip2-devel
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.163.com
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
[root@localhost php-7.3.4]# rpm -qa|grep curl
curl-7.29.0-51.el7.x86_64
libcurl-7.29.0-51.el7.x86_64
python-pycurl-7.19.0-19.el7.x86_64
[root@localhost php-7.3.4]# yum install -y curl-devel
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.nwsuaf.edu.cn
 * extras: mirrors.cn99.com
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-webp-dir=<DIR>
configure: error: jpeglib.h not found.
[root@localhost php-7.3.4]# yum install -y libjpeg-devel
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.nwsuaf.edu.cn
configure: error: png.h not found.
[root@localhost php-7.3.4]# yum install -y libpng-devel
已加載插件:fastestmirror
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
[root@localhost php-7.3.4]# yum install -y freetype-devel
已加載插件:fastestmirror
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
[root@localhost php-7.3.4]# yum install -y libxslt-devel
已加載插件:fastestmirror
configure: error: Please reinstall the libzip distribution
[root@localhost php-7.3.4]# rpm -qa|grep libzip
[root@localhost php-7.3.4]# yum install -y libzip
已加載插件:fastestmirror
[root@localhost php-7.3.4]# rpm -qa|grep libzip
libzip-0.10.1-8.el7.x86_64
[root@localhost php-7.3.4]# yum install -y libzip-devel
已加載插件:fastestmirror
checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11
[root@localhost php-7.3.4]#

下載libzip-1.5.2.tar.gz

https://libzip.org/download/libzip-1.5.2.tar.gz

[root@localhost devdir]# pwd
/root/devdir
[root@localhost devdir]# wget -c https://libzip.org/download/libzip-1.5.2.tar.gz--2019-05-09 15:02:31--  https://libzip.org/download/libzip-1.5.2.tar.gz
正在解析主機 libzip.org (libzip.org)... 5.2.73.210, 2a04:52c0:101:2e6::de6c
正在鏈接 libzip.org (libzip.org)|5.2.73.210|:443... 已鏈接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:1203524 (1.1M) [application/x-gzip]
正在保存至: 「libzip-1.5.2.tar.gz」

100%[======================================>] 1,203,524   44.8KB/s 用時 36s    

2019-05-09 15:03:14 (32.8 KB/s) - 已保存 「libzip-1.5.2.tar.gz」 [1203524/1203524])

[root@localhost devdir]# tar zxvf libzip-1.5.2.tar.gz 
libzip-1.5.2/
[root@localhost libzip-1.5.2]# ls
API-CHANGES.md     CMakeLists.txt      INSTALL.md    man        src
appveyor.yml       cmake-zipconf.h.in  lib           NEWS.md    THANKS
AUTHORS            examples            libzip.pc.in  README.md  TODO.md
cmake-config.h.in  FindNettle.cmake    LICENSE       regress
[root@localhost libzip-1.5.2]# mkdir build && cd build
[root@localhost build]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/libzip ..
-bash: cmake: 未找到命令
[root@localhost build]# yum install -y cmake     【版本過低因此安裝cmake最新版】
[root@localhost build]# rm -f CMakeCache.txt 
[root@localhost build]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/libzip ..
CMake Error at CMakeLists.txt:4 (CMAKE_MINIMUM_REQUIRED):
  CMake 3.0.2 or higher is required.  You are running version 2.8.12.2


-- Configuring incomplete, errors occurred!
[root@localhost build]# yum remove -y cmake
已加載插件:fastestmirror
[root@localhost devdir]# wget -c https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gz

[root@localhost devdir]# tar -zxvf cmake-3.14.3.tar.gz
[root@localhost devdir]# cd cmake-3.14.3
[root@localhost cmake-3.14.3]# ./configure 
---------------------------------------------
CMake 3.14.3, Copyright 2000-2019 Kitware, Inc. and Contributors
C compiler on this system is: cc       
---------------------------------------------
Error when bootstrapping CMake:
Cannot find a C++ compiler that supports both C++11 and the specified C++ flags.
Please specify one using environment variable CXX.
[root@localhost cmake-3.14.3]# yum install -y gcc-c++    【安裝gcc-c++編譯環境】
[root@localhost cmake-3.14.3]# ./bootstrap 
[root@localhost cmake-3.14.3]# gmake &&gmake install
[root@localhost cmake-3.14.3]# which cmake
/usr/local/bin/cmake
[root@localhost cmake-3.14.3]# cmake --version
-bash: /usr/bin/cmake: 沒有那個文件或目錄
[root@localhost cmake-3.14.3]# cmake
-bash: /usr/bin/cmake: 沒有那個文件或目錄
[root@localhost cmake-3.14.3]# vim /etc/profile
文件末尾 PATH="$PATH=/usr/local/bin"  export PATH
[root@localhost cmake-3.14.3]# source /etc/profile
[root@localhost cmake-3.14.3]# cmake --version
cmake version 3.14.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@localhost cmake-3.14.3]#

解決libzip 和cmake版本問題

從新配置PHP7編譯環境參數

checking for libzip... not found
configure: error: Please reinstall the libzip distribution
[root@localhost php-7.3.4]# yum -y install libzip-devel
checking for pkg-config... (cached) /usr/bin/pkg-config
checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11
[root@localhost php-7.3.4]# which libzip
/usr/bin/which: no libzip in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/bin:/root/bin)
[root@localhost php-7.3.4]# ll /usr/local/lib
lib/     lib64/   libexec/ libzip/  
[root@localhost php-7.3.4]# ll /usr/local/libzip/
bin/     include/ lib64/   share/   
[root@localhost php-7.3.4]# ll /usr/local/libzip/bin/zip
zipcmp    zipmerge  ziptool   
[root@localhost php-7.3.4]# ll /usr/local/libzip/bin
總用量 80
-rwxr-xr-x. 1 root root 24392 5月   9 16:04 zipcmp
-rwxr-xr-x. 1 root root 18880 5月   9 16:04 zipmerge
-rwxr-xr-x. 1 root root 34928 5月   9 16:04 ziptool
[root@localhost php-7.3.4]# vim /etc/profile

unset i
PATH="$PATH:/usr/local/bin:/usr/local/libzip/bin"
export PATH

[root@localhost php-7.3.4]# source /etc/profile
[root@localhost php-7.3.4]#

libzip-1.5.2 沒法安裝,已經取消了。

/root/devdir/libzip-1.5.2/build
[root@localhost build]# cd ../../
[root@localhost devdir]# wget -c https://nih.at/libzip/libzip-1.2.0.tar.gz
[root@localhost devdir]# tar -zxvf libzip-1.2.0.tar.gz 
[root@localhost devdir]# cd libzip-1.2.0
[root@localhost libzip-1.2.0]# ls
aclocal.m4          config.sub    libzip-uninstalled.pc.in  README.md
API-CHANGES         configure     LICENSE                   regress
AUTHORS             configure.ac  ltmain.sh                 src
cmake-config.h.in   depcomp       m4                        test-driver
CMakeLists.txt      examples      Makefile.am               THANKS
cmake-zipconf.h.in  INSTALL       Makefile.in               TODO.md
compile             install-sh    man                       xcode
config.guess        lib           missing
config.h.in         libzip.pc.in  NEWS.md
[root@localhost libzip-1.2.0]# ./configure 
[root@localhost libzip-1.2.0]# make -j4 &&make install

【最終解決方案】
cp ../libzip-1.5.2/build/lib/libzip.so /lib64/

提示off_t類型沒有定義 undefind,解決方法:

[root@localhost ~]# cd devdir/php-7.3.4
[root@localhost php-7.3.4]# vim /etc/ld.so.conf
ld.so.conf    ld.so.conf.d/ 
[root@localhost php-7.3.4]# vim /etc/ld.so.conf
[root@localhost php-7.3.4]# vim /usr/lib64/
Display all 588 possibilities? (y or n)
[root@localhost php-7.3.4]# vim /usr/lib64/l
Display all 538 possibilities? (y or n)
[root@localhost php-7.3.4]# vim /usr/lib64/lib
Display all 535 possibilities? (y or n)
[root@localhost php-7.3.4]# vim /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64

[root@localhost php-7.3.4]# ldconfig -v
ldconfig: 屢次給出路徑「/lib」

 

編譯安裝

In file included from /root/devdir/php-7.3.4/ext/zip/php_zip.h:31:0,
                 from /root/devdir/php-7.3.4/ext/zip/php_zip.c:36:
/usr/local/include/zip.h:59:21: 致命錯誤:zipconf.h:沒有那個文件或目錄
 #include <zipconf.h>
                     ^
編譯中斷。
make: *** [ext/zip/php_zip.lo] 錯誤 1
解決方案:
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
[root@localhost php-7.3.4]# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/

測試PHP是否安裝成功

Installing PEAR environment:      /usr/local/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.5
[PEAR] Console_Getopt - installed: 1.4.2
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.3
[PEAR] PEAR           - installed: 1.10.9
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/root/devdir/php-7.3.4/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/
[root@localhost php-7.3.4]# php -v
-bash: php: 未找到命令
[root@localhost php-7.3.4]# ll /usr/local/php/
bin/     etc/     include/ lib/     php/     sbin/    var/     
[root@localhost php-7.3.4]# ll /usr/local/php/bin/p
pear        pecl        phar.phar   php-cgi     phpdbg      
peardev     phar        php         php-config  phpize      
[root@localhost php-7.3.4]# vim /etc/profile
[root@localhost php-7.3.4]# source /etc/profile
[root@localhost php-7.3.4]# php -v
PHP 7.3.4 (cli) (built: May  9 2019 17:39:42) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies
[root@localhost php-7.3.4]#
相關文章
相關標籤/搜索