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

Summary of ways to install extensions for PHP in CentOS systems

Jun 04, 2018 pm 05:27 PM
centos php Way

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, mainly package management yum installation, pecl installation , and source code compilation and installation.

Package management style is particularly convenient for installation and uninstallation, while source code compilation style installation is convenient for parameter tuning.

Generally recommended to build a local development environment Package management installation to save time. For online deployment environment, compile and install is recommended for easy tuning.

This article uses the MongoDB extension 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 method Install the .so dynamic library that can automatically install extensions. And configure php.ini

Note:

Please make sure that your yum source has the corresponding extension

After the installation is completed Restart the server Nginx or Apache

browser to access the index.php file and output the phpinfo information, if anyMongoDB information, 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 mongodb and an error will be reported, indicating that pecl we have not installed it, install pecl

[root@localhost ~]# yum -y install php70w-pear
[root@localhost ~]# pecl install mongodb
configure: error: Cannot find OpenSSL&#39;s <evp.h>
ERROR: `/var/tmp/mongodb/configure --with-php-config=/usr/bin/php-config&#39; failed

At this step, another

error will be reported. We need to install openssl. After the installation is completed, continue to execute the last unsuccessfully 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

PHP configuration file php.iniMongoDB Extension

##After installation is complete, restart the server

Nginx

or Apache browser Access the

index.php

file and output phpinfo information. If there is MongoDB information, 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&#39;s <evp.h>

At this point

It’s a familiar taste and a familiar feeling

, We need to install openssl. After the installation is completed, continue to execute the last unexecuted successfully command

##

[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

obtain the installed PHP configuration information. 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-config script. Compilation successful

As shown below

At this time in the PHP

configuration file

php.ini Load insideMongoDB extension

Restart the serverNginx

or

Apache The browser accesses the index.php

file and outputs

phpinfo information. If there is MongoDB information, 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 installation is : The latter is more convenient for parameter tuning. When choosing Mongo extension

, the official provides two types:

mongo and mongodbThe 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, but bug and security Problems will continue to be fixed, and PHP7 is not supported.

Recommendation:

If PHP version is 5.x, it is recommended to use mongo extension

If PHP version is 7.x, it is recommended to use mongodb Extensions

PHP5.x can use the mongodb extension. But PHP7.x cannot use the mongo extension.

Written at the end:

If you are learning by yourself, it is still recommended to install with yum, because there will be missing during your installation process Error 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 of this Website
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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1596
276
Fix: Ethernet 'Unidentified Network' Fix: Ethernet 'Unidentified Network' Aug 12, 2025 pm 01:53 PM

Restartyourrouterandcomputertoresolvetemporaryglitches.2.RuntheNetworkTroubleshooterviathesystemtraytoautomaticallyfixcommonissues.3.RenewtheIPaddressusingCommandPromptasadministratorbyrunningipconfig/release,ipconfig/renew,netshwinsockreset,andnetsh

How to work with arrays in php How to work with arrays in php Aug 20, 2025 pm 07:01 PM

PHParrayshandledatacollectionsefficientlyusingindexedorassociativestructures;theyarecreatedwitharray()or[],accessedviakeys,modifiedbyassignment,iteratedwithforeach,andmanipulatedusingfunctionslikecount(),in_array(),array_key_exists(),array_push(),arr

Describe the Observer design pattern and its implementation in PHP. Describe the Observer design pattern and its implementation in PHP. Aug 15, 2025 pm 01:54 PM

TheObserverdesignpatternenablesautomaticnotificationofdependentobjectswhenasubject'sstatechanges.1)Itdefinesaone-to-manydependencybetweenobjects;2)Thesubjectmaintainsalistofobserversandnotifiesthemviaacommoninterface;3)Observersimplementanupdatemetho

How to use the $_COOKIE variable in php How to use the $_COOKIE variable in php Aug 20, 2025 pm 07:00 PM

$_COOKIEisaPHPsuperglobalforaccessingcookiessentbythebrowser;cookiesaresetusingsetcookie()beforeoutput,readvia$_COOKIE['name'],updatedbyresendingwithnewvalues,anddeletedbysettinganexpiredtimestamp,withsecuritybestpracticesincludinghttponly,secureflag

phpMyAdmin security best practices phpMyAdmin security best practices Aug 17, 2025 am 01:56 AM

To effectively protect phpMyAdmin, multiple layers of security measures must be taken. 1. Restrict access through IP, only trusted IP connections are allowed; 2. Modify the default URL path to a name that is not easy to guess; 3. Use strong passwords and create a dedicated MySQL user with minimized permissions, and it is recommended to enable two-factor authentication; 4. Keep the phpMyAdmin version up to fix known vulnerabilities; 5. Strengthen the web server and PHP configuration, disable dangerous functions and restrict file execution; 6. Force HTTPS to encrypt communication to prevent credential leakage; 7. Disable phpMyAdmin when not in use or increase HTTP basic authentication; 8. Regularly monitor logs and configure fail2ban to defend against brute force cracking; 9. Delete setup and

Using XSLT Parameters to Create Dynamic Transformations Using XSLT Parameters to Create Dynamic Transformations Aug 17, 2025 am 09:16 AM

XSLT parameters are a key mechanism for dynamic conversion through external passing values. 1. Use declared parameters and set default values; 2. Pass the actual value from application code (such as C#) through interfaces such as XsltArgumentList; 3. Control conditional processing, localization, data filtering or output format through $paramName reference parameters in the template; 4. Best practices include using meaningful names, providing default values, grouping related parameters, and performing value verification. The rational use of parameters can make XSLT style sheets highly reusable and maintainable, and the same style sheets can produce diversified output results based on different inputs.

You are not currently using a display attached to an NVIDIA GPU [Fixed] You are not currently using a display attached to an NVIDIA GPU [Fixed] Aug 19, 2025 am 12:12 AM

Ifyousee"YouarenotusingadisplayattachedtoanNVIDIAGPU,"ensureyourmonitorisconnectedtotheNVIDIAGPUport,configuredisplaysettingsinNVIDIAControlPanel,updatedriversusingDDUandcleaninstall,andsettheprimaryGPUtodiscreteinBIOS/UEFI.Restartaftereach

How would you implement API versioning in a PHP application? How would you implement API versioning in a PHP application? Aug 14, 2025 pm 11:14 PM

APIversioninginPHPcanbeeffectivelyimplementedusingURL,header,orqueryparameterapproaches,withURLandheaderversioningbeingmostrecommended.1.ForURL-basedversioning,includetheversionintheroute(e.g.,/v1/users)andorganizecontrollersinversioneddirectories,ro

See all articles