php扩展

说明:

通过phpize可执行命令安装。

phpSrcDir是php源码包目录。

installDir是php服务安装目录。

pecl地址https://pecl.php.net/package

composer

cd installDir/bin

# 直接安装
curl -sS https://getcomposer.org/installer | ./php

# 多个版本php安装多个版本composer
wget https://install.phpcomposer.com/composer.phar
chmod +x composer.phar
installDir/bin/php installDir/bin/composer.phar --help

# 嫌弃命令太长可以将其写入一个脚本然执行脚本
vim composer.sh
#! /bin/bash
installDir/bin/php installDir/bin/composer.phar $*

phpunit

cd installDir/bin
wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar

# 需要部分括扩展
installDir/bin/php installDir/bin/phpunit.phar --help

# 嫌弃命令太长可以将其写入一个脚本然执行脚本
vim phpunit.sh
#! /bin/bash
installDir/bin/php installDir/bin/phpunit.phar $*

phpDocumentor

cd installDir/bin
wget https://phpdoc.org/phpDocumentor.phar
chmod +x phpDocumentor.phar

# 需要部分括扩展
installDir/bin/php installDir/bin/phpDocumentor.phar --help

# 嫌弃命令太长可以将其写入一个脚本然执行脚本
vim phpDocumentor.sh
#! /bin/bash
installDir/bin/php installDir/bin/phpDocumentor.phar $*

openssl

cd phpSrcDir/ext/openssl
mv config0.m4 config.m4
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--with-openssl=opensslInstalllDir \
OPENSSL_CFLAGS='-I/opensslInstalllDir/include' \
OPENSSL_LIBS='-L/opensslInstalllDir/lib64 -lssl -lcrypto'

make
make install

# 修改php.ini文件
[openssl]
extension=openssl.so

curl

cd phpSrcDir/ext/curl
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--with-curl=curlInstallDir

make
make install

# 修改php.ini文件
[curl]
extension=curl.so

opcache

cd phpSrcDir/ext/opcache
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
[opcache]
zend_extension=opcache.so
;启用OPcache
opcache.enable=1
;CLI模式下启用OPcache
opcache.enable_cli=1
;共享内存大小(单位M)
opcache.memory_consumption=128
;存储字符串的内存大小(单位M)
opcache.interned_strings_buffer=8
;允许缓存脚本文件最大数量
opcache.max_accelerated_files=4000
;缓存过期的时间(单位秒) 0每次都检查脚本是否更新
opcache.revalidate_freq=60
;启用快速关闭
opcache.fast_shutdown=1
;启用tracing后JIT可以更精细并选择函数中的代码段进行编译
opcache.jit=tracing
opcache.jit_buffer_size=100M

;opcache.revalidate_freq配置项参数较大的话 改变源代码访问时并不一定实时改变(有缓存)
declare (strict_types=1);
$start = microtime(true);
$total = 0;
for ($i = 0; $i < 1000000; $i++) {
    $total += $i;
}
echo 'Count:' . $i . ',Total' . $total . '<br/>';
$end = microtime(true);
$spend = floor(($end - $start) * 1000);
echo $spend;

# 开启时
# Count:1000000,Total499999500000
# 15(最大)
# 未开启时
# Count:1000000,Total499999500000
# 54(有时更大)

mysqli

cd phpSrcDir/ext/mysqli
installDir/bin/phpize
# --with-mysqli=mysqlInstallDir/bin/mysql_config
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 错误
# error: Please reinstall the mysql distribution
# 修改mysqli_api.c文件
# 将#include "ext/mysqlnd/mysql_float_to_double.h"
# 改为#include "../mysqlnd/mysql_float_to_double.h"

# 修改php.ini文件
[MySQLi]
extension=mysqli.so

pdo_mysql

cd phpSrcDir/ext/pdo_mysql
installDir/bin/phpize
# --with-pdo-mysql=mysqlInstallDir/bin/mysql_config
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
[Pdo_mysql]
extension=pdo_mysql.so

pgsql

# 此扩展依赖postgresql
cd phpSrcDir/ext/pgsql
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
[PostgreSQL]
extension=pgsql.so
pgsql.allow_persistent=On
pgsql.auto_reset_persistent=Off
pgsql.max_persistent=-1
pgsql.max_links=-1
pgsql.ignore_notice=0
pgsql.log_notice=0

