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:
- OpenSSL
- PDO
- Mbstring
- Tokenizer
- XML
- Ctype
- JSON
- Exif
- Fileinfo
By following these steps, you’ll ensure that your server is set up to support popular web applications and frameworks.
Prerequisites
- A VPS running CentOS.
- cPanel/WHM installed and configured on your VPS.
- 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:
-
Log in to WHM: Access WHM by visiting
https://your-server-ip:2087
. -
Navigate to EasyApache 4: In WHM, go to WHM » Software » EasyApache 4.
-
Customize the PHP Configuration: Click on the Customize button under the "Currently Installed Packages" section.
-
Select the PHP Extensions Tab: In the EasyApache 4 interface, click on the PHP Extensions tab.
-
Search for the Desired Extension: Use the search bar to find the required extension (e.g., OpenSSL, PDO).
-
Enable or Disable the Extension: Toggle the switch next to the extension to enable or disable it.
-
Review and Provision: After selecting the required extensions, click Review at the bottom of the page, then click Provision to apply changes.
Common PHP Extensions and Their Functions
Here’s a closer look at some essential PHP extensions and their uses:
OpenSSL: Provides encryption and decryption functions for secure data transfer.
PDO (PHP Data Objects): A database access layer that enables a uniform method for database interactions.
Mbstring: Supports multibyte string functions, crucial for handling non-ASCII characters.
Tokenizer: Enables the parsing of PHP code, used in syntax highlighting and compilers.
XML: Essential for parsing and manipulating XML data, commonly used by content management systems.
Ctype: Character type checking, useful for validating input data.
- JSON: Allows encoding and decoding of JSON data.
- Exif: Provides metadata information for images (useful in applications that handle photo uploads).
- 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:
-
Check Built-in Extensions: To check if a built-in extension like
json
oropenssl
is present:php -i | grep -E -i '(json|openssl)'
- 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
- 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:
- apcu - APCu (Alternative PHP Cache) for caching.
- imagick - Image processing via ImageMagick.
- redis - Redis caching and session management.
- mysqli - Improved MySQL database driver.
- opcache - Opcode caching to improve performance.
- xmlrpc - XML-RPC for remote procedure calls.
- 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:
-
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
-
Verify PHP Version Compatibility: Ensure that the extension is compatible with your PHP version. Some older extensions may not work with newer PHP versions.
-
Re-Provision in EasyApache 4: If changes aren’t applied after enabling an extension, re-run the provisioning process in EasyApache 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
-
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.
-
To Install Certain Extensions via PECL:
- For extensions like
mongodb
orimagick
, 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
- For extensions like
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.