As a developer, managing PHP modules on your Ubuntu system can be an essential part of your workflow. Modules are packages that extend the functionality of PHP, and they are a key aspect of creating dynamic and powerful web applications. This article provides a comprehensive guide on enabling and disabling PHP modules in Ubuntu, streamlining your experience and optimizing your development environment.
All the installed PHP modules configuration files are available under /etc/php/{php_version}/mods-available directory. You can see the number of files with extension .ini. You must have installed specific PHP modules, you need to enable before using this tutorial. The php-common package provides followings commands to manage PHP modules.
- phpenmod – Used to enable modules in PHP
- phpdismod – Used to disable modules in PHP
- phpquery – Used to view status of modules of PHP
There are 3 types of SAPI (Server API) available – CLI, FPM, and Apache2 being the most commonly used. You can define SAPI using -s
switch to enable/disable module for that only.
Enabling PHP Modules
Use phpenmod command followed by module name to enable specific PHP module on your system. In the below example, the first command is an example and the second command will enable mbstring module for all installed PHP versions and all SAPI.
### Syntax phpenmod MODULE_NAME
### Enable mbstring php module phpenmod mbstring
You can also define the PHP version using -v
switch to enable specific modules. Using this you will enable the module for all SAPI.
### Syntax phpenmod -v <PHP VERSION> <MODULE NAME>
### Enable module for specific php version phpenmod -v 8.2 mbstring
phpenmod -v 7.4 mbstring
Use -s
switch to define the SAPI to enable specific modules for specific SAPI for all PHP versions.
### Syntax phpenmod -s <SAPI> <MODULE NAME>
### Enable module for specific SAPI phpenmod -s cli mbstring
phpenmod -s fpm mbstring
phpenmod -s apache2 mbstring
You can also define both the PHP version and SAPI for a more specific update.
Disabling PHP Modules
You can also disable any un-necessary PHP modules from your system using phpdismod command. For example, disable mbstring module for ALL PHP versions and all SAPI.
phpdismod mbstring
To disable any module for a specific PHP version use the command below.
phpdismod -v 8.2 mbstring
To disable any module for specific SAPI on all PHP versions, use the command below.
phpdismod -s apache2 mbstring
Restarting the Web Server
Once you have enabled or disabled a PHP module, you need to restart your web server for the changes to take effect. Depending on your web server, you can use the following commands:
For Apache:
sudo systemctl restart apache2
For Nginx with PHP-FPM:
sudo systemctl restart php8.x-fpm
sudo systemctl restart nginx
Replace 8.x with your PHP version (e.g., php8.2-fpm).
Verify PHP Module Status
After restarting the web server, you can verify if a PHP module is enabled or disabled by running the following command:
php -m | grep <module-name>
If the command returns the module name, it is enabled. Otherwise, the module is disabled.
Conclusion
Managing PHP modules on your Ubuntu system is a crucial part of optimizing your development environment. By following this guide, you can now easily enable and disable PHP modules on your Ubuntu system. Remember to restart your web server after making changes to ensure the new settings take effect. With this knowledge in hand, you’re now ready to enhance your PHP development experience on Ubuntu.
4 Comments
Missing phpquery example here, could you please fill it
Thanks mate.
Great pal!
Thanks for writing useful article… Finally I found an article to understand about php module management…