PHP

Centos8 编译安装 PHP 8.1.0

2021-12-01  本文已影响0人  ___n

安装工具包

yum -y install libtool automake libzip-devel epel-release libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel uuid libuuid-devel gcc bzip2 bzip2-devel gmp-devel  readline-devel libxslt-devel autoconf bison gcc gcc-c++ sqlite-devel cmake

下载安装 oniguruma

wget -c https://github.com/kkos/oniguruma/archive/refs/tags/v6.9.7.1.tar.gz
tar -zxvf v6.9.7.1.tar.gz
cd oniguruma-6.9.7.1
./autogen.sh && ./configure --prefix=/usr
make && make install

下载安装 php 8.1.0

wget -c  https://www.php.net/distributions/php-8.1.0.tar.gz
tar -zxvf php-8.1.0.tar.gz
cd php-8.1.0

./configure \
--prefix=/opt/php/8.1.0 \
--with-config-file-path=/opt/php/8.1.0/etc \
--with-config-file-scan-dir=/opt/php/8.1.0/etc/conf.d \
--enable-fpm \
--enable-soap \
--with-openssl \
--with-openssl-dir \
--with-zlib \
--with-iconv \
--with-bz2 \
--enable-gd \
--with-jpeg \
--with-freetype \
--with-curl \
--enable-dom \
--with-xml \
--with-zip \
--enable-mbstring \
--enable-pdo \
--with-pdo-mysql \
--with-zlib-dir \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-xsl \
--enable-mysqlnd \
--with-mysqli \
--without-pear \
--disable-short-tags 

make && make install

Installing shared extensions:     /opt/php/8.1.0/lib/php/extensions/no-debug-non-zts-20210902/
Installing PHP CLI binary:        /opt/php/8.1.0/bin/
Installing PHP CLI man page:      /opt/php/8.1.0/php/man/man1/
Installing PHP FPM binary:        /opt/php/8.1.0/sbin/
Installing PHP FPM defconfig:     /opt/php/8.1.0/etc/
Installing PHP FPM man page:      /opt/php/8.1.0/php/man/man8/
Installing PHP FPM status page:   /opt/php/8.1.0/php/php/fpm/
Installing phpdbg binary:         /opt/php/8.1.0/bin/
Installing phpdbg man page:       /opt/php/8.1.0/php/man/man1/
Installing PHP CGI binary:        /opt/php/8.1.0/bin/
Installing PHP CGI man page:      /opt/php/8.1.0/php/man/man1/
Installing build environment:     /opt/php/8.1.0/lib/php/build/
Installing header files:          /opt/php/8.1.0/include/php/
Installing helper programs:       /opt/php/8.1.0/bin/
  program: phpize
  program: php-config
Installing man pages:             /opt/php/8.1.0/php/man/man1/
  page: phpize.1
  page: php-config.1
/home/centos/php-8.1.0/build/shtool install -c ext/phar/phar.phar /opt/php/8.1.0/bin/phar.phar
ln -s -f phar.phar /opt/php/8.1.0/bin/phar
Installing PDO headers:           /opt/php/8.1.0/include/php/ext/pdo/

启动和后续配件可以参考这里
Centos7 编译 PHP7.4.16 - 简书 (jianshu.com)


增加扩展

进入刚才的解压目录

#安装GD库示例
cd php-8.1.0/ext/gd
/opt/php/8.1.0/bin/phpize

Configuring for:
PHP Api Version:         20210902
Zend Module Api No:      20210902
Zend Extension Api No:   420210902

./configure --with-php-config=/opt/php/8.1.0/bin/php-config
make && make install

完成后记得在 php.ini 里加入 extension=gd.so

PHP8 主要不向后兼容的变更

请注意,这意味着 0 == "not-a-number" 现在将被认为是 false 。

Comparison Before After
0 == "0" true true
0 == "0.0" true true
0 == "foo" true false
0 == "" true false
42 == " 42" true true
42 == "42foo" true false

PHP8 主要新特性

命名参数

新增命名参数的功能。

注解(Attributes)

新增注解的功能。

构造器属性提升(Constructor Property Promotion)

新增构造器属性提升功能 在构造函数中声明类的属性)。

联合类型

新增 联合类型

Match 表达式

新增 match 表达式

Nullsafe 运算符

新增Nullsafe 运算符(?->)。

其他新特性

<?php class A {
         public function method(int $many, string $parameters, $here) {}
    }
    class B extends A {
         public function method(...$everything) {}
    } ?>
    <?php class Test {
         public function create(): static {
              return new static();
         }
    } ?>
    <?php
    $fn = fn() => throw new Exception('Exception in arrow function'); $user = $session->user ?? throw new Exception('Must have user');
    <?php function functionWithLongSignature(
        Type1 $parameter1,
        Type2 $parameter2, // <-- 这个逗号也被允许了 ) {
    }
上一篇 下一篇

猜你喜欢

热点阅读