Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk11 min

How to Install PHP Modules on a Linux VPS (Ubuntu, Debian, and DNF Systems)

Install PHP modules correctly on a Linux VPS by matching the package to your distribution, PHP version, and SAPI. Follow APT or DNF steps, restart Apache or PHP-FPM, verify the web runtime, and troubleshoot undefined functions.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install a PHP module with your VPS distribution’s package manager, then restart the PHP runtime that actually serves your application. On Debian or Ubuntu, that normally means sudo apt update followed by a package such as sudo apt install php-mysql php-curl. On a DNF-based distribution, search with dnf search php and install the matching package, such as php-mysqlnd or php-gd.

The important qualification is that PHP’s command-line interface, Apache module, CGI process, and PHP-FPM service can load different configuration files. A module that appears in php -m is not necessarily available to a web application. Identify the application’s SAPI, install a package compatible with its PHP version, restart that SAPI, and verify it from the same runtime.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a PHP module is and why installation can be confusing

A PHP module (also called an extension) adds functions, classes, protocol support, or performance features to the PHP runtime. Database drivers, image processing, cURL networking, and internationalization are common examples. Linux distributions usually ship these extensions as packages so that the package manager can resolve dependencies, place configuration files in the expected directories, and deliver security updates.

PHP is not a single process on a VPS. The CLI SAPI runs commands such as php artisan or a cron script. Apache may load PHP as an Apache module, while Nginx commonly passes requests to PHP-FPM. CGI is another possible SAPI. Each can have its own php.ini and conf.d directory. This is why installing an extension successfully but checking it only with the CLI can still leave a website reporting an undefined function.

“Most Unix (and Linux) operating systems have a packaged version of PHP and extensions available through their packaging system.” — PHP Documentation Group, Installation on Unix systems.

Check the VPS before changing anything

Identify the distribution and package manager

Log in over SSH with an account that can use sudo. Determine whether the server is Debian/Ubuntu based or uses DNF:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
cat /etc/os-release
command -v apt
action=$(command -v dnf); [ -n "$action" ] && echo "$action"

The first command prints the distribution and release. Debian and Ubuntu use APT. Fedora-family and other DNF-based systems use DNF. Do not run an APT command on a DNF system or assume that a package name from one family exists unchanged in the other.

Record the PHP version and current CLI configuration

php -v
php --ini
php -m

php -v gives the CLI version, php --ini shows the CLI’s loaded php.ini and additional scan directory, and php -m lists modules loaded by that CLI process. The CLI version is a useful reference, but it does not prove which version or configuration the web server uses.

Find the SAPI that serves the application

Check how the web stack is arranged. Apache may load PHP directly; Nginx normally forwards .php requests to FPM. Useful inspection commands include:

systemctl list-units --type=service | grep -Ei 'apache2|httpd|nginx|php.*fpm'
ps aux | grep -E '[p]hp-fpm|[a]pache2|[h]ttpd|[n]ginx'

If you manage a control panel or a multi-version PHP setup, use that panel’s documented PHP-FPM service and version rather than assuming the system default. Write down the exact PHP major and minor version before selecting a versioned package.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install modules on Debian or Ubuntu with APT

1. Refresh package metadata

sudo apt update

This downloads current package indexes. It does not upgrade PHP or install an extension by itself. If the command reports an unreachable repository, fix the repository or network error first; installing from stale metadata can select an unavailable or unsuitable package.

2. Search for the distribution package

apt search php-
apt-cache search php

Package names usually begin with php-, but the exact suffix and version relationship are distribution-specific. Search results show the package description and often the supported PHP series. Prefer the package from the enabled distribution repository that matches the PHP runtime used by the application.

3. Install the required extension

Install one or more packages in a single transaction. For example:

sudo apt install php-mysql php-curl

Common Debian/Ubuntu package names include:

Capability Typical package What to confirm
MySQL or MariaDB connectivity php-mysql That the package supports the PHP version selected for the site
cURL networking php-curl That the application needs the cURL extension, not only the command-line curl utility
PostgreSQL connectivity php-pgsql That the database driver matches the application’s PostgreSQL requirements
Command-line PHP php-cli That cron, deployment, or framework commands use the same PHP series
CGI support php-cgi That the server actually uses CGI rather than FPM
Apache PHP integration libapache2-mod-php That Apache is configured to load PHP as a module

Ubuntu’s Apache setup can be installed with:

sudo apt install php libapache2-mod-php

That command installs the base PHP package and Apache integration. Add application-specific packages such as php-cli, php-cgi, php-mysql, or php-pgsql when the application requires them. A package can install successfully while targeting a different PHP version than the one your virtual host uses, so inspect the installed files and runtime after installation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Enable or disable an extension explicitly when necessary

