php7.3.1在Contos7下编译安装

文章目录

    • 1. 安装依赖库
    • 2. 编译安装php
    • 3. 系统配置
    • 4. 配置全局变量
    • 5. php.ini

1. 安装依赖库


  • 安装支持库
    yum install screen gcc git vim wget openssl curl
    yum install gmp-devel libc-client-devel bzip2-devel enchant-devel libwebp-devel libXpm-devel openldap openldap-devel php-pspell aspell-devel readline-devel libtidy-devel libxslt-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel autoconf
    
  • 解决yum包不存在问题
    wget http://www6.atomicorp.com/channels/atomic/centos/7/x86_64/RPMS/atomic-release-1.0-21.el7.art.noarch.rpm
    rpm -Uvh atomic-release*rpm
    
  • libc-client 和 libldap 找不到
    ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so
    cp -frp /usr/lib64/libldap* /usr/lib/
    

2. 编译安装php


  • 下载php7.3.1源码

    wget http://php.net/distributions/php-7.3.1.tar.gz && tar -zxvf php-7.3.1.tar.gz && cd  php-7.3.1
    
  • 配置要安装的库

    ./buildconf --force
    
    ./configure \
    --prefix=/usr/local/php \
    --with-config-file-path=/usr/local/php/etc \
    --with-config-file-scan-dir=/usr/local/php/conf.d \
    --with-sqlite3 \
    --with-pdo-sqlite \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --enable-posix \
    --enable-pcntl \
    --enable-shmop \
    --enable-sysvshm \
    --enable-sysvsem \
    --enable-sysvmsg \
    --enable-phar \
    --enable-zip \
    --with-zlib \
    --with-zlib-dir \
    --with-bz2 \
    --with-gd \
    --enable-gd-jis-conv \
    --with-webp-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-xpm-dir \
    --with-freetype-dir \
    --enable-exif \
    --enable-json \
    --enable-libxml \
    --with-libxml-dir \
    --enable-xml \
    --enable-xmlreader \
    --enable-xmlwriter \
    --enable-simplexml \
    --with-pear \
    --with-xsl \
    --enable-dom \
    --enable-soap \
    --enable-wddx \
    --with-xmlrpc \
    --enable-ctype \
    --enable-filter \
    --with-pcre-regex \
    --with-pcre-jit \
    --with-enchant \
    --with-pspell \
    --enable-fileinfo \
    --enable-mbstring \
    --with-iconv \
    --enable-hash \
    --with-openssl \
    --enable-bcmath \
    --with-gmp \
    --enable-session \
    --enable-sockets \
    --enable-ftp \
    --with-curl \
    --with-ldap \
    --with-ldap-sasl \
    --with-imap \
    --with-kerberos \
    --with-imap-ssl \
    --enable-calendar \
    --with-gettext \
    --with-tidy \
    --with-readline \
    --enable-tokenizer \
    --enable-opcache \
    --enable-cli \
    --enable-cgi \
    --enable-fpm \
    --enable-phpdbg
    
  • 编译安装

    make -j `grep processor /proc/cpuinfo | wc -l` && make install
    
  • 编译报错

    1. checking for libzip… configure: error: system libzip must be upgraded to version >= 0.11

      yum remove libzip libzip-devel
      wget https://nih.at/libzip/libzip-1.2.0.tar.gz
      tar -zxvf libzip-1.2.0.tar.gz
      cd libzip-1.2.0
      ./configure
      make
      make install
      
    2. collect2: error: ld returned 1 exit status

      vim Makefile 找到 开头是 ‘EXTRA_LIBS’ 这一行 在结尾加上 ‘-llber’
      如果还报错再加上’-liconv’

    3. fatal error: zipconf.h: No such file or directory

      //查找 zipconf.h
      find / -name zipconf.h
      // 复制 zipconf.h 到 /usr/local/include/
      cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/

3. 系统配置


cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

4. 配置全局变量

vim /etc/profile
export PATH=$PATH:/usr/local/php/bin
source /etc/profile

5. php.ini


  • 设置时区
     date.timezone = Asia/Shanghai
    
  • 开启 opcache 字节码缓存
        sysctl vm.nr_hugepages=512
        # 将下面内容添加至php.ini 开启OPcache
        [Zend OPcache]
        zend_extension=opcache.so
        opcache.enable=1
        opcache.enable_cli=1
        opcache.huge_code_pages=1
        opcache.file_cache=/tmp
    

你可能感兴趣的:(php7.3.1在Contos7下编译安装)