pdo_pgsql

# 此扩展依赖postgresql
cd phpSrcDir/ext/pdo_pgsql
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
;pdo_pgsql
extension=pdo_pgsql.so

calendar-日历扩展

# 包含了简化不同日历格式间转换函数
cd phpSrcDir/ext/calendar
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--enable-calendar

make
make install

# 修改php.ini文件
;calendar
extension=calendar.so

exif-处理图像元数据

# 例如使用exif函数通过处理存储在标题信息来读取从数码相机拍摄图片的元数据
# 常见于JPEG和TIFF图像中
cd phpSrcDir/ext/exif
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

# make可能会报错使用c99标准
make CFLAGS=-std=c99
make install

# 修改php.ini文件
[exif]
extension=exif.so
exif.encode_unicode=ISO-8859-15
exif.decode_unicode_motorola=UCS-2BE
exif.decode_unicode_intel=UCS-2LE
exif.encode_jis=
exif.decode_jis_motorola=JIS
exif.decode_jis_intel=JIS

xsl

# 依赖libxslt
# XSL代表可扩展样式表语言 它是用来理解和样式化XML文档
# 它可以作为基于XML的样式表语言 就像CSS是基于HTML的样式表语言一样
# 它是一种标记语言 可以指定浏览器应该如何呈现XML文档
cd phpSrcDir/ext/xsl
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--with-xsl=/opt/local

make
make install

# 修改php.ini文件
;xsl
extension=xsl.so

sysvmsg-消息队列

cd phpSrcDir/ext/sysvmsg
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
;sysvmsg
extension=sysvmsg.so

sysvshm-共享内存

cd phpSrcDir/ext/sysvshm
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
[sysvshm]
extension=sysvshm.so

bcmath-数学扩展

cd phpSrcDir/ext/bcmath
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
[bcmath]
extension=bcmath.so

gettext-国际化与字符编码支持

cd phpSrcDir/ext/gettext
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--with-gettext=gettextInstallDir

make
make install

# 修改php.ini文件
;gettext
extension=gettext.so

mbstring-多字节字符串

cd phpSrcDir/ext/mbstring
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
[mbstring]
extension=mbstring.so

zlib-读写gzip压缩过的文件

cd phpSrcDir/ext/zlib
mv config0.m4 config.m4
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--with-zlib

make
make install

# 修改php.ini文件
;zlib
extension=zlib.so

gzip-压缩文件

# 更改php.ini
zlib.output_compression=On
;gzip压缩级别1~9 建议3~5
zlib.output_compression_level=4
;gzip压缩方式 建议注释
;zlib.output_handler=

#页面头部信息还没有输出 而且php已经加载了zlib扩展 而且浏览器接受GZIP
if(!headers_sent() && extension_loaded('zlib') && strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')){
    ini_set('zlib.output_compression', 'On');
    ini_set('zlib.output_compression_level', '4');
}

bzip2-读写.bz2压缩文件

# 依赖bzip2库
cd phpSrcDir/ext/bz2
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--with-bz2

make
make install

# 修改php.ini文件
;bz2
extension=bz2.so

zip-压缩zip

# https://pecl.php.net/package/zip
cd zip
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
;zip
extension=zip.so

ftp

cd phpSrcDir/ext/ftp
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--with-openssl-dir=opensslInstallDir \
--enable-ftp

make
make install

# 修改php.ini文件
;ftp
extension=ftp.so

sockets

cd phpSrcDir/ext/sockets
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--enable-sockets

make
make install

# 修改php.ini文件
;sockets
extension=sockets.so

soap

# 依赖libxml SOAP协议可以实现不同系统之间的数据交互和通信
cd phpSrcDir/ext/soap
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--enable-soap

make
make install

# 修改php.ini文件
[soap]
extension=soap.so

gd

# 依赖libgd
cd phpSrcDir/ext/dg
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--with-jpeg=jpegInstallDir \
--with-freetype=freetypeInstallDir \
--with-webp=libwebpInstallDir \
PNG_CFLAGS='-I/libpngInstallDir/include' \
PNG_LIBS='-L/libpngInstallDir/lib'

make
make install

# 修改php.ini文件
[gd]
extension=gd.so

mcrypt-加密扩展

# 依赖mhash和libmcrypt
# https://pecl.php.net/package/mcrypt 不维护
cd mcrypt
installDir/bin/phpize
./configure \
--with-php-config=phpInstallDir/bin/php-config \
--with-mcrypt=libmcryptInstallDir

