If you try to install the Sodium PHP Extension via WHM, it initially may ignore your request. Before it will allow you to install the PHP Extension, you will have to install the Sodium Cryptographic Library (libsodium) first.
Overview of Steps
The overall process of installing Sodium is a two-step process.
- Install the base libsodium library via your server's package manager, such as yum, dnf, or apt.
- Use one of the procedures below corresponding to your server configuration.
You will need the following for this process:
- Root access to WHM.
- Including access to the command line (via the Terminal in WHM or via SSH).
- A server running PHP 7.4 or higher.*
*If you are using PHP version 7.4 or higher (ea-php74), you can do everything from within WHM, although step 1 can be done via SSH if you desire.
If you are a web hosting customer or an employee that does not have root access, you will need to contact the support department of your web hosting company, or the administrator of your server. This cannot be installed by a user that only has cPanel access.
Step 1: Installing the Base Sodium Library (libsodium)
This step can be completed within WHM or via SSH. Since step 2 requires you to log into WHM and we are lazy efficient, our instructions will show you the way to do it in WHM.
- Log into WHM as the root user.
- Navigate to Home > Server Configuration > Terminal
- Search for "terminal" or "command" in WHM (or click on "Server Configuration" in the left menu to expand your choices).
- Click on "Terminal" in the left menu.
- Use the instructions below corresponding to your operating system.
Next, from this command line, you will need to install the Sodium Cryptographic Library (libsodium) and its development package (libsodium-devel). This process uses YUM, DNF, or APT, depending on your server's operating system (OS).
CentOS 7 & CloudLinux 7
You will need to install both the EPEL repository and the sodium libraries. CentOS 7 and CloudLinux 7 use YUM.
yum install epel-release
yum install libsodium libsodium-devel
Note: you must complete these commands in this order and together.
lmaLinux 8 & CloudLinux 8
AlmaLinux 8 and CloudLinux 8 use DNF to install the sodium libraries.
dnf install libsodium libsodium-devel
Ubuntu 20.4 LTS
Ubunto 20 uses APT to install the sodium libraries.
apt install libsodium-dev libsodium23
Step 2: Install the Sodium PHP Extension
For PHP 7.4 (ea-php74) and newer, you can install the Sodium PHP Extension via EasyApache in WHM.
The numbering starts at #4 because Step 1 above is required and you have to complete #1 through #3 first.
- Log into WHM as the root user (if not already logged in).
- Unless you used SSH for step 1, you should already be logged in.
- Navigate to Home > Software > EasyApache 4
- Search for "apache" (or click on "Software" in the left menu to expand your choices).
- Click on "EasyApache 4" in the left menu.
This will load your server profiles. To keep your current configuration and add Sodium to it, you will Customize your current profile.
You also have the option of creating a new profile or using one that already has the configuration you need, including Sodium. That is not covered in this article, but it is worth mentioning that you have other options.
Continue with the installation:
- Click on the blue "Customize" button where it says "Currently Installed Packages."
- Click on "PHP Extensions" in the sidebar.
- Search for "sodium" or scroll through the list until you find it.
- Click on the toggle switch for the PHP versions(s) of Sodium that you want.
- For example,
php81-php-sodium is for PHP 8.1.
- The toggle switch should say "Install" next to it if set correctly.
- Click on "Review" in the sidebar.
- The review page should show you the package(s) you are about to install.
- It may also show you packages that are being updated.
- See the troubleshooting section below if you don't see it here.
- Click on the blue "Provision" button.
If successful, it should show that the package has been installed.
The Sodium PHP Extension Does Not Appear on Provisioning Screen
This is probably why you are here in the first place.
If you tried to install the Sodium extension and you get to the Review screen and it simply is not there anymore, then something went wrong with Step 1 above, or you did not complete step 1.
Installing Sodium for Multiple PHP Versions
If you have problems when trying to install Sodium for more than one PHP Version, try installing them one at a time. You can install more than one version on the server, but you are less likely to get errors during the installation process if you install them one at a time.
In theory, there should be no problems with installing multiple packages at a time, but if you run into difficulties, installing each one at a time sometimes works.
I Don't Have Access to WHM
The Sodium PHP Extension needs to be installed by the root user of the server. If you have a script or app that needs this extension, you will need to contact the administrator of the server. If you are a web hosting customer with only cPanel access, you would typically contact the support department of your web host.
Older Version of PHP
Older versions of PHP are deprecated and you should avoid using them. See the references tab for information about the current PHP versions.
For AlmaLinux, CloudLinux 8, and Ubuntu, PHP version 7.3 (ea-php73) or earlier is not supported.
CentOS 7 and CloudLinux 7 can run earlier versions of PHP, but it is not recommended.
There are ways to install it in earlier versions in CentOS 7 and CloudLinux 7, and they all involve the command line. See the references tab for possible solutions. But keep in mind that if you use an older version, it will probably be phased out in cPanel and you will eventually be forced to update.