ubuntu编译安装php

  • 选择版本 php官网下载链接
  • 官网编译 安装文档

    当前系统

  • Ubuntu 16.04.7 LTS (使用cat /etc/issue查看)

    需求

  • 编译安装php7.2.x

    执行configure报错总结

  • 报错一

      configure: error: The pkg-config script could not be found or is too old.  Make sure it
      is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config.
  • 解决办法

      sudo apt-get install  pkg-config -y
  • 报错二

      No package 'libxml-2.0' found
  • 解决办法

      sudo apt-get install  libxml2 libxml2-dev -y
  • 报错三

      No package 'sqlite3' found
  • 解决办法

      sudo apt-get install libsqlite3-dev -y
  • 报错四

      No package 'zlib' found
  • 解决办法

      sudo apt-get install zlib1g-dev -y

    安装扩展报错

  • 报错五

    Cannot find autoconf. Please check your autoconf installation and the
    $PHP_AUTOCONF environment variable. Then, rerun this script.
  • 解决办法

    sudo apt-get install autoconf -y

    php -m 显示不出来某些扩展

    #查看php配置文件所在路径
    vagrant@ubuntu-xenial:/data/www/software/php-7.4.27$ php --ini
    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         (none)
    Scan for additional .ini files in: (none)
    Additional .ini files parsed:      (none)
    #查找当前php.ini位置
    vagrant@ubuntu-xenial:/data/www/software/php-7.4.27$ sudo find / -name php.ini
    /usr/local/php/php.ini
    #复制一份到默认读取路径
    vagrant@ubuntu-xenial:/data/www/software/php-7.4.27$ sudo cp /usr/local/php/php.ini /usr/local/lib/
    vagrant@ubuntu-xenial:/data/www/software/php-7.4.27$ php --ini
    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         /usr/local/lib/php.ini
    Scan for additional .ini files in: (none)
    Additional .ini files parsed:      (none)

    因内存不足导致的编译失败

    #查看当前内存
    free -m 
    #创建swap挂载点
    sudo  mkdir /opt/images/swap
    sudo rm -rf /opt/images/swap
    #设置挂载swap
    sudo dd if=/dev/zero of=/opt/images/swap bs=1024 count=2048000
    sudo mkswap /opt/images/swap
    #开启swap
    sudo swapon /opt/imgaes/wsap
    #关闭swap并删除挂载文件
    sudo swapoff swap
    sudo rm -f /opt/images/swap
Last modification:January 10, 2022
如果觉得我的文章对你有用,请随意赞赏