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:452359browse

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:
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