Under CentOS, PHP has multiple ways to install extensions, including package management-style yum installation, pecl installation, and source code compilation and installation.
Package management-style installation and uninstallation is particularly convenient, while source code compilation-style installation facilitates parameter tuning.
Generally, package-managed installation is recommended to build a local development environment to save time. For online deployment environments, compilation and installation are recommended to facilitate tuning.
This article uses MongoDB extension installation as an example.
Tools
PHP version: 7.0.17
Nginx: 1.10.2
VMware version number: 12.0.0
CentOS version: 7.0
1. yum installation
The yum method can automatically install the expanded .so dynamic library and configure php.ini
Note:
Please make sure there is a corresponding extension in your yum source
After the installation is complete, restart the server Nginx or Apache
Visit the index.php file with your browser , output phpinfo information, if there is MongoDB 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 documentation: https: //www.php.net/manual/zh/mongodb.installation.pecl.php[root@localhost ~]# pecl install mongodb-bash: pecl: Command not found Directly enter pecl install mongodb and an error will be reported, indicating pecl We have not installed it. When installing pecl
[root@localhost ~]# yum -y install php70w-pear [root@localhost ~]# pecl install mongodb configure: error: Cannot find OpenSSL's <evp.h> ERROR: `/var/tmp/mongodb/configure --with-php-config=/usr/bin/php-config' failed, an error will be reported at this step. We need to install openssl. After the installation is completed, continue to execute the last failed command

[root@localhost ~]# yum -y install openssl openssl-devel [root@localhost ~]# pecl install mongodb [root@localhost ~]# systemctl restart nginx # 重新启动 NginxAfter the installation is completed, load the MongoDB extension in the PHP configuration file php.ini


[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 <evp.h>At this step, it feels familiar again It feels familiar again. We need to install openssl. After the installation is completed, continue to execute the command that was not successfully executed last time
##
[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 # 编译
Instructions: php-config is a simple command line Script is used to obtain information about the installed PHP configuration.
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 corresponding php-config. The path to the script.
The compilation is successful as shown below
At this time, load the MongoDB extension in the PHP configuration file php.ini
Restart the server Nginx 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
The difference between pecl installation and source code compilation and installation is that the latter is more convenient for parameter tuning.
When choosing Mongo extensions, the official provides two types: mongo and mongodb
The first one: https://pecl.php.net/package/mongo
Second: https://pecl.php.net/package/mongodb
First official tip: This package has been superseded, but is still maintained for bugs and security fixes, has been abandoned, However, bugs and security issues will continue to be fixed, and PHP7 is not supported.
Recommendation:If the PHP version is 5.x, it is recommended to use the mongo extension
The PHP version is 7.x, it is recommended to use the mongodb extension
PHP5.x can use mongodb extension. But PHP7.x cannot use mongo extension.
Written at the end:If you are learning by yourself, it is recommended to install it with yum, because during your installation process, errors will appear for missing various dependencies.
For more PHP related knowledge, please visit
PHP TutorialThe above is the detailed content of Three PHP extension installation methods under CentOS. For more information, please follow other related articles on the PHP Chinese website!
Laravel routing parameter delivery and controller method definition: Avoiding common errors and best practicesJul 23, 2025 pm 07:27 PMThis tutorial details the correct method of parameter passing in Laravel routing, and corrects common errors in writing parameter placeholders into controller method names. The article provides examples of standardized routing definitions and controller methods, and emphasizes that deletion operations should prioritize the use of HTTPDELETE methods to enhance routing semantics and maintainability.
Guide to matching Laravel routing parameter passing and controller methodJul 23, 2025 pm 07:24 PMThis article aims to resolve common errors in the Laravel framework where routing parameter passing matches controller methods. We will explain in detail why writing parameters directly to the controller method name in the routing definition will result in an error of "the method does not exist", and provide the correct routing definition syntax to ensure that the controller can correctly receive and process routing parameters. In addition, the article will explore best practices for using HTTPDELETE methods in deletion operations.
How to use PHP to develop a Q&A community platform Detailed explanation of PHP interactive community monetization modelJul 23, 2025 pm 07:21 PM1. The first choice for the Laravel MySQL Vue/React combination in the PHP development question and answer community is the first choice for Laravel MySQL Vue/React combination, due to its maturity in the ecosystem and high development efficiency; 2. High performance requires dependence on cache (Redis), database optimization, CDN and asynchronous queues; 3. Security must be done with input filtering, CSRF protection, HTTPS, password encryption and permission control; 4. Money optional advertising, member subscription, rewards, commissions, knowledge payment and other models, the core is to match community tone and user needs.
Efficiently use JSON data to implement cascading drop-down menus in Laravel Blade templatesJul 23, 2025 pm 07:18 PMThis article details how to load a local JSON file in a Laravel application and pass its data to a Blade template. By processing JSON parsing by the controller, the view layer uses Blade's @foreach instruction to traverse the data, thereby realizing dynamically generating drop-down menus. In particular, the article also explores in-depth how to combine JavaScript to implement multi-level linkage drop-down menu functions to provide users with dynamic content display based on selection, and provides practical code examples and precautions for implementing such interactions.
Deep analysis of matching Laravel routing parameter transfer and controller methodJul 23, 2025 pm 07:15 PMThis article deeply explores the correct transmission of routing parameters and the matching mechanism of controller methods in the Laravel framework. In response to the common "method does not exist" error caused by writing routing parameters directly to the controller method name, the article elaborates on the correct way to define routing, that is, declare parameters in the URI and receive them as independent parameters in the controller method. At the same time, the article also provides code examples and suggestions on best practices for HTTP methods, aiming to help developers build more robust and RESTful Laravel applications.
PHP integrated AI intelligent image processing PHP image beautification and automatic editingJul 23, 2025 pm 07:12 PMPHP integrated AI image processing requires the help of a third-party API or local model, which cannot be directly implemented; 2. Use ready-made services such as Google CloudVision API to quickly realize facial recognition, object detection and other functions. The advantages are fast development and strong functions. The disadvantages are that they need to pay, rely on the network and have data security risks; 3. Deploy local AI models through PHP image library such as Imagick or GD combined with TensorFlowLite or ONNXRuntime. It can be customized, the data is safer, and the cost is low, but the development is difficult and requires AI knowledge; 4. Mixed solutions can combine the advantages of API and local model, such as using API for detection and beautification of local models; 5. Selecting AI image processing API should be comprehensive
Twilio Voice Call Maintenance and Recovery: Meeting Functions and Independent Call Leg Management PracticeJul 23, 2025 pm 07:09 PMThis article discusses in-depth two main strategies for realizing voice call holding (Hold) and recovery (Unhold) on the Twilio platform. First, we introduce the detailed introduction to leveraging the Twilio Conference feature to easily manage call retention by updating the Participant resources, and provide corresponding code examples. Second, for scenarios where more detailed control of independent call legs (CallLeg) is required, how to combine TwiML instructions (such as and/) to handle call reconnection, while highlighting the complexity of this approach. The article aims to provide professional and practical guidance to help developers choose the most suitable implementation solution according to specific needs.
Laravel routing parameter passing: correctly define the controller method and routing bindingJul 23, 2025 pm 07:06 PMThis article discusses the correct posture of parameter transfer of controller method in Laravel routing in depth. In response to common errors caused by writing routing parameters directly to the controller method name, the correct routing definition syntax is explained in detail, and the mechanism of Laravel automatic parameter binding is emphasized. At the same time, the article recommends using HTTPDELETE method that is more in line with RESTful specifications to handle deletion operations to improve the maintainability and semantics of the application.


Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download
The most popular open source editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),