Most Debian-family extension packages create an ini fragment and enable it automatically. If a package is installed but its module is not enabled for a particular SAPI, use Debian’s helpers:

sudo phpenmod extension_name
sudo phpdismod extension_name

Replace extension_name with the module identifier, not the full package name. These commands operate on the Debian configuration tree and can be directed at a PHP version or SAPI when those options are available on the installed system. Check the command’s local help before changing a non-default version.

5. Restart the serving runtime

A running PHP process does not normally reread extension files after installation. Restart the process that handles requests:

sudo systemctl restart apache2

Use that command when Apache loads PHP directly. For PHP-FPM, find the exact service name first and restart that service, for example the versioned FPM unit shown by systemctl list-units:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
systemctl list-units --type=service | grep -Ei 'php.*fpm'
sudo systemctl restart <the-exact-php-fpm-service>

The angle-bracket text is a placeholder for the unit name displayed on your VPS; do not type the brackets literally. If Nginx is only the front end and FPM runs PHP, restarting Nginx alone will not load a newly installed PHP extension.

6. Verify the CLI and the web SAPI separately

Start with the CLI:

php -m | grep -i module_name
php --ri module_name

Replace module_name with the extension’s runtime name. For example, a package named php-mysql exposes MySQL-related modules; the package name and the name shown by php -m are not always identical.

Then test the web SAPI. Create a temporary file in the site’s document root containing:

<?php
phpinfo();

Open it only from a restricted connection, confirm the PHP version, “Loaded Configuration File,” “Scan this dir for additional .ini files,” and the module section, then delete the file immediately:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
rm /path/to/document-root/phpinfo.php

A safer application-level check is preferable for production. For a function-based extension, call the expected function behind an administrator-only diagnostic route and remove that route after testing. Never leave a public phpinfo() page on an Internet-facing VPS because it discloses paths, versions, and configuration details.

Install modules on DNF-based systems

1. Search the enabled repositories

sudo dnf search php

Search results can include several PHP versions, development packages, and similarly named libraries. Select the package that belongs to the PHP stream or repository used by your application. Do not mix packages from incompatible streams merely because their names look similar.

2. Install the matching package

sudo dnf install php-mysqlnd php-gd

php-mysqlnd provides the native MySQL driver package used by many DNF distributions, while php-gd supplies common image functions. Package names and available streams vary by release, so treat these as examples and confirm with dnf search before installing.

