Home>Article>Backend Development> Summary of ways to install extensions for PHP in CentOS systems

Summary of ways to install extensions for PHP in CentOS systems

不言
不言 Original
2018-06-04 17:27:45 2204browse

This article gives you a summary of the ways to install and expand PHP in CentOS systems, mainly including package-managed yum installation, pecl installation, and source code compilation and installation. The summary is very comprehensive and I recommend it to everyone.

CentOS, PHP has many ways to install extensions, mainlypackage managementyum installation,pecl installation, andsource code compilation and installation.

Package management styleis particularly convenient for installation and uninstallation, whilesource code compilation styleinstallation is convenient for parameter tuning.

Generally recommended to build a local development environmentPackage managementinstallation to save time. Foronline deploymentenvironment,compile and installis recommended for easy tuning.

This article uses theMongoDBextension installation example.

Tools

PHP version: 7.0.17

Nginx: 1.10.2

VMware version number: 12.0.0

CentOS version: 7.0

1. yum installation

yum methodInstall the .so dynamic library that can automatically install extensions. And configurephp.ini

Note:

Please make sure that youryum sourcehas the corresponding extension

After the installation is completed Restart the serverNginxorApache

browser to access theindex.phpfile and output thephpinfoinformation, if anyMongoDBinformation, the installation is successful

[root@localhost ~]yum search mongodb|grep php # 搜索 yum 源里面 MongoDB 拓展 [root@localhost ~]yum -y install php70w-pecl-mongo # 安装 PHP 对应版本的 MongoDB 扩展 [root@localhost ~]systemctl restart nginx # 重新启动 Nginx

# #2. pecl installation

Official document: http://php.net/manual/zh/mong...

[root@localhost ~]# pecl install mongodb -bash: pecl: 未找到命令

Directly enter

pecl install mongodband an error will be reported, indicating thatpeclwe have not installed it, installpecl

[root@localhost ~]# yum -y install php70w-pear [root@localhost ~]# pecl install mongodb configure: error: Cannot find OpenSSL's  ERROR: `/var/tmp/mongodb/configure --with-php-config=/usr/bin/php-config' failed

At this step, another

error will be reported. We need to installopenssl. After the installation is completed, continue to execute the lastunsuccessfully executed command

[root@localhost ~]# yum -y install openssl openssl-devel [root@localhost ~]# pecl install mongodb [root@localhost ~]# systemctl restart nginx # 重新启动 Nginx

After the installation is complete, load it in the

PHPconfiguration filephp.iniMongoDBExtension

##After installation is complete, restart the server

Nginx

orApachebrowser Access the

index.php

file and outputphpinfoinformation. If there isMongoDBinformation, the installation is successful

3. Source code compilation and installation

Source code compilation package download list: https://pecl.php.net/packages.php

Mongodb package download address: https: //pecl.php.net/package/mongodb

[root@localhost ~]# wget http://pecl.php.net/get/mongodb-1.2.8.tgz #下载源码包 [root@localhost ~]# tar zxf mongodb-1.2.8.tgz #解压 [root@localhost ~]# cd mongodb-1.2.8 # 可能是 /usr/local/php/bin/phpize 找到自己的 phpize 文件,php-config 同理 [root@localhost mongodb-1.2.8]# /usr/bin/phpize Configuring for: PHP Api Version: 20151012 Zend Module Api No: 20151012 Zend Extension Api No: 320151012 [root@localhost mongodb-1.2.8]# ./configure --with-php-config=/usr/bin/php-config configure: error: Cannot find OpenSSL's 

At this point

It’s a familiar taste and a familiar feeling

, We need to installopenssl. After the installation is completed, continue to execute the lastunexecuted successfullycommand

##

[root@localhost mongodb-1.2.8]# yum -y install openssl openssl-devel [root@localhost mongodb-1.2.8]# ./configure --with-php-config=/usr/bin/php-config # 确保自己安装了 gcc gcc++ 如果没有安装 yum -y install gcc gcc++ [root@localhost mongodb-1.2.8]# make && make install # 编译

Description:

php-config

is a simple command line script used to

obtainthe installedPHP configurationinformation.When compiling an extension, if multiple PHP versions are installed, you can use the--with-php-config

option during configuration to specify which version to use for compilation. This option specifies The path to the corresponding

php-configscript.Compilation successful

As shown below

At this time in thePHP

configuration file

php.iniLoad insideMongoDBextension

Restart the serverNginx

or

ApacheThe browser accesses theindex.php

file and outputs

phpinfoinformation. If there isMongoDBinformation, the installation is successful

[root@localhost mongodb-1.2.8]# systemctl restart nginx # 重新启动 Nginx

Summary: The difference between

pecl installation

and

source code compilation and installationis : The latter is more convenient for parameter tuning.When choosingMongo extension

, the official provides two types:

mongoandmongodbThe first one: https://pecl.php.net/package/mongo

Second type: https://pecl.php.net/package/mongodb

The first official tip:This package has been superseded, but is still maintained for bugs and security fixes, has been abandoned, butbugandsecurityProblems will continue to be fixed, andPHP7is not supported.

Recommendation:

If PHP version is 5.x, it is recommended to usemongoextension

If PHP version is 7.x, it is recommended to usemongodbExtensions

PHP5.x can use themongodbextension. But PHP7.x cannot use themongoextension.

Written at the end:

If you are learning by yourself, it is still recommended to installwith yum, because there will bemissing during your installation processError reports for various dependencies

The above is the detailed content of Summary of ways to install extensions for PHP in CentOS systems. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn