Ubuntu lamp PHP 7.2 安装mysql和mcrypt 扩展

PHP 7.2 中安装 mysql 扩展

环境: Ubuntu 18.04 + LAMP(PHP 7.2)

  1. 下载 mysql 仓库到本地 (http://git.php.net/?p=pecl/database/mysql.git;a=summary)
# 下载 php.net mysql仓库到本地
cd /tmp
git clone https://git.php.net/repository/pecl/database/mysql.git
# 进入mysql扩展目录
cd mysql
#使用phpize初始化 
phpize
#查找php-config命令在哪里
vagrant@ubuntu-bionic:/tmp/mysql$ whereis php-config
php-config: /usr/bin/php-config7.2 /usr/bin/php-config /usr/share/man/man1/php-config.1.gz
#编译mysql扩展,使用mysql native driver作为mysql链接库   
./configure --with-php-config=/usr/bin/php-config --with-mysql=mysqlnd 
#编译
vagrant@ubuntu-bionic:/tmp/mysql$ sudo make && sudo make install 
#编译输出
Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/lib/php/20170718/
  1. 接下来,我们直接编辑php.ini文件,把mysql.so拷贝到php.ini的extension_dir中,然后在php.ini 文件末尾添加一行,填入:
extension=mysql.so
  1. 重启 web服务器

sudo apt-get install mcrypt libmcrypt-dev #Ubuntu 安装编译依赖的文件
yum install libmcrypt libmcrypt-devel mcrypt mhash #Centos

在 php 官网下载 mcrypt 包,php 扩展官网

cd /tmp
wget https://pecl.php.net/get/mcrypt-1.0.3.tgz
tar xf mcrypt-1.0.3.tgz
cd mcrypt-1.0.3

编译安装 mcrypt

phpize
./configure --with-php-config=/usr/bin/php-config
sudo make && sudo make install

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/lib/php/20170718/

编辑 php.ini(如: /etc/php/7.2/apache2/php.ini)文件,在文件末尾添加

extension=mcrypt.so

References

原文地址:https://www.cnblogs.com/fsong/p/13682193.html