DNF resolves dependent libraries and places global PHP configuration in locations such as /etc/php.ini and module fragments under /etc/php.d/*.ini. Inspect the installed package if you need to know the exact fragment name:

rpm -ql php-gd | grep -E 'php.ini|php.d|.so$'

3. Restart Apache or PHP-FPM

For an Apache service managed as httpd:

sudo systemctl restart httpd

For PHP-FPM, identify and restart the FPM unit used by the virtual host. Nginx workers do not load PHP modules themselves; FPM does. If the service fails to restart, inspect its status and journal before retrying:

systemctl list-units --type=service | grep -Ei 'php.*fpm'
sudo systemctl status <the-exact-php-fpm-service>
sudo journalctl -u <the-exact-php-fpm-service> -n 100 --no-pager

4. Verify the loaded module

php -m | grep -i module_name
php --ini

As with APT, CLI output is only one SAPI. Confirm the web process with an application check or a short-lived, access-controlled phpinfo() page, then remove the diagnostic file.

Know which php.ini file your VPS uses

There is no universal answer to “which php.ini does PHP use?” The answer depends on the SAPI, PHP version, distribution, and service configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Environment Typical configuration layout How to verify
Debian/Ubuntu CLI /etc/php/M.N/cli/php.ini plus /etc/php/M.N/cli/conf.d/ php --ini
Debian/Ubuntu Apache /etc/php/M.N/apache2/php.ini plus the Apache conf.d directory Apache-side phpinfo() or an application check
Debian/Ubuntu FPM /etc/php/M.N/fpm/php.ini plus the FPM conf.d directory FPM-side phpinfo() or an application check
DNF-based systems Usually /etc/php.ini and fragments such as /etc/php.d/*.ini php --ini for CLI and a web-SAPI check for the site

Here M.N means the installed major and minor PHP version, such as the directory shown by your own system; it is not a command to copy verbatim. Debian-family systems keep version- and SAPI-specific trees, so editing the CLI file will not fix an FPM request if FPM reads a different tree.

When a package supplies its own ini fragment, prefer that managed fragment over copying directives into several php.ini files. Duplicate extension= lines can produce startup warnings or make it unclear which setting wins.

Why “undefined function” remains after installation

An undefined-function error means the process handling the request does not have the extension loaded; it does not necessarily mean the package installation failed. Work through these checks in order:

  1. Confirm the function belongs to the extension you installed. Check the application’s requirement and the package description. Similar package names can provide different APIs.
  2. Compare PHP versions. Run php -v and compare it with the version shown by the web SAPI. A package for one PHP series will not automatically load into another.
  3. Inspect the correct ini tree. Use php --ini for CLI and phpinfo() or an application diagnostic for Apache, CGI, or FPM. Look at both the loaded file and the additional scan directory.
  4. Check the module list in that SAPI. Search for the runtime module name, not just the APT or DNF package name.
  5. Restart the actual serving process. Restart Apache, httpd, or the exact PHP-FPM service. Reloading an unrelated Nginx process does not reload FPM’s PHP modules.
  6. Read service logs. A startup warning such as “Unable to load dynamic library” usually indicates a missing shared library, wrong architecture, wrong PHP ABI, or an incorrect extension path.
  7. Check file permissions and confinement. The FPM or web-server account must be able to read the extension and its dependent libraries. Mandatory access controls can also block loading; use the distribution’s audit logs rather than disabling security controls blindly.

If the CLI sees the module but the website does not, the most likely causes are different SAPIs, different PHP versions, or a missing restart. If neither SAPI sees it, verify that the package is installed and that its ini fragment exists in the expected scan directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use PECL or phpize only when a repository package is unsuitable

Distribution packages are the default because they receive coordinated dependency and security updates. Use PECL or a source build when no suitable package exists for the required extension or when the packaged version cannot satisfy a documented application requirement. A source build increases maintenance responsibility: you must track compatibility, rebuild after PHP upgrades, and monitor security fixes yourself.

PECL considerations

PECL installs extensions from the PHP ecosystem, but the command and its build dependencies must match the active PHP development environment. Confirm the extension’s supported PHP versions and the repository used by your distribution before compiling. After installation, add the resulting shared object to the ini tree used by the target SAPI and restart that service.

The phpize source-build workflow

The standard workflow is:

phpize
./configure
make
sudo make install

phpize prepares a source tree for the installed PHP development headers. ./configure checks libraries and build options, make compiles the extension, and make install copies the shared object into PHP’s extension directory. A successful compilation does not enable the module automatically.

Add an ini directive to the correct SAPI configuration:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
extension=extname.so

Use the actual file name produced by the build. Place the directive in the target version/SAPI’s managed additional-ini directory when possible, rather than editing an unrelated CLI file. Then verify the file path and restart Apache, httpd, or PHP-FPM. If loading fails, inspect the service log for unresolved libraries and ABI mismatches before rebuilding.

Choose the right installation method

Approach Distribution support Version and SAPI control Dependencies and updates Restart needed
APT package Debian and Ubuntu repositories Usually follows the enabled PHP series; verify CLI versus web SAPI Managed by APT with distribution security updates Yes, restart the serving runtime
DNF package DNF-based distributions and their enabled streams Choose a compatible stream and verify the target SAPI Managed by DNF with repository updates Yes, restart Apache, httpd, or FPM
PECL Independent of the normal distribution package name Requires careful PHP-version and ABI matching Build and update responsibility is greater than with distribution packages Yes, after enabling the extension
phpize/source build Works where build tools and source are available Most control, but also the greatest compatibility risk You manage compiler dependencies, rebuilds, and security maintenance Yes, after adding the ini directive

Use the first two rows whenever they provide the required extension. Reserve PECL and source compilation for a genuine packaging gap, document the build options, and record the PHP version and SAPI for which the module was compiled.

Operational checklist after installation

  • Record the distribution, PHP version, SAPI, package name, and installation date in your server documentation.
  • Keep APT or DNF repositories enabled so extension security updates arrive with normal system maintenance.
  • Test both a representative web request and any CLI, queue-worker, or cron command that uses PHP.
  • Restart only the affected service when practical, and check its status immediately afterward.
  • Remove temporary diagnostic scripts such as phpinfo.php.
  • After a PHP major or minor upgrade, recheck every extension; versioned configuration directories and compiled modules may not carry forward.

Quick command reference

Task Debian/Ubuntu DNF-based system
Refresh/search sudo apt update
apt search php-
sudo dnf search php
Install examples sudo apt install php-mysql php-curl sudo dnf install php-mysqlnd php-gd
Inspect CLI modules php -m and php --ini
Restart Apache sudo systemctl restart apache2 sudo systemctl restart httpd
Enable/disable Debian module sudo phpenmod extension_name
sudo phpdismod extension_name
Use the package’s ini fragment or distribution documentation

The reliable pattern is consistent: identify the distribution and SAPI, install a repository package that matches the running PHP version, restart the process that serves the application, and verify from that same SAPI. Only move to PECL or phpize when the normal package path cannot provide a suitable module.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.