Install PHP Extensions on CentOS

This section provides a tutorial example on how to add PHP extensions on CentOS Linux systems by searching and installing the extension using the 'dnf' package manager.

PHP has many extensions. Some of them are pre-installed and some are not. If you are getting errors like "Class ... not found", or "Call to undefined function ...", you need to install the extension that provides the missing class or function.

For example, when I test a new Web application on my CentOS system, I see this error. I know that I need to install the ZIP extension.

PHP Fatal error:  Uncaught Error: Class 'ZipArchive' not found in

Stack trace:
#0 download.php(338): zipData()
#1 dowload.php(22): prepareData()
#2 {main}

To fix the problem, I check what PHP extensions have been installed on the system first:

herong$ dnf list installed | grep php


There is no ZIP related extensions installed yet. So I search for PHP extensions:

herong$ dnf search php

php-opcache.x86_64 : The Zend OPcache
php-pecl-zip.x86_64 : A ZIP archive management extension
php-pecl-apcu.x86_64 : APC User Cache
php-pecl-apcu-devel.x86_64 : APCu developer files (header)

I see that "php-pecl-zip" is available for my system. So I install it:

herong$ sudo dnf install php-pecl-zip

Now re-run the Web application. The 'ZipArchive' error is gone!

Table of Contents

 About This Book

 Introduction and Installation of PHP

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Interface with Operating System

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 Managing File Upload

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Parsing and Managing HTML Documents

 Configuring and Sending Out Emails

 Image and Picture Processing

 Managing ZIP Archive Files

 Managing PHP Engine and Modules on macOS

Managing PHP Engine and Modules on CentOS

 PHP Version Pre-Installed on CentOS

Install PHP Extensions on CentOS

 PHP Version Pre-Installed on CentOS 6

 Use PHP Composer on CentOS Computers

 Archived Tutorials


 Full Version in PDF/EPUB