Home>Article>Backend Development> Summary of ways to install extensions for PHP in CentOS systems
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 management
yum installation
,pecl installation
, andsource code compilation and installation
.
Package management style
is particularly convenient for installation and uninstallation, whilesource code compilation style
installation is convenient for parameter tuning.
Generally recommended to build a local development environmentPackage management
installation to save time. Foronline deployment
environment,compile and install
is recommended for easy tuning.
This article uses theMongoDB
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 configurephp.ini
Note:
Please make sure that youryum source
has the corresponding extension
After the installation is completed Restart the serverNginx
orApache
browser to access theindex.php
file and output thephpinfo
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 mongodband an error will be reported, indicating that
peclwe have not installed it, install
pecl
[root@localhost ~]# yum -y install php70w-pear [root@localhost ~]# pecl install mongodb configure: error: Cannot find OpenSSL'sAt this step, anotherERROR: `/var/tmp/mongodb/configure --with-php-config=/usr/bin/php-config' failed
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 # 重新启动 NginxAfter the installation is complete, load it in the
PHPconfiguration file
php.iniMongoDB
Extension
##After installation is complete, restart the server
NginxorApache
browser Access the
file and outputphpinfo
information. If there isMongoDB
information, the installation is successful
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 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 toobtainthe installed
PHP configurationinformation.
When compiling an extension, if multiple PHP versions are installed, you can use the
--with-php-config
php-configscript.
Compilation successful
At this time in thePHP
configuration filephp.iniLoad inside
MongoDBextension
Restart the serverNginx
orApacheThe browser accesses the
index.php
phpinfoinformation. If there is
MongoDBinformation, the installation is successful
[root@localhost mongodb-1.2.8]# systemctl restart nginx # 重新启动 Nginx
Summary: The difference between
pecl installation
andsource code compilation and installationis : The latter is more convenient for parameter tuning.
When choosing
Mongo extension
mongoand
mongodbThe first one: https://pecl.php.net/package/mongo
The first official tip:This package has been superseded, but is still maintained for bugs and security fixes
, has been abandoned, butbug
andsecurity
Problems will continue to be fixed, andPHP7
is not supported.
Recommendation:
If PHP version is 5.x, it is recommended to usemongo
extension
If PHP version is 7.x, it is recommended to usemongodb
Extensions
PHP5.x can use themongodb
extension. But PHP7.x cannot use themongo
extension.
Written at the end:
If you are learning by yourself, it is still recommended to installwith yum, because there will be
missing 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!