(MAC) PHP擴充套件安裝

so_easy發表於2020-09-09

前言

每個人的安裝環境不同,具體安裝依個人而異!

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/local/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

readline || editline

如果要使用 readline 函式,你必須安裝 libreadline,你也能使用非 GPL 的 libedit 庫來替代 readline 庫。
要使用這些函式,你必須在編譯 PHP 的 CGI 或者 CLI 版本時啟用 readline 支援. 你需要在編譯配置 PHP 時使用 –with-readline[=DIR] 選項. 如果你想使用 libedit 來代替 readline , 配置 PHP 時使用 –with-libedit[=DIR] 選項

cd /usr/local/opt/php-src/ext/readline
./configure && sudo make && sudo make install
sudo vim /usr/local/php7.3/lib/php.ini 
# 增加readline.so

1、先下載包:thrysoee.dk/editline/
2、然後解壓後進入包,執行以下命令

./configure
make
make install

3、重新編譯PHP

寫個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 協議》,轉載必須註明作者和本文連結

相關文章