(MAC) PHP extension installation

Time:2021-1-7

preface

Everyone’s installation environment is different, the specific installation depends on the individual!

1. Check before installingphp.iniAnd then write the extension to the configuration file.

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. Modification.bash_profile, add the following lines, so that you can easily use PHP, phpize, PHP config commands!

PATH=/usr/local/bin:$PATH

3. Find extended resource packages

(1)pecl.php.net/

(2)github

PHP installation extension method

see php.ini The default extension corresponds to the configuration item launched at compile install time. If you need to start an extension, you can try the following scheme:

(1) When compiling and installing PHP, start the configuration item, provided that the configuration item supports it!

(2) Download the resource package of the corresponding extension, then compile and install it yourself

(3) Find the resource directory of the original PHP installation, and then CD to ext and the corresponding extension to compile and install. give an example:

#Enter the resource directory of php-7.1 and extend curl
cd /usr/local/opt/php-src/ext/curl
phpize
./configure --with-php-config=php-config
sudo make && sudo make install

More waiting records

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

Redis

git clone git://github.com/phpredis/phpredis.git 
#Git checkout XXX # you can view the branches of the resource by yourself
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

git clone https://github.com/php-memcached-dev/php-memcached.git
cd ~/opt/php-memcached
phpize
./configure --with-php-config=php-config --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

Installation dependency: 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

PDO

event

Dependency extension: 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

mysqli

cd /usr/local/opt/php-src/ext/mysqli
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

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

Write a shell script

Here is a paste in one by one, you can also define an associative array. However, we tried to get the expected value by using the string as the subscript of the shell’s associative array. Let’s go around first. We’ll do it when we have time.

#!/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

# ...

This work adoptsCC agreementReprint must indicate the author and the link of this article