- How to Enable or Disable PHP Modules on Ubuntu
- Enabling PHP Modules
- Disabling PHP Modules
- Restarting the Web Server
- Verify PHP Module Status
- Conclusion
- Установка PHP и модулей на Ubuntu/Debian
- Nginx, Php-Fpm и что это вообще?
- Почему timeout для curl в php необходим
- Угадайте самый медленный фреймворк. И это не Laravel
- Curl в PHP
- Сессии в PHP - часть первая для Чайников
- How to Enable or Disable PHP Modules on Ubuntu 20.04 | 18.04
- Prerequisites
- Managing PHP Modules
- Enable PHP Modules
- Enable module for specific php version
- Disable PHP Modules
- Conclusion
How to Enable or Disable PHP Modules on Ubuntu
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//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
### 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
### 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.
To disable any module for a specific PHP version use the command below.
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:
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:
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.
Установка PHP и модулей на Ubuntu/Debian
В Debian и Ubuntu есть несколько вариантов работы php: как модуль apache и как php-fpm. Первый вариант удобен тем, кому придется использовать не только сам PHP, но и возможности Apache, такие как .htaccess. Второй же вариат удобен например для Yii или Laravel.
Установка PHP 5 как модуля Apache:
apt-get update apt-get install libapache2-mod-php5 php5-cli php5-memcache php5-memcached php5-mysql php5-pgsql php5-curl php5-gd php5-imagick php5-intl php5-mcrypt
Установка PHP 7 как модуля Apache:
apt-get update apt-get install libapache2-mod-php7.0 php7.0-curl php7.0-cli php-memcache php-memcached php7.0-mysql php7.0-pgsql php7.0-gd php7.0-imagick php7.0-intl php7.0-mcrypt
Установка PHP 5 как PHP-FPM:
apt-get update apt-get install php5-fpm php5-cli php5-memcache php5-memcached php5-mysql php5-pgsql php5-curl php5-gd php5-imagick php5-intl php5-mcrypt
Установка PHP 7 как PHP-FPM
apt-get update apt-get install php7.0-fpm php7.0-curl php7.0-cli php-memcache php-memcached php7.0-mysql php7.0-pgsql php7.0-gd php7.0-imagick php7.0-intl php7.0-mcrypt
В Debian и Ubuntu зачастую установка модулей PHP не требует каких-то сложных манипуляций. Для того, чтобы посмотреть, что Вы можете поставить прямо сейчас, нужно сделать:
lynx@lnxdsk:~$ apt-cache search php7.0 php-amqp - AMQP extension for PHP php-apcu - APC User Cache for PHP php-all-dev - package depending on all supported PHP development packages php-gearman - PHP wrapper to libgearman php-geoip - GeoIP module for PHP php-gmagick - Provides a wrapper to the GraphicsMagick library php-gnupg - PHP wrapper around the gpgme library php-igbinary - igbinary PHP serializer php-imagick - Provides a wrapper to the ImageMagick library php-libsodium - PHP wrapper for the Sodium cryptographic library php-mailparse - Email message manipulation for PHP php-memcache - memcache extension module for PHP php-memcached - memcached extension module for PHP, uses libmemcached php-mongodb - MongoDB driver for PHP php-msgpack - PHP extension for interfacing with MessagePack php-oauth - OAuth 1.0 consumer and provider extension php-http - PECL HTTP module for PHP Extended HTTP Support php-pinba - Pinba module for PHP php-propro - propro module for PHP php-radius - radius client library for PHP php-raphf - raphf module for PHP php-redis - PHP extension for interfacing with Redis php-rrd - PHP bindings to rrd tool system php-smbclient - PHP wrapper for libsmbclient php-solr - PHP extension for communicating with Apache Solr server php-ssh2 - Bindings for the libssh2 library php-stomp - Streaming Text Oriented Messaging Protocol (STOMP) client module for PHP php-uploadprogress - file upload progress tracking extension for PHP php-uuid - PHP UUID extension php-yac - YAC (Yet Another Cache) for PHP php-yaml - YAML-1.1 parser and emitter for PHP php-zmq - ZeroMQ messaging bindings for PHP php7.0 - server-side, HTML-embedded scripting language (metapackage) php7.0-bcmath - Bcmath module for PHP php7.0-bz2 - bzip2 module for PHP php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary) php7.0-cli - command-line interpreter for the PHP scripting language php7.0-common - documentation, examples and common module for PHP php7.0-curl - CURL module for PHP php7.0-dba - DBA module for PHP php7.0-dev - Files for PHP7.0 module development php7.0-enchant - Enchant module for PHP php7.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php7.0-gd - GD module for PHP php7.0-gmp - GMP module for PHP php7.0-imap - IMAP module for PHP php7.0-interbase - Interbase module for PHP php7.0-intl - Internationalisation module for PHP php7.0-json - JSON module for PHP php7.0-ldap - LDAP module for PHP php7.0-mbstring - MBSTRING module for PHP php7.0-mcrypt - libmcrypt module for PHP php7.0-mysql - MySQL module for PHP php7.0-odbc - ODBC module for PHP php7.0-opcache - Zend OpCache module for PHP php7.0-pgsql - PostgreSQL module for PHP php7.0-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary) php7.0-pspell - pspell module for PHP php7.0-readline - readline module for PHP php7.0-recode - recode module for PHP php7.0-snmp - SNMP module for PHP php7.0-soap - SOAP module for PHP php7.0-sqlite3 - SQLite3 module for PHP php7.0-sybase - Sybase module for PHP php7.0-tidy - tidy module for PHP php7.0-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP php7.0-xmlrpc - XMLRPC-EPI module for PHP php7.0-xsl - XSL module for PHP (dummy) php7.0-zip - Zip module for PHP
Давайте для примера установим GD для работы с изображениями:
lynx@lnxdsk:~$ sudo apt-get install php7.0-gd Чтение списков пакетов… Готово Построение дерева зависимостей Чтение информации о состоянии… Готово Заметьте, вместо «php7.0-gd» выбирается «php-gd» НОВЫЕ пакеты, которые будут установлены: php-gd обновлено 0, установлено 1 новых пакетов, для удаления отмечено 0 пакетов, и 148 пакетов не обновлено. Необходимо скачать 350 kБ архивов. После данной операции, объём занятого дискового пространства возрастёт на 1 493 kB. Пол:1 http://mirror.mephi.ru/debian stretch/main amd64 php-gd amd64 2.5.0-1 [350 kB] Получено 350 kБ за 0с (2 266 kБ/c) Выбор ранее не выбранного пакета php-gd. (Чтение базы данных … на данный момент установлено 61175 файлов и каталогов.) Подготовка к распаковке …/php-gd_2.5.0-1_amd64.deb … Распаковывается php-xdebug (2.5.0-1) … Настраивается пакет php-xdebug (2.5.0-1) … После установки нам нужно перезапустить apache (эти примеры я показываю от пользователя root):
root@lnxdsk:~# service apache2 restart
Либо php-fpm, смотря, что используете Вы:
root@lnxdsk:~# service php7.0-fpm restart
Чтобы посмотреть список модулей php, который прямо сейчас подключен, можно запустить:
lynx@lnxdsk:~$ php -m [PHP Modules] bcmath bz2 calendar Core ctype curl date dba dom ereg exif fileinfo filter ftp gd gettext hash iconv intl json libxml mbstring mhash mysql mysqli openssl pcntl pcre PDO pdo_mysql pdo_pgsql pgsql Phar posix readline Reflection session shmop SimpleXML soap sockets SPL standard sysvmsg sysvsem sysvshm tokenizer wddx xdebug xml xmlreader xmlwriter Zend OPcache zip zlib [Zend Modules] Xdebug Zend OPcache
Nginx, Php-Fpm и что это вообще?
Что такое php-fpm и зачем он нужен более-менее посещаемым проектам? Какие неприятности несет в себе переход с apache на fpm? Какие проблемы решает реально, а какие - надуманно?
Почему timeout для curl в php необходим
Использование cURL в PHP имеет свою не очень приятную особенность - вечная блокировка процесса
Угадайте самый медленный фреймворк. И это не Laravel
Есть распространенное мнение, что Laravel почти самый медленный фреймворк, что даже его название нужно читать медленно и только одним пользователем на 1 ядро CPU. Но к счастью, это не так
Curl в PHP
Curl - это библиотека для работы с URL. Она интегрирована во множество языков, в том числе и в PHP.
Сессии в PHP - часть первая для Чайников
Вводная статья о том, как использовать сессии в PHP
How to Enable or Disable PHP Modules on Ubuntu 20.04 | 18.04
In this guide, we will be showing how you can enable or disable PHP modules on Ubuntu 20.04 LTS as well as other versions.
PHP modules are extensions that add features to the core PHP functions.
Prerequisites
In this guide, we will be making the assumption that you have already installed a supported PHP version such as PHP 7.4 or PHP 8.0 on your Ubuntu system. This short tutorial will show you how to install PHP modules on your system.
Managing PHP Modules
The php-common package provides the following commands to manage PHP modules as listed below:
- phpenmod: Used to enable modules in PHP
- phpdismod: Used to disable modules in PHP
- phpquery: Used to view status of modules of PHP
Modules can be enabled or disabled in PHP for a specific SAPI (Server API). The three common ones found on any Ubuntu system are CLI, FPM, and Apache2. You can use the -s switch to enable or disable modules in PHP for any of these.
Enable PHP Modules
To enable a specific module in PHP you need to use phpenmod command followed by module name using the following syntax.
Here is an example showing how to enable the curl module for ALL PHP versions and all SAPI.
phpenmod provides a -v switch to specify the PHP version that you intend to enable the module for with the following syntax.
$ phpenmod -v PHP_VERSION MODULE_NAME
This example shows how to enable the curl module for specific PHP versions.
Enable module for specific php version
$ phpenmod -v 7.3 curl $ phpenmod -v 7.4 curl
Moving further, this is the syntax if you need to specify the SAPI using the -s switch.
$ phpenmod -s SAPI MODULE_NAME
Now let’s enable curl for all the SAPIs individually.
$ phpenmod -s cli curl $ phpenmod -s fpm curl $ phpenmod -s apache2 curl
Disable PHP Modules
You can use phpdismod to disable any unused or unwanted PHP modules from your system. Here we will disable the curl module for all PHP versions and all SAPI.
The following command will disable the specific module for the specified version:
The following example will disable the module only for the specified SAPI
Conclusion
You should now be able to enable and disable PHP modules based on PHP version and SAPI to keep your system running optimally.
Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.