Installing and Managing PHP Extensions in DirectAdmin: A Detailed Guide Print

  • 1

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:

  1. Viewing pre-installed PHP extensions on DirectAdmin VPS.
  2. Installing additional PHP extensions using CustomBuild.
  3. Installing complex libraries with dependencies.
  4. 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

  1. 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
  2. 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:

  1. Navigate to CustomBuild Directory

    cd /usr/local/directadmin/custombuild
    
  2. Update CustomBuild

    Ensure you’re working with the latest version:

    ./build update
    
  3. Set the PHP Extension for Installation

    To prepare imap for installation:

    ./build set_php "imap" yes
    
  4. 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:

  1. Set the Extension for Installation:

    ./build set_php "<extension_name>" yes
    
  2. Install the Extension:
    ./build php_<extension_name>
    ​

Common Additional PHP Extensions

  1. Database Extensions

    • pdo_pgsql - PostgreSQL driver for PDO.
    • pgsql - PostgreSQL database functions.
    • mongodb - MongoDB driver (usually installed via PECL).
    • sqlite3 - SQLite database access.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Security Extensions

    • suhosin - Hardened PHP security extension.
    • snuffleupagus - PHP security module for runtime security.
  7. 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.
  8. File and Data Compression Extensions

    • bz2 - Bzip2 compression.
    • zlib - Data compression.
    • zip - ZIP file creation and extraction.
  9. 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:

  1. Set the Extension for Installation:

    ./build set_php "ldap" yes
    
  2. 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.

  1. 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
    
  2. Install Boost Libraries

    dlib depends on Boost libraries, so install them:


    sudo dnf install boost boost-devel -y
    ​
  3. Install Additional Dependencies

    Install other dependencies, like X11 and OpenBLAS, which are often required for dlib:

    sudo dnf install openblas-devel libX11-devel -y
    
  4. Install dlib with pip

    With dependencies installed, use pip to install dlib. 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
    
  5. Verify the Installation

    After installation, verify if dlib is correctly installed by running a simple Python script:

    python3 -c "import dlib; print(dlib.__version__)"
    
  6. Alternatively Install dlib Using Composer

    After setting up dependencies, use Composer to install dlib:

    composer require dlib/dlib
    

B. Installing imagick (ImageMagick for PHP)

ImageMagick provides advanced image manipulation capabilities.

  1. Install ImageMagick Libraries

    sudo dnf install ImageMagick ImageMagick-devel -y
    
  2. Install the PHP imagick Extension via PECL
    sudo pecl install imagick
    echo "extension=imagick.so" > /usr/local/php/php.ini
    ​
  3. Verify Installation
    php -m | grep imagick
    ​

C. Installing redis (In-Memory Database)

Redis is commonly used for caching and session management.

  1. Install Redis Server

    sudo dnf install redis -y
    
  2. Enable Redis PHP Extension

    Enable Redis in CustomBuild:

    cd /usr/local/directadmin/custombuild
    ./build set_php "redis" yes
    ./build php_redis
    

    Start and Enable Redis Service

    sudo systemctl start redis
    sudo systemctl enable redis
    

    D. Installing mongodb (NoSQL Database Driver)

    MongoDB is a popular NoSQL database, and its PHP extension is installed via PECL.

    1. Install MongoDB PHP Extension

      sudo pecl install mongodb
      echo "extension=mongodb.so" > /usr/local/php/php.ini
      
    2. Verify Installation
      php -m | grep mongodb
      ​

    E. Installing gmp (GNU Multiple Precision Arithmetic Library)

    GMP supports large number calculations often required in cryptographic applications.

    1. Install GMP Libraries

      sudo dnf install gmp gmp-devel -y
      
    2. Enable GMP Extension in PHP

      cd /usr/local/directadmin/custombuild
      ./build set_php "gmp" yes
      ./build php_gmp
      
    3. Verify Installation
      php -m | grep gmp
      ​

    5. Installing PHP Libraries Using Composer

    Composer is essential for managing additional PHP libraries, especially those not available as extensions.

    Step 1: Install Composer

    If Composer is not already installed, install it with:

    curl -sS https://getcomposer.org/installer | php
    sudo mv composer.phar /usr/local/bin/composer
    

    Step 2: Install PHP Libraries with Composer

    Once Composer is set up, you can install any PHP library. For instance, to install monolog:

    composer require monolog/monolog
    

    Composer automatically handles dependencies and ensures compatibility.

    6. Configuring and Verifying Installations

    After installing extensions and libraries, verify their status.

    1. List Installed PHP Extensions

      php -m
      
    2. List Composer Packages

      Navigate to your project root and run:

      composer show
      

    7. Performance and Security Considerations

    1. Limit Active Extensions: Only enable necessary extensions to conserve server resources.
    2. Keep Libraries Updated: Regularly update both PHP extensions and Composer libraries to maintain security.
    3. Remove Unused Extensions: Periodically audit your extensions and disable any that are not actively used.

    8. Troubleshooting Common Issues

    1. Dependencies Not Found: If an extension fails due to missing dependencies, review the installation steps to ensure each dependency is installed.
    2. Composer Conflicts: Use composer diagnose to identify and resolve any dependency conflicts.
    3. Library Not Loading: Ensure the extension path is correctly configured in php.ini.

    Conclusion

    Managing PHP extensions and libraries on DirectAdmin is straightforward with CustomBuild and Composer. By following these detailed steps, you can ensure your PHP environment is tailored to support your application needs efficiently. For further assistance, refer to DomainIndia’s knowledge base or reach out to support.


Was this answer helpful?

« Back