How to Enable Essential PHP Extensions on a VPS with CentOS and cPanel Print

  • 15

PHP extensions enhance the functionality of your server, allowing applications to leverage additional features such as database access, data encryption, and file manipulation. In this article, we’ll guide you through the process of enabling essential PHP extensions on a VPS running CentOS with cPanel and WHM.

Introduction

This guide covers enabling essential PHP extensions on a CentOS VPS with cPanel. The following PHP extensions are discussed, as they are crucial for web applications:

  1. OpenSSL
  2. PDO
  3. Mbstring
  4. Tokenizer
  5. XML
  6. Ctype
  7. JSON
  8. Exif
  9. Fileinfo

By following these steps, you’ll ensure that your server is set up to support popular web applications and frameworks.


Prerequisites

  1. A VPS running CentOS.
  2. cPanel/WHM installed and configured on your VPS.
  3. WHM access (admin-level privileges).

Step 1: Check Existing PHP Extensions

Before enabling or installing extensions, check the extensions that are already available on your server.

To list all currently installed PHP extensions, run:

php -m

To check for a specific extension, use:

php -m | grep <extension_name>

For example, to check if the ctype extension is installed, run:

php -m | grep ctype

Step 2: Enabling PHP Extensions in WHM via EasyApache 4

cPanel provides EasyApache 4, a tool for managing Apache, PHP, and their modules. You can use EasyApache 4 to enable or disable PHP extensions.

Steps to Enable/Disable PHP Extensions:

  1. Log in to WHM: Access WHM by visiting https://your-server-ip:2087.

  2. Navigate to EasyApache 4: In WHM, go to WHM » Software » EasyApache 4.

  3. Customize the PHP Configuration: Click on the Customize button under the "Currently Installed Packages" section.

  4. Select the PHP Extensions Tab: In the EasyApache 4 interface, click on the PHP Extensions tab.

  5. Search for the Desired Extension: Use the search bar to find the required extension (e.g., OpenSSL, PDO).

  6. Enable or Disable the Extension: Toggle the switch next to the extension to enable or disable it.

  7. Review and Provision: After selecting the required extensions, click Review at the bottom of the page, then click Provision to apply changes.


 

Cpanel - Easy Apache 4

 

Common PHP Extensions and Their Functions

Here’s a closer look at some essential PHP extensions and their uses:

  1. OpenSSL: Provides encryption and decryption functions for secure data transfer.
  2. PDO (PHP Data Objects): A database access layer that enables a uniform method for database interactions.
  3. Mbstring: Supports multibyte string functions, crucial for handling non-ASCII characters.
  4. Tokenizer: Enables the parsing of PHP code, used in syntax highlighting and compilers.
  5. XML: Essential for parsing and manipulating XML data, commonly used by content management systems.
  6. Ctype: Character type checking, useful for validating input data.
  7. JSON: Allows encoding and decoding of JSON data.
  8. Exif: Provides metadata information for images (useful in applications that handle photo uploads).
  9. Fileinfo: Helps in determining the file type of a file, useful for handling file uploads.

Step 3: Enabling PHP Extensions from Command Line (Optional)

Some PHP extensions are built into PHP and may not be available through EasyApache 4. If you need to verify or enable these extensions directly from the command line:

  1. Check Built-in Extensions: To check if a built-in extension like json or openssl is present:

    php -i | grep -E -i '(json|openssl)'
    
  2. Manual Installation for Some Extensions: If an extension isn’t available through EasyApache, you might need to install it manually. For example, to install the intl extension:
    yum install ea-phpxx-php-intl  # Replace xx with your PHP version
    ​
  3. Restart Apache to Apply Changes:
    systemctl restart httpd
    ​

Additional Extensions Available in EasyApache 4

If your application requires additional PHP functionality, here are other commonly installed PHP extensions you can enable in EasyApache 4:

  1. apcu - APCu (Alternative PHP Cache) for caching.
  2. imagick - Image processing via ImageMagick.
  3. redis - Redis caching and session management.
  4. mysqli - Improved MySQL database driver.
  5. opcache - Opcode caching to improve performance.
  6. xmlrpc - XML-RPC for remote procedure calls.
  7. intl - Internationalization support, important for multi-language applications.

Enable these extensions by following the steps outlined in Step 2.

Troubleshooting PHP Extension Issues

If you encounter issues with enabling or disabling PHP extensions:

  1. Check Apache Logs: Logs can provide information on errors related to PHP extensions. Check Apache’s error log:

    tail -f /etc/httpd/logs/error_log
    
  2. Verify PHP Version Compatibility: Ensure that the extension is compatible with your PHP version. Some older extensions may not work with newer PHP versions.

  3. Re-Provision in EasyApache 4: If changes aren’t applied after enabling an extension, re-run the provisioning process in EasyApache 4.

  4. Restart Apache: Always restart Apache after making changes to PHP extensions:

    systemctl restart httpd
    

Complete List of PHP Extensions for cPanel/WHM (EasyApache 4 and Manual Installation)

This list includes a wide range of extensions, from essential to advanced, for various applications in web development.

