search
HomeBackend DevelopmentPHP ProblemHow to install extension in php

WorkerMan runs based on the PHP command line PHP CLI and uses different PHP executable programs. Today we will talk about how to install the extension. You can refer to it if you need it.

How to install extension in php

Install extension

Note

Different from the running mode of Apache PHP or Nginx PHP, WorkerMan is based on PHP command line PHP CLI runs, using different PHP executable programs, and the php.ini file used may also be different. Therefore, if you print phpinfo() on the web page and see that an extension is installed, it does not mean that the corresponding extension is also installed on 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 that PHP The location of the CLI's php.ini file. You can run php --ini to find the location of the ini file of 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 extensions for PHP CLI (installing the memcached extension as an example)

Method 1. Use apt or yum command to install

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

debian /ubuntu and other systems apt to install 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 installation PHP extension method

1. Use yum search to find the extension package

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

2. Use yum install to install the extension 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.

Method 2, use pecl to install

Use pecl install command to install extension

1, pecl install installation

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

2, Configure php.ini

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

Method 3. Source code compilation and installation (generally It is to install the extension that comes with PHP, take the installation of pcntl extension as an 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 according to the version PHP source code

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

3. Decompress 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 the configure command

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

7. Run the 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 the make install command

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

9. Configure the ini file

Search by running php --ini php.ini file location, and then add extension=pcntl.so

to the file. Description: 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 the extension to be installed is not in the php source code ext directory, then the 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 libevent installed -dev library)

1. Download the libevent expansion 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 expanded 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. Run the make command

~# /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. Run make install command

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

8, configure ini file

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

Recommended learning: php video tutorial

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
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
ACID vs BASE Database: Differences and when to use each.ACID vs BASE Database: Differences and when to use each.Mar 26, 2025 pm 04:19 PM

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

PHP Secure File Uploads: Preventing file-related vulnerabilities.PHP Secure File Uploads: Preventing file-related vulnerabilities.Mar 26, 2025 pm 04:18 PM

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

PHP Input Validation: Best practices.PHP Input Validation: Best practices.Mar 26, 2025 pm 04:17 PM

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

PHP API Rate Limiting: Implementation strategies.PHP API Rate Limiting: Implementation strategies.Mar 26, 2025 pm 04:16 PM

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

PHP Password Hashing: password_hash and password_verify.PHP Password Hashing: password_hash and password_verify.Mar 26, 2025 pm 04:15 PM

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.Mar 26, 2025 pm 04:13 PM

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

PHP XSS Prevention: How to protect against XSS.PHP XSS Prevention: How to protect against XSS.Mar 26, 2025 pm 04:12 PM

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

PHP Interface vs Abstract Class: When to use each.PHP Interface vs Abstract Class: When to use each.Mar 26, 2025 pm 04:11 PM

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct

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

Video Face Swap

Video Face Swap

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

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

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

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.