(MAC) PHP扩展安装

前言

每个人的安装环境不同,具体安装依个人而异!

1、安装之前先查看php.ini的位置,然后将扩展写入配置文件。

php -i | grep php.ini
# php --ini
# Loaded Configuration File => /usr/local/lib/php.ini
sudo cp /etc/php.ini.default /usr/local/lib/php.ini

2、修改.bash_profile,增加如下几行,这样就可以方便使用php、phpize、php-config命令了!

PATH=/usr/local/bin:$PATH

3、查找扩展的资源包
(1)pecl.php.net/
(2)github

PHP安装扩展方法

查看php.ini默认的扩展和编译安装时启动的配置项是对应的。如果需要启动某个扩展可以尝试以下方案:
(1)编译安装PHP的时候启动配置项,前提是配置项支持!
(2)下载对应扩展的资源包然后自己编译安装
(3)找到原安装PHP的资源目录,然后cd到ext及对应的扩展下编译安装。举例:

# 进入PHP-7.1版本的资源目录及扩展curl
cd /usr/local/opt/php-src/ext/curl
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

更多等待记录…

igbinary

wget http://pecl.php.net/get/igbinary-3.1.5.tgz
tar zxvf igbinary-3.1.5.tgz
cd ~/opt/igbinary-3.1.5
sudo phpize --clean && sudo make clean
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

curl

wget https://curl.haxx.se/download/curl-7.72.0.tar.gz
tar -zxvf curl-7.72.0.tar.gz && cd curl-7.72.0
./configure && sudo make && sudo make install

cd /usr/local/opt/php-src/ext/curl
phpize --with-curl=/usr/local/opt/curl
./configure --with-php-config=php-config
sudo make && sudo make install

sockets

cd /usr/local/opt/php-src/ext/sockets
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

tidy

exif

fileinfo

ftp

zip

Redis

git clone git://github.com/phpredis/phpredis.git 
#git checkout xxx # 可以自己查看该资源的分支
cd ~/opt/phpredis/
phpize
./configure --with-php-config=php-config --enable-redis-igbinary 
sudo make && sudo make install

Memcache

git clone git://github.com/websupport-sk/pecl-memcache
cd ~/opt/pecl-memcache
phpize
./configure --with-php-config=php-config --with-zlib-dir=/usr/local/opt/zlib
sudo make && sudo make install

Memcached

# wget http://download.tangent.org/libmemcached-1.0.18.tar.gz
# sudo tar -zxvf libmemcached-1.0.18.tar.gz
# cd libmemcached-1.0.18 && sudo ./configure && sudo make && sudo make install

git clone https://github.com/php-memcached-dev/php-memcached.git
# git clone git://github.com/php-memcached-dev/php-memcached.git
cd ~/opt/php-memcached
phpize
sudo ./configure --with-php-config=/usr/local/bin/php-config --enable-memcached  --with-libmemcached-dir=/usr/local  --disable-memcached-sasl --enable-memcached-igbinary
sudo make && sudo make install

configure: error: Please reinstall the pkg-config distribution
wget pkgconfig.freedesktop.org/releases/...

swoole

# git clone git://github.com/swoole/swoole-src.git
wget https://github.com/swoole/swoole-src/archive/v4.5.3.tar.gz
tar -zxvf v4.5.3.tar.gz && cd swoole-src-4.5.3
# sudo make clean && phpize --clean
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

yar

安装依赖:Curl、Json、Msgpack (Optional)

git clone https://github.com/laruence/yar.git
cd ~/opt/yar
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

mbstring

cd /usr/local/opt/php-src/ext/mbstring
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

PDO

先配置pdo.so,在配置pdo_mysql.so

cd /usr/local/opt/php-src/ext/pdo
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

event

依赖扩展:socket

wget https://pecl.php.net/get/event-2.5.7.tgz
tar -zxvf event-2.5.7.tgz
cd ~/opt/event-2.5.7
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

mysqlnd

cd /usr/local/opt/php-src/ext/mysqlnd
sudo mv config9.m4 config.m4
phpize
export PHP_OPENSSL_DIR=yes
./configure --with-php-config=php-config
sudo make && sudo make install

mysqli

cd /usr/local/opt/php-src/ext/mysqli
phpize
./configure --with-php-config=php-config --with-mysqli=/usr/bin/mysql_config
sudo make && sudo make install

pdo_mysql

cd /usr/local/opt/php-src/ext/pdo_mysql
phpize clean && make clean
phpize
./configure --with-php-config=php-config --with-pdo-mysql=/usr/local/mysql
sudo make && sudo make install

zlib

cd /usr/local/opt/php-src/ext/zlib
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

gd

cd /usr/local/opt/php-src/ext/gd
phpize
./configure --with-php-config=php-config --with-zlib-dir=/usr/local/opt/zlib --with-jpeg-dir=/usr/local/opt/jpeg --with-webp-dir=/usr/local/opt/webp
sudo make && sudo make install

# 开发机搭建
# ./configure --with-freetype-dir=/usr/include/freetype2  --with-jpeg-dir=/usr/include

openssl

cd /usr/local/opt/php-src/ext/openssl
mv config0.m4 config.m4
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

crypto

wget https://pecl.php.net/get/crypto-0.3.1.tgz && tar -zxvf crypto-0.3.1.tgz
cd crypto-0.3.1
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

pcntl

cd /usr/local/opt/php-src/ext/pcntl
sudo phpize --clean && sudo make clean
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

php-fpm

cd /usr/local/opt/php-src/sapi/fpm/
phpize
./configure --with-php-config=php-config

写个shell脚本吧

这里是一个一个的粘贴进来,也可以定义一个关联数组。但是尝试了下shell的关联数组以字符串为下标获取不到预期的值。先绕过去再说吧,有空再弄。

#!/bin/sh

#igbinary
cd ~/opt/igbinary-3.1.5
sudo phpize --clean && sudo make clean
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

# curl
cd /usr/local/opt/php-src/ext/curl
sudo phpize --clean && sudo make clean
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

# ...
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!