make
make install

# 修改php.ini文件
;mcrypt
extension=mcrypt.so

igbinary-序列化

# https://pecl.php.net/package/igbinary
# 相对于自带serialize igbinary具有性能高节省空间的特点
cd igbinary
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
;igbinary
extension=igbinary.so
;使用igbinary作为会话序列化程序
session.serialize_handler=igbinary
;复字符串压缩 默认On
igbinary.compact_strings=On
;使用igbinary作为APCu序列化器
apc.serializer=igbinary

imagick-创建和修改图像

# 依赖ImageMagick
# https://pecl.php.net/package/imagick
# imagick是一个原生的php扩展 用于使用ImageMagick API创建和修改图像
# imageMagick是一个用于创建 编辑和合成位图图像的软件套件
# 它可以读取 转换和写入多种格式(超过100种)的图像
# 包括DPX EXR GIF JPEG JPEG-2000 PDF PhotoCD PNG Postscript SVG和TIFF
cd imagick
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--with-imagick=ImageMagickSrc

make
make install

# 修改php.ini文件
;imagick
extension=imagick.so

redis

# https://pecl.php.net/package/redis
cd redis
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config \
--enable-redis

make
make install

# 修改php.ini文件
;redis
extension=redis.so

memcache

# https://pecl.php.net/package/memcache
cd memcache
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
;memcache
extension=memcache.so

mongodb

# https://pecl.php.net/package/mongodb
cd mongodb
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
;mongodb
extension=mongodb.so

swoole

# 依赖c-ares
#
cd swoole
installDir/bin/phpize
./configure \
./configure \
--with-php-config=installDir/bin/php-config \
--enable-cares \
--enable-sockets \
--enable-mysqlnd \
--enable-swoole-curl \
--enable-swoole-sqlite \
--with-nghttp2-dir=nghttp2InstallDir \
--with-openssl-dir=opensslInstallDir

make
make install

# 修改php.ini文件
;swoole
extension=swoole.so

xdebug

# 查看适配php的Xdebug版本
# 将php -i输出内容复制到https://xdebug.org/wizard 查看适配Xdebug的版本
cd xdebug
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
;xdebug
zend_extension=xdebug.so
;是否允许Xdebug跟踪函数调用 跟踪信息以文件形式存储
xdebug.mode=debug,trace
;否允许Xdebug远程调试
xdebug.start_with_request=yes
xdebug.idekey=xdebug
xdebug.client_port=9000
xdebug.client_host=127.0.0.1
;收集返回值
xdebug.collect_return=On
xdebug.output_dir=/tmp/xdebug
xdebug.log=/tmp/xdebug/xdebug.log

;指定xdebug.output_dir和xdebug.log参数 应创建对应目录与文件并赋予相应权限
;xdebug扩展与opcache扩展的opcache.jit_buffer_size参数冲突

扩展(不建议开启)

fileinfo

# 获取文件mime类型fileinfo等方法
cd phpSrcDir/ext/fileinfo
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

;fileinfo
extension=fileinfo.so

readline

# readline扩展并非线程安全
cd phpSrcDirext/readline
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
;readline
extension=readline.so

ffi

# readline扩展并非线程安全
cd phpSrcDirext/ffi
installDir/bin/phpize
./configure \
--with-php-config=installDir/bin/php-config

make
make install

# 修改php.ini文件
[ffi]
extension=ffi.so

相关推荐

  1. php扩展

    2024-07-22 11:02:04       18 阅读
  2. php.2安装Imagick扩展

    2024-07-22 11:02:04       51 阅读
  3. PHP8.2-xlswriter 扩展

    2024-07-22 11:02:04       24 阅读
  4. pear + pecl 安装php扩展

    2024-07-22 11:02:04       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-22 11:02:04       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-22 11:02:04       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-22 11:02:04       45 阅读
  4. Python语言-面向对象

    2024-07-22 11:02:04       55 阅读

热门阅读

  1. SpringMVC基础

    2024-07-22 11:02:04       17 阅读
  2. [C/C++入门][ifelse]18、Switch星期课表

    2024-07-22 11:02:04       19 阅读
  3. 如何在 .NET Core 中生成服务器端报表

    2024-07-22 11:02:04       17 阅读