- Saved searches
- Use saved searches to filter your results more quickly
- License
- legale/phpenmod
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- How to enable/disable PHP extension for PHP CLI if there is no loaded configuration file?
- 2 Answers 2
- Is there any command to enable/disable a php extension from command line?
- How to Enable or Disable PHP Modules on Ubuntu
- Enabling PHP Modules
- Disabling PHP Modules
- Restarting the Web Server
- Verify PHP Module Status
- Conclusion
- ubuntu enable specific php extension
- 1 Answer 1
- You must log in to answer this question.
- Related
- Hot Network Questions
- Subscribe to RSS
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Simple PHP extension enabler/disabler
License
legale/phpenmod
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Simple PHP extension enabler/disabler
Just compiled and installed php-src on Arch Linux
git clone https://github.com/php/php-src cd php-src ./buildconf ./configure \ --disable-all \ --with-config-file-scan-dir=/etc/php/php.d \ --with-config-file-path=/etc/php/php.ini \ --enable-ctype \ make -j4 && sudo make install
cd ~/src/php-src/ext/readline phpize && ./configure && make -j4 && sudo make install cd ~/src/php-src/ext/mbstring phpize && ./configure && make -j4 && sudo make install
wget https://github.com/legale/phpenmod/raw/master/phpenmod -O ~/bin/phpenmod chmod +x ~/bin/phpenmod ln -s /home/ru/bin/phpenmod /home/ru/bin/phpdismod
Trying to enable installed extensions
[ru@ru-manjaro php.d]$ phpenmod readline mbstring
phpenmod: Ini file not found. Trying to create new. phpenmod: Done. phpenmod: Ini file not found. Trying to create new. phpenmod: Done.
10-readline.ini 20-mbstring.ini
Trying to disable mbstring
phpdismod mbstring cat 20-mbstring.ini
phpdismod: Trying to disable PHP extension mbstring. phpdismod: Done. ;extension=mbstring
Listing enabled PHP extensions
[PHP Modules] Core ctype date hash pcre readline Reflection SPL standard [Zend Modules]
About
Simple PHP extension enabler/disabler
How to enable/disable PHP extension for PHP CLI if there is no loaded configuration file?
I just executed php -i | grep «Loaded Configuration File» to find out where the configuration file of my PHP CLI is stored, but I get: Loaded Configuration File => (none) . So it loads the default settings as a fallback. How can I enable the openssl extension for PHP CLI if no configuration file is loaded? Currently I get OpenSSL support => disabled (install ext/openssl) when calling php -i | grep -i «openssl»
php -i also shows the location where it expects the configuration file to be, run php -i |grep -i configuration .
Thank you. I get Configuration File (php.ini) Path => /usr/local/lib64 but there is no php.ini file there. Can I just copy the php.ini from the «normal» php into it and restart the webserver?
That’s an extremely strange path to search for a configuration file, but copying it there should work. You don’t need to restart the webserver if you use the CLI, the configuration file is read every time it is started from the command line.
2 Answers 2
php -i also shows the location where it expects the configuration file to be, just run php -i |grep -i configuration .
Example output from my Ubuntu host:
$ php -i |grep -i configuration Configuration File (php.ini) Path => /etc/php/7.2/cli Loaded Configuration File => /etc/php/7.2/cli/php.ini
Just copy a php.ini file there and adapt it to your needs (or just create a symlink).
You can get a list of all configuration files by passing the —ini flag to php:
$ php --ini Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.1 Loaded Configuration File: /opt/homebrew/etc/php/8.1/php.ini Scan for additional .ini files in: /opt/homebrew/etc/php/8.1/conf.d Additional .ini files parsed: /opt/homebrew/etc/php/8.1/conf.d/error_log.ini, /opt/homebrew/etc/php/8.1/conf.d/ext-opcache.ini, /opt/homebrew/etc/php/8.1/conf.d/ext-pcov.ini, /opt/homebrew/etc/php/8.1/conf.d/ext-redis.ini, /opt/homebrew/etc/php/8.1/conf.d/ext-xdebug.ini, /opt/homebrew/etc/php/8.1/conf.d/php-memory-limits.ini
Is there any command to enable/disable a php extension from command line?
If you are using PHP5.4+ on Debian based distro you can use php5enmod to enable and php5dismod to disable PHP extensions.
You can enable an extension from the command line using:
php -d extension=/path/to/extension.so
-d is used to pass ini values via the command line. Unfortunately there is no way to disable an extension on the command line if it has been configured in the php.ini file. (You can follow the other answers of course but there is nothing you can do using -d or whatever option of the php command.)
On Lubuntu I needed pdo_sqlite .
$ sudo php5enmod pdo_sqlite
The result list was missing pdo_sqlite.ini . We have to install it.
$ sudo apt-get install php5-sqlite
$ sudo apt-get install php7-sqlite3
Extension sqlite3 is auto-enabled in CLI and in Apache during installation process, and now we have mods-available : pdo_sqlite.ini , sqlite3.ini .
$ sudo php5dismod pdo_sqlite
You can also use straight phpenmod and phpdismod without version number. After this you may need to restart apache server
You have to use -n and then to append each needed extension using -dextension
php -n -dextension=json.so -dextension=phar.so composer.phar update
the order of the argument is not relevant. you can also do php -d extension=json.so -d extension=phar.so -n composer.phar update Or mix -d around -n. I tested this while I had to hack openssl.so back into pecl command via PHP_PEAR_PHP_BIN.
You can specify -n to avoid any extensions loading from php.ini . This can improve some performance when you’re using some (e.g. XDebug). E.g.
Any way to prevent loading an extension (like memcached) from loading, on a hosted server, although it is set up initially? I don’t control my host setup, just the scripts on it. I’m suspecting it is somehow messing up with my sessions and would like to make sure it is off since I don’t really use it..
usage: phpenmod [ -v ALL|php_version ] [ -s ALL|sapi_name ] module_name [ module_name_2 ]
So use phpenmod -s cli yourextension
This command is used in newer Debian versions, like Stretch, where PHP5/PHP7 can be run side-by-side.
sed -i.bkp 's/^extension=x.so/# extension=x.so/' /path/of/php.ini && /etc/init.d/httpd reload
-i.bkp take backup as php.php.bkp and write in to original file
&& if first command is success then reload httpd service.
but I just notice that sed giving exit status 0 when search patter not match so you can use
php_ini=/path/of/php.ini __module=x.so grep -q "^extension=$__module" $php_ini && < sed -i.bkp "s/^extension=$__module/# extension=$__module/" $php_ini && echo /etc/init.d/httpd reload; >|| echo "cannot make requested change"
Or you can use below script for the enable and disable :
#!/bin/bash php_ini=/path/of/php.ini __module="$2" [[ ! -f $php_ini ]] && < echo "Error: Can not found $php_ini" >&2; echo "Please define php.ini path in $php_ini"; exit 1; > [[ -z $__module ]] && < echo "Error: Please Type Module Name:" >&2; exit 1; > show_help() < cat To disable : $0 -id example: $0 -i xyz.so _EOF > do_enable() < grep -Eq "# extension=$__module$" $php_ini && < sed -i.bkp "s/^# extension\=$__module$/extension=$__module/" $php_ini && echo /etc/init.d/httpd reload; echo "Changes Successfully Done"; >|| echo "cannot make requested change" > do_disable() < grep -q "^extension=$__module" $php_ini && < sed -i.bkp "s/^extension=$__module/# extension=$__module/" $php_ini && echo /etc/init.d/httpd reload; echo "Changes Successfully Done"; >|| echo "cannot make requested change" > Main() < case $1 in -ie) do_enable ;; -id) do_disable ;; *) show_help ;; esac >Main $*
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.
ubuntu enable specific php extension
I have just upgraded to ubuntu 16.04. Now I have in /etc a folder for php5.6, one for 7.0 and one for 7.1 each with their mods-available subfolder. I have installed the php7.0-zip extension and I see it in the mods-available subfolder for php7.0. How to enable it? phpenmod will look in 5.6 version mods-available only.
and what does php7.0-cli -m say? (I can confuse commands a bit in favor of usual php-cli -m for php5, but it has to show modules you have currently loaded for your cli side)
1 Answer 1
Have you tried phpenmod -v 7.0 extension ?
Alternatively, you can create the symlink yourself (which is what phpenmod does internally):
ln -s /etc/php/7.0/mods-available/extension.ini /etc/php/7.0/apache2/conf.d/extension.ini
You must log in to answer this question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.26.43545
Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.