1. Core and Commonly Used Extensions

  • bcmath - Arbitrary precision mathematics.
  • calendar - Calendar functions.
  • Core - Core PHP functions.
  • ctype - Character type checking, useful for validating input.
  • curl - Allows PHP to make HTTP requests.
  • date - Date and time functions.
  • dom - DOM manipulation, useful for XML and HTML handling.
  • exif - Image metadata for photos.
  • fileinfo - Identifies file types, useful for file uploads.
  • filter - Data filtering functions.
  • ftp - FTP functions for file transfer.
  • gettext - Localization support for multilingual applications.
  • hash - Data hashing functions.
  • iconv - Character set conversion functions.
  • json - JSON encoding and decoding.
  • libxml - Core XML library.
  • mbstring - Multibyte string handling for non-ASCII characters.
  • mysqli - Improved MySQL extension.
  • mysqlnd - Native MySQL driver.
  • openssl - Secure communication through SSL.
  • pcre - Regular expression functions.
  • PDO - Database access layer.
  • pdo_mysql - MySQL driver for PDO.
  • pdo_pgsql - PostgreSQL driver for PDO.
  • pdo_sqlite - SQLite driver for PDO.
  • Phar - PHP Archive (Phar) support.
  • posix - POSIX functions for process handling.
  • Reflection - Reflection API, useful in frameworks.
  • session - Session management for PHP.
  • SimpleXML - Simple XML handling.
  • soap - Simple Object Access Protocol (SOAP) for web services.
  • sockets - Network socket support.
  • sodium - Advanced cryptographic library.
  • SPL - Standard PHP Library.
  • sqlite3 - SQLite database handling.
  • standard - Standard PHP functions.
  • tokenizer - PHP code tokenization.
  • xml - Core XML handling.
  • xmlreader - Streaming XML reader.
  • xmlwriter - XML writing functions.
  • xsl - XSLT transformations for XML.
  • zip - ZIP file handling.
  • zlib - Data compression functions.

2. Database Extensions

  • mysqli - Improved MySQL support.
  • pdo_mysql - PDO driver for MySQL.
  • pdo_pgsql - PDO driver for PostgreSQL.
  • pgsql - PostgreSQL database functions.
  • sqlite3 - SQLite database handling.
  • mongodb - MongoDB NoSQL database driver (typically installed via PECL).

3. Caching and Performance Extensions

  • apcu - Alternative PHP Cache, APCu, for caching.
  • memcached - Memcached support for session and caching.
  • redis - Redis database support for caching and session management.
  • opcache - Opcode caching to improve PHP performance.

4. Image and Document Processing Extensions

  • gd - Basic graphics library for image processing.
  • imagick - Advanced image processing with ImageMagick (PECL).
  • exif - Metadata handling for images, useful in photo uploads.
  • pdf - PDF generation and manipulation (optional, depending on availability).

5. Networking and Communication Extensions

  • curl - Client URL library functions for making HTTP requests.
  • soap - SOAP protocol for web services.
  • sockets - Network socket functions.
  • xmlrpc - XML-RPC protocol for remote procedure calls.

6. Cryptography Extensions

  • openssl - Encryption for secure communications.
  • mcrypt - Data encryption (deprecated but still used in older applications).
  • gmp - GNU Multiple Precision arithmetic library, often used in cryptographic applications.
  • sodium - Advanced cryptography support, recommended for secure applications.

7. String, Data Handling, and Internationalization Extensions

  • intl - Internationalization support for multilingual applications.
  • mbstring - Multibyte string functions for non-ASCII characters.
  • iconv - Character set conversion.
  • gettext - Localization support for different languages.

8. File Compression and Archive Extensions

  • bz2 - Bzip2 compression.
  • zlib - Compression functions.
  • zip - ZIP file handling for file uploads and downloads.

9. Security Extensions

  • suhosin - Hardened PHP security extension (optional, not commonly included by default).
  • snuffleupagus - PHP security extension that provides runtime security policies.

10. Miscellaneous Extensions

  • ldap - LDAP protocol functions for directory services.
  • xml - Core XML handling.
  • xsl - XSLT transformations.
  • tokenizer - Tokenizes PHP code for syntax highlighting and parsing.
  • json - JSON encoding and decoding for data exchange.

Installation Commands for cPanel

  1. To Enable an Extension via EasyApache 4 in WHM:

    • Go to WHM » Software » EasyApache 4.
    • Select Customize in the “Currently Installed Packages” section.
    • Find the required extension under PHP Extensions and toggle it on.
  2. To Install Certain Extensions via PECL:

    • For extensions like mongodb or imagick, use:
      sudo pecl install <extension_name>
      ​
    • Enable the extension in php.ini:
      echo "extension=<extension_name>.so" >> /opt/cpanel/ea-phpXX/root/etc/php.ini
      ​

Conclusion

Enabling essential PHP extensions in cPanel/WHM with EasyApache 4 allows you to tailor your VPS for improved functionality and compatibility with various web applications. Whether you’re setting up a new server or optimizing an existing one, enabling the right extensions can significantly enhance your server’s capabilities. For more detailed information on specific PHP extensions, refer to the official PHP documentation.


Was this answer helpful?

« Back