PHP extensions and libraries provide essential functionality for various applications. In this guide, we’ll walk through managing pre-installed extensions, installing additional ones, and handling complex libraries with required dependencies in DirectAdmin. Additionally, we’ll cover Composer for managing PHP libraries.
1. Introduction to PHP Extensions
PHP extensions enhance server capabilities, supporting everything from database interactions to image processing. This guide covers:
- Viewing pre-installed PHP extensions on DirectAdmin VPS.
- Installing additional PHP extensions using CustomBuild.
- Installing complex libraries with dependencies.
- Using Composer for PHP library management.
2. Viewing Pre-installed PHP Extensions
DirectAdmin comes with many core PHP extensions pre-installed. To see which are currently enabled, use:
php -m
Commonly Pre-installed PHP Extensions
-
Core Modules:
bcmath
,calendar
,ctype
,curl
,date
,dom
,exif
,fileinfo
,filter
,ftp
,gettext
,hash
,iconv
,json
,libxml
,mbstring
,mysqli
,mysqlnd
,openssl
,pcre
,PDO
,pdo_mysql
,pdo_sqlite
,Phar
,Reflection
,session
,SimpleXML
,sockets
,sodium
,SPL
,sqlite3
,standard
,tokenizer
,xml
,xmlreader
,xmlwriter
,xsl
,zip
,zlib
-
Zend Extensions:
ionCube Loader
- Decrypts encrypted PHP files.
3. Installing Additional PHP Extensions with CustomBuild
DirectAdmin’s CustomBuild allows you to manage PHP extensions. Here’s an example of installing the imap
extension, which can be replicated for any other extension.
Steps:
-
Navigate to CustomBuild Directory
cd /usr/local/directadmin/custombuild
-
Update CustomBuild
Ensure you’re working with the latest version:
./build update
-
Set the PHP Extension for Installation
To prepare
imap
for installation:./build set_php "imap" yes
-
Install the PHP Extension
Run:
./build php_imap
Repeat these steps for any other extension by replacing imap
with the extension’s name.
List of Additional PHP Extensions Available with CustomBuild in DirectAdmin
These extensions provide specialized functionalities for various applications and can be installed through DirectAdmin’s CustomBuild system. To install each extension, replace <extension_name>
in the command below with the desired extension’s name.
Installation Command Template:
-
Set the Extension for Installation:
./build set_php "<extension_name>" yes
- Install the Extension:
./build php_<extension_name>
Common Additional PHP Extensions
-
Database Extensions
pdo_pgsql
- PostgreSQL driver for PDO.pgsql
- PostgreSQL database functions.mongodb
- MongoDB driver (usually installed via PECL).sqlite3
- SQLite database access.
-
Caching and Memory Extensions
apcu
- Alternative PHP Cache for caching.memcached
- Memcached driver for PHP.redis
- Redis database support for caching and session management.opcache
- OPcache for improving PHP performance.
-
Cryptography Extensions
gmp
- GNU Multiple Precision arithmetic.mcrypt
- Encryption functions (deprecated but sometimes required).sodium
- Advanced cryptography library.openssl
- Secure Sockets Layer (SSL) support for secure connections.
-
Image and Document Processing Extensions
gd
- Basic graphics library.imagick
- Advanced image processing with ImageMagick (installed via PECL).exif
- Metadata handling for images.pdf
- PDF generation and manipulation support.
-
Network and Communication Extensions
curl
- Client URL library functions.soap
- Simple Object Access Protocol for web services.sockets
- Network socket support.xmlrpc
- Remote Procedure Call using XML.
-
Security Extensions
suhosin
- Hardened PHP security extension.snuffleupagus
- PHP security module for runtime security.
-
String and Data Manipulation Extensions
intl
- Internationalization functions for language handling.mbstring
- Multibyte string functions for non-ASCII character handling.iconv
- Character set conversion.gettext
- Localization support for multiple languages.
-
File and Data Compression Extensions
bz2
- Bzip2 compression.zlib
- Data compression.zip
- ZIP file creation and extraction.
-
Miscellaneous Extensions
ldap
- Lightweight Directory Access Protocol functions.xml
- Core XML manipulation functions.xsl
- XSL transformations for XML.tokenizer
- Tokenizes PHP code, useful for parsing and analysis.json
- JSON encoding and decoding.
Example Installation:
To install the ldap
extension:
-
Set the Extension for Installation:
./build set_php "ldap" yes
- Install the Extension:
./build php_ldap
4. Installing Complex PHP Libraries
Some PHP libraries, like dlib
, imagick
, mongodb
, and redis
, require additional dependencies and specific installation steps. Here’s a guide to installing these advanced libraries.
A. Installing dlib
(Machine Learning Library)
dlib
is a powerful machine-learning library requiring additional dependencies.
-
Install Essential Packages
Start by updating your system and installing packages required for compiling
dlib
and Python libraries:sudo dnf update -y sudo dnf groupinstall "Development Tools" -y sudo dnf install cmake epel-release python3 python3-devel -y
-
Install Boost Libraries
dlib
depends on Boost libraries, so install them:
sudo dnf install boost boost-devel -y
-
Install Additional Dependencies
Install other dependencies, like X11 and OpenBLAS, which are often required for
dlib
:sudo dnf install openblas-devel libX11-devel -y
-
Install
dlib
with pipWith dependencies installed, use
pip
to installdlib
. It's recommended to create a virtual environment first to manage dependencies effectively:python3 -m venv dlib_env source dlib_env/bin/activate pip install --upgrade pip pip install dlib
-
Verify the Installation
After installation, verify if
dlib
is correctly installed by running a simple Python script:python3 -c "import dlib; print(dlib.__version__)"
-
Alternatively Install
dlib
Using ComposerAfter setting up dependencies, use Composer to install
dlib
:composer require dlib/dlib
B. Installing imagick
(ImageMagick for PHP)
ImageMagick provides advanced image manipulation capabilities.
-
Install ImageMagick Libraries
sudo dnf install ImageMagick ImageMagick-devel -y
- Install the PHP
imagick
Extension via PECLsudo pecl install imagick echo "extension=imagick.so" > /usr/local/php/php.ini
- Verify Installation
php -m | grep imagick
C. Installing redis
(In-Memory Database)
Redis is commonly used for caching and session management.
-
Install Redis Server
sudo dnf install redis -y
-
Enable Redis PHP Extension
Enable Redis in CustomBuild: