search
HomeBackend DevelopmentPHP ProblemHow to install extension in php

How to install extensions in php: 1. Use the apt or yum command to install the extension; 2. Use the pecl install command to install the extension; 3. Compile and install from source code; 4. Install through phpize.

How to install extension in php

The operating environment of this article: windows7 system, php5.3.29 version, DELL G3 computer

Several methods of php installation extension

Install the extension

Note

Different from the running mode of Apache PHP or Nginx PHP, WorkerMan runs based on the PHP command line PHP CLI , using different PHP executable programs, the php.ini file used may also be different. So when you print phpinfo() on the web page and see that a certain extension is installed, it does not mean that the corresponding extension is also installed in the PHP CLI on the command line.

How to determine which extensions are installed by PHP CLI

Running php -m will list the extensions that have been installed by the command line PHP CLI. The result is similar to the following:

~# php -m
[PHP Modules]
libevent
posix
pcntl
...

How to determine the location of the php.ini file of PHP CLI

When we install the extension, we may need to manually configure the php.ini file and add the extension, so we must confirm the php.ini file of PHP CLI s position. You can run php --ini to find the location of the ini file of the PHP CLI. The results are similar to the following (the results displayed by each system will be different):

~# php --ini
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/apc.ini,
/etc/php5/cli/conf.d/libevent.ini,
/etc/php5/cli/conf.d/memcached.ini,
/etc/php5/cli/conf.d/mysql.ini,
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_mysql.ini
...

Install the extension for the PHP CLI (install the memcached extension as Example)

Method 1. Install using apt or yum command

If PHP is installed via apt or yum command, the extension can also be installed via apt or yum

debian/ubuntu and other systems apt installation PHP extension method (non-root users need to add sudo command)

1. Use apt-cache search to find the extension package

~# apt-cache search memcached php
php-apc - APC (Alternative PHP Cache) module for PHP 5
php5-memcached - memcached module for php5

2. Use apt-get install to install the extension package

~# apt-get install -y php5-memcached
Reading package lists... Done
Reading state information... Done
...

centos and other systems yum to install the PHP extension method

1.Useyum searchFind the expansion package

~# yum search memcached php
php-pecl-memcached - memcached module for php5

2. Use yum install to install the expansion package

~# yum install -y php-pecl-memcached
Reading package lists... Done
Reading state information... Done
...

Instructions:

Using apt or yum to install the PHP extension will automatically configure the php.ini file. It can be used directly after installation, which is very convenient. The disadvantage is that some extensions do not have corresponding extension installation packages in apt or yum.

[Recommended learning: "PHP Video Tutorial"]

Method 2. Use pecl to install

Use the pecl install command Install extension

1, pecl installInstall

~# pecl install memcached
downloading memcached-2.2.0.tgz ...
Starting to download memcached-2.2.0.tgz (70,449 bytes)
....

2, Configure php.ini

By running php --ini Find the location of the php.ini file, and then add extension=memcached.so

to the file. Method 3. Source code compilation and installation (generally install the extension that comes with PHP, to install the pcntl extension as Example)

1. Use the php -v command to check the current PHP CLI version

~# php -v
PHP 5.3.29-1~dotdeb.0 with Suhosin-Patch (cli) (built: Aug 14 2014 19:55:20)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies

2. Download the PHP source code according to the version

PHP Historical version download page: http://php.net/releases/

3. Unzip the source code compressed package

. For example, the name of the downloaded compressed package is php-5.3.29.tar .gz

~# tar -zxvf php-5.3.29.tar.gz
php-5.3.29/
php-5.3.29/README.WIN32-BUILD-SYSTEM
php-5.3.29/netware/
...

4. Enter the ext/pcntl directory in the source code

~# cd php-5.3.29/ext/pcntl/

5. Run the phpize command

~# phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626

6. Run configureCommand

~# ./configure
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
...

7. Run make command

~# make
/bin/bash /tmp/php-5.3.29/ext/pcntl/libtool --mode=compile cc ...
-I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend...
...

8. Run make install command

~# make install
Installing shared extensions:     /usr/lib/php5/20090626/

9. Configure the ini file

Find the location of the php.ini file by running php --ini, and then add extension=pcntl.so## to the file

#Note: This method is generally used to install extensions that come with PHP, such as posix extensions and pcntl extensions. In addition to using phpize to compile an extension, you can also recompile the entire PHP and add the extension with parameters during compilation. For example, run

~# ./configure --enable-pcntl --enable-posix ...
~# make && make install
in the source code root directory. Method 4. phpize installation

If you want to install The extension is not in the php source code ext directory, then this extension needs to be searched and downloaded at http://pecl.php.net

Take the installation of the libevent extension as an example (assuming that the system has the libevent-dev library installed)

1. Download the libevent extension file compressed package (you can download it in any directory of the current system)

~# wget http://pecl.php.net/get/libevent-0.1.0.tgz
--2015-05-26 21:43:40--  http://pecl.php.net/get/libevent-0.1.0.tgz
Resolving pecl.php.net... 104.236.228.160
Connecting to pecl.php.net|104.236.228.160|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9806 (9.6K) [application/octet-stream]
Saving to: “libevent-0.1.0.tgz”

100%[=======================================================>] 9,806       41.4K/s   in 0.2s
2. Unzip the extended file compressed package

~# tar -zxvf libevent-0.1.0.tgz
package.xml
libevent-0.1.0/config.m4
libevent-0.1.0/CREDITS
libevent-0.1.0/libevent.c
....
3. Enter the source code directory

~# cd libevent-0.1.0/
4. Run the

phpize command

~# phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
5. Run the

configure command

~# ./configure
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
...

6、运行make命令

~# /bin/bash /data/test/libevent-0.1.0/libtool --mode=compile cc  -I. -I/data/test/libevent-0.1.0 -DPHP_ATOM_INC -I/data/test/libevent-0.1.0/include
...

7、运行make install命令

~# make install
Installing shared extensions:     /usr/lib/php5/20090626/

8、配置ini文件

通过运行 php --ini查找php.ini文件位置,然后在文件中添加extension=libevent.so

The above is the detailed content of How to install extension in php. 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
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

See all articles

Hot AI Tools

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.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft