How to Install PHP Intl Extension: 4 Easy Steps
PHP is one of the most widely-used server-side scripting languages for web development. It powers millions of websites worldwide due to its simplicity and flexibility. However, when developing multilingual websites or applications that need...

7 min read
PHP is one of the most widely-used server-side scripting languages for web development. It powers millions of websites worldwide due to its simplicity and flexibility. However, when developing multilingual websites or applications that need...
- Why Do You Need PHP Sodium?
- How to Install PHP Sodium Extension on Ubuntu
- How to Install PHP Sodium Extension on CentOS
The PHP Sodium extension is a modern cryptography library designed to make encryption easier and more secure. If youâre developing applications that require cryptographic operations, learning how to install PHP Sodium extension is essential. In this guide, we will walk you through the steps to install the PHP Sodium extension on Ubuntu, CentOS, and other Linux distributions. Letâs dive in!
Why Do You Need PHP Sodium?
PHP Sodium provides advanced cryptographic features such as encryption, decryption, password hashing, and more. It is a highly reliable and efficient library integrated into PHP since version 7.2. By ensuring that the PHP Sodium extension is installed, you can secure your applications while leveraging its extensive cryptographic capabilities.
This extension simplifies the implementation of cryptographic functions, reducing the risk of errors that can compromise security. Moreover, its seamless integration into PHP means developers can access state-of-the-art encryption tools with minimal configuration.
How to Install PHP Sodium Extension on Ubuntu
Ubuntu is one of the most popular Linux distributions, and installing the PHP Sodium extension here is straightforward. Follow these steps to get started:
Step 1: Update Your Package List
Open your terminal and update the package list to ensure youâre downloading the latest versions of the required packages:
sudo apt update
This step ensures your system has access to the most up-to-date software repositories, minimizing compatibility issues.
Step 2: Install PHP and Required Extensions
Ensure you have PHP installed. If not, install it along with the necessary dependencies:
sudo apt install php php-cli php-dev -y
These packages include the core PHP interpreter, command-line tools, and development libraries needed for extension compilation.
Step 3: Install the Sodium Extension
For PHP 7.2 and above, the Sodium extension is bundled and enabled by default. However, if it is missing, you can manually install it:
sudo apt install php-sodium -y
This command retrieves the Sodium extension from the official Ubuntu repositories and integrates it with your PHP installation.
Step 4: Verify the Installation
After installation, confirm that the Sodium extension is enabled:
php -m | grep sodium
If the output shows âsodium,â the installation was successful. This step ensures your PHP environment is correctly configured.
How to Install PHP Sodium Extension on CentOS
CentOS is widely used in server environments. Follow these steps to install the PHP Sodium extension:
Step 1: Update the System
Update your system to ensure compatibility:
sudo yum update -y
Keeping your system updated reduces potential issues caused by outdated dependencies.
Step 2: Install PHP and Developer Tools
Install PHP and development tools required for building extensions:
sudo yum install php php-cli php-devel gcc make -y
These tools allow you to compile and install custom PHP extensions if needed.
Step 3: Install Sodium Library
Install the libsodium library, which is required for the PHP Sodium extension:
sudo yum install libsodium libsodium-devel -y
This step ensures that the underlying cryptographic library is available for PHP to interface with.
Step 4: Install the Sodium Extension
For CentOS, you may need to use pecl to install the extension:
sudo pecl install libsodium
The pecl command downloads and compiles the Sodium extension, ensuring compatibility with your PHP version.
Step 5: Enable the Extension
Add the following line to your PHP configuration file (usually php.ini):
extension=sodium.so
This line tells PHP to load the Sodium extension during startup.
Step 6: Verify the Installation
Restart your web server and confirm the installation:
php -m | grep sodium
If âsodiumâ appears in the output, the installation is complete. Restarting ensures all changes take effect.
Installing PHP Sodium on Other Linux Variants
For other Linux distributions such as Fedora, Debian, or Arch Linux, the steps are similar. Here is a general guide:
Step 1: Update Your System
Always begin by updating your system:
sudo dnf update # Fedora sudo apt update # Debian sudo pacman -Syu # Arch Linux
This step ensures youâre working with the latest package versions and dependencies.
Step 2: Install PHP and Dependencies
Ensure PHP and the required development libraries are installed. For example:
sudo dnf install php php-cli php-devel -y # Fedora sudo apt install php php-cli php-dev -y # Debian sudo pacman -S php php-cli php-dev # Arch Linux
These commands install the PHP interpreter and necessary tools for building extensions.
Step 3: Install the Sodium Extension
On most distributions, the Sodium extension can be installed via the default package manager or pecl:
sudo pecl install libsodium
The pecl utility is a versatile tool for adding PHP extensions that may not be included in standard repositories.
Step 4: Enable and Verify the Extension
Add extension=sodium.so to your php.ini file and verify the installation using:
php -m | grep sodium
Verifying ensures the extension is active and properly integrated with your PHP setup.
Common Issues and Troubleshooting
- PHP Version Compatibility: Ensure your PHP version is 7.2 or higher. If not, consider upgrading your PHP installation. Older versions of PHP do not include native support for Sodium.
- Missing Development Tools: If you encounter errors during installation, ensure development tools like
gccandmakeare installed. These tools are critical for compiling extensions from source. - Extension Not Found: Double-check your PHP configuration files and restart the web server after enabling the extension. Sometimes, misconfigurations or typos in
php.inican prevent extensions from loading. - Library Conflicts: Ensure there are no conflicting versions of the
libsodiumlibrary on your system. Use your package manager to check for duplicate installations.
You may also like:
Learn PHP
Conclusion
Installing the PHP Sodium extension on Linux distributions like Ubuntu, CentOS, and others is a straightforward process. By following this guide on how to install PHP Sodium extension, you can enable powerful cryptographic capabilities in your PHP applications. Whether youâre enhancing data encryption or implementing secure password hashing, Sodium is a tool you can trust.
Take the time to verify your installation and troubleshoot any issues to ensure your PHP environment is secure and optimized. With the PHP Sodium extension, youâre equipped to build applications that meet modern security standards. Start today and give your projects the robust protection they deserve!
Website Vidya Team
Technology educator and researcher at Website Vidya.
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides











Discussion
0No comments on this guide yet. Be the first to share your thoughts or ask a question!