centos7.9 源碼編譯安裝php

準備

  • 查看當前linux版本

    命令
    lsb_release -a
    

  • 創建安裝軟件的目錄,方便統一管理,在根目錄下創建路徑/server用來存放所有軟件。

    命令
    mkdir /server
    
  • 選擇下載php的版本,這裏以7.3.13爲例。下載地址:php版本

    命令:
    cd /server #切換到軟件安裝目錄
    
    wget https://www.php.net/distributions/php-7.3.13.tar.gz #下載到當前目錄
    
    tar -zxvf php-7.3.13.tar.gz #解壓到當前位置
    
    rm -rf nginx-1.18.0.tar.gz  #刪除壓縮包
    


安裝

  • 執行configure,生成配置

    命令:
    
    cd php-7.3.13/  #進入php的目錄
     
    ./configure \
    --prefix=/server/php \
    --with-config-file-path=/server/php/etc \
    --with-mhash \
    --with-openssl \
    --with-mysqli \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --with-gd \
    --with-iconv \
    --with-zlib \
    --enable-zip \
    --enable-inline-optimization \
    --disable-debug \
    --disable-rpath \
    --enable-shared \
    --enable-xml \
    --enable-bcmath \
    --enable-shmop \
    --enable-sysvsem \
    --enable-mbregex \
    --enable-mbstring \
    --enable-ftp \
    --enable-pcntl \
    --enable-calendar \
    --enable-exif \
    --enable-sockets \
    --with-xmlrpc \
    --with-libxml-dir \
    --enable-soap \
    --with-gettext \
    --enable-session \
    --with-curl \
    --with-jpeg-dir \
    --with-png-dir \
    --with-freetype-dir \
    --with-bz2 \
    --enable-opcache \
    --enable-fpm \
    --with-fpm-user=nginx \
    --with-fpm-group=nginx \
    --enable-fast-install
    

    編譯一般都會缺少各種依賴而報錯,解決依賴

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

      解決辦法: yum install -y libxml2-devel

    2. configure: error: Please reinstall the BZip2 distribution

      解決辦法: yum install -y bzip2-devel

    3. configure: error: cURL version 7.15.5 or later is required to compile php with cURL support

      解決辦法: yum install -y curl-devel

    4. configure: error: jpeglib.h not found.

      解決辦法: yum install -y libjpeg-devel

    5. configure: error: png.h not found.

      解決辦法: yum install -y libpng-devel

    6. configure: error: freetype-config not found.

      解決辦法: yum install -y freetype-devel

    7. configure: error: Please reinstall the libzip distribution

      解決辦法:

      wget https://libzip.org/download/libzip-1.2.0.tar.gz #下載libzip
      
      tar -zxvf libzip-1.2.0.tar.gz #解壓到當前目錄
      
      rm -rf libzip-1.2.0.tar.gz  #刪除壓縮包
      
      cd libzip-1.2.0/ #進去libzip目錄
      
      ./configure --bindir=/usr/sbin/ \
          --sbindir=/usr/sbin/ \
          --libexecdir=/usr/libexec \
          --sysconfdir=/etc/ \
          --localstatedir=/var \
          --libdir=/usr/lib64/  \
          --includedir=/usr/include/ \
          --datarootdir=/usr/share \
          --infodir=/usr/share/info \
          --localedir=/usr/share/locale \
          --mandir=/usr/share/man/ \
          --docdir=/usr/share/doc/libzip-1.2.0 #生成配置
      
      make && make install #編譯安裝
      
    結果:

    出現如上顯示,則代表配置成功

  • 編譯源碼

    命令:

    make #在當前路徑下執行make命令進行編譯

    結果:

    出現如上顯示,則代表編譯成功

  • 編譯安裝

    命令:

    make install #在當前路徑下執行編譯安裝

    結果:

    出現如上顯示,則代表編譯成功

  • 配置PHP

    1. 複製php.ini:

      cp -a php.ini-production /server/php/etc/php.ini  #複製php.ini到etc目錄下
      
    2. 複製php-fpm.conf

      cd /server/php/etc/ #跳轉到etc目錄下
      
      cp -a php-fpm.conf.default ./php-fpm.conf #複製php-fpm配置文件 
      
    3. 複製www.conf

      cd /server/php/etc/php-fpm.d #跳轉到php-fpm.d目錄下
      
      cp -a www.conf.default ./www.conf #複製www.conf
      
    4. 配置php爲環境變量

      export PATH=$PATH:/server/php/bin
      
  • 測試

    命令:

    php-v

    結果:

    安裝完成

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章