简体   繁体   English

如何在 Ubuntu 上为 PHP7 安装 GMP

[英]How to install GMP for PHP7 on Ubuntu

I was getting the following error when trying to run composer update on a SimpleSAML project.尝试在 SimpleSAML 项目上运行composer update时出现以下错误。

- openid/php-openid dev-master requires ext-gmp * -> the requested PHP extension gmp is missing from your system.

Running sudo apt-get install php5-gmp did not work and neither did sudo apt-get install php7-gmp运行sudo apt-get install php5-gmp不起作用, sudo apt-get install php7-gmp

To install GMP for PHP7.0 on Ubuntu, run: sudo apt-get install php7.0-gmp要在 Ubuntu 上为 PHP7.0 安装 GMP,请运行: sudo apt-get install php7.0-gmp

Make sure your php.ini contains the following: extension=php_gmp.so确保您的php.ini包含以下内容: extension=php_gmp.so

To find out where your php.ini is located, run: php --ini要找出php.ini所在的位置,请运行: php --ini

对于 PHP 7.2:

sudo apt-get install php7.2-gmp

PHP 7 中安装扩展的新方法是只写“php-EXTENSION”在这种情况下它很简单:

sudo apt-get install php-gmp

For PHP 7.4:对于 PHP 7.4:

sudo apt-get install php7.4-gmp

SO: Ubuntu 20.04所以: Ubuntu 20.04

Thank you it helps me.谢谢它对我有帮助。 I use PHP 7.2.我使用 PHP 7.2。 Therefore, I run:因此,我运行:

  1. sudo apt-get install php7.2-gmp
  2. extension=php_gmp.so
apt-get install php7.1-gmp

就是这样。

If you are running php 7.2 and above, then如果您运行的是 php 7.2 及更高版本,那么

sudo apt-get install php7.2-gmp

or you can as well install bcmath extension using或者您也可以使用安装bcmath扩展

sudo apt-get install php7.2-bcmath

I recommend you install both of them, after complete install restart apache我建议你安装它们,完成安装后重启apache

sudo service apache2 reload

sudo service apache2 restart

For docker based on official php images like php:7.2-fpm对于基于php:7.2-fpm等官方 php 镜像php:7.2-fpm

Just add this to Dockerfile只需将其添加到 Dockerfile

RUN apt install -y libgmp-dev && docker-php-ext-install gmp

for centos对于centos

sudo yum install php-gmp

for ubuntu对于 ubuntu

sudo apt install php-gmp

also enable php extension in ini file还要在ini文件中启用php扩展

extension=php_gmp.so

UPDATE: apt-get has evolved over the years into just apt.更新: apt-get 多年来已经演变成 apt。 On modern systems this will detect the php version, etc.在现代系统上,这将检测 php 版本等。

sudo apt install php-gmp

It's better to search using package or dependency manager installed in machine.最好使用安装在机器上的packagedependency manager进行搜索。 For yum , you can search using yum search gmp and then install.对于yum ,您可以使用yum search gmp进行yum search gmp ,然后安装。

yum search gmp

This will yield these search results这将产生这些搜索结果

Loaded pluginss: extras_suggestions, langpacks, priorities, update-motd
170 packages excluded due to repository priority protections
========================================================= N/S matched: gmp ==========================================================
perl-Math-BigInt-GMP.x86_64 : Math::BigInt::GMP Perl module
python-gmpy2.x86_64 : Python 2 interface to GMP, MPFR, and MPC
gmp.x86_64 : A GNU arbitrary precision library
gmp.i686 : A GNU arbitrary precision library
gmp-devel.x86_64 : Development tools for the GNU MP arbitrary precision library
gmp-static.x86_64 : Development tools for the GNU MP arbitrary precision library
mingw32-gmp.noarch : Cross-compiled GNU arbitrary precision library
mingw64-gmp.noarch : Cross-compiled GNU arbitrary precision library
perl-Math-GMP.x86_64 : High speed arbitrary size integer math
php-gmp.x86_64 : A module for PHP applications for using the GNU MP library

Now install extension with: yum install php-gmp.x86_64现在安装扩展: yum install php-gmp.x86_64

For PHP 7.3 try this.对于 PHP 7.3,试试这个。

sudo apt-get install php7.3 -gmp
extension=php_gmp.so

in Ubuntu在 Ubuntu 中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM