Skip to content

kodie/apache-module-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apache Module Manager

npm package version Travis build status npm package downloads code style license

asciicast

A CLI tool for enabling/disabling Apache modules.

Installation

$ npm install --global apache-module-manager

Note

This will modify your Apache config file. It is your responsibility to make a backup. This has only been tested on macOS with the default Apache installation. Use at your own risk.

Usage

list|l [-d -e -s <columns>] [search]

List/search for modules.

Options

Long Short Description
--disabled -d Only display disabled modules
--enabled -e Only display enabled modules
--sort -s A comma separated list of columns to sort by (defaults to enabled,name,path)

Examples

# Display all modules
$ amm list
$ amm l

# Display modules that contain 'php'
$ amm list php

# Display all modules and sort them by their line number
$ amm list --sort line

# Display all currently enabled modules
$ amm list -e
Example Output
$ amm list -s line

ID  NAME                       PATH                                                ENABLED LINE
0   authn_file_module          libexec/apache2/mod_authn_file.so                   true    71
1   authn_dbm_module           libexec/apache2/mod_authn_dbm.so                    false   72
2   authn_anon_module          libexec/apache2/mod_authn_anon.so                   false   73
3   authn_dbd_module           libexec/apache2/mod_authn_dbd.so                    false   74
4   authn_socache_module       libexec/apache2/mod_authn_socache.so                false   75
5   authn_core_module          libexec/apache2/mod_authn_core.so                   true    76
6   authz_host_module          libexec/apache2/mod_authz_host.so                   true    77
7   authz_groupfile_module     libexec/apache2/mod_authz_groupfile.so              true    78
8   authz_user_module          libexec/apache2/mod_authz_user.so                   true    79
9   authz_dbm_module           libexec/apache2/mod_authz_dbm.so                    false   80
...

enable|e <search>

Enable a module. If multiple modules match the search term, a select prompt will be displayed allowing you to choose from the matches. The sudo prefix is required since the script modifies a system file.

Examples

$ sudo amm enable php
$ sudo amm e php
Example Output
$ sudo amm enable php

? Which module are you looking for? (Use arrow keys)
  php7_module libexec/apache2/libphp7.so
❯ php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so
? Enable php5_module (/usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so)? (Y/n)
✔ Changed line 180 to LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so
? Restart Apache (/usr/sbin/apachectl restart)? (Y/n)

disable|d <search>

Disable a module. If multiple modules match the search term, a select prompt will be displayed allowing you to choose from the matches. The sudo prefix is required since the script modifies a system file.

Examples

$ sudo amm disable php
$ sudo amm d php
Example Output
$ sudo amm disable php

? Disable php5_module (/usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so)? (Y/n)
✔ Changed line 180 to #LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so
? Restart Apache (/usr/sbin/apachectl restart)? (Y/n)

switch <old/new search> [new search]

Disable a module and enable another one. If only one argument is given, the first argument will be used to search for both the module to disable and the module to enable. If multiple modules match a search term, a select prompt will be displayed allowing you to choose from the matches. The sudo prefix is required since the script modifies a system file.

Examples

$ sudo amm switch php5 php7
$ sudo amm s php
Example Output
$ sudo amm switch php

? Disable php5_module (/usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so)? (Y/n)
✔ Changed line 180 to #LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so
? Enable php7_module (libexec/apache2/libphp7.so)? (Y/n)
✔ Changed line 176 to LoadModule php7_module libexec/apache2/libphp7.so
? Restart Apache (/usr/sbin/apachectl restart)? (Y/n)

Config File

By default, AMM will check if the file ~/.amm.json exists and load config options from it.

Default Config

{
  "apache_config": "/etc/apache2/httpd.conf",
  "apache_restart": "/usr/sbin/apachectl restart"
}

Global Options

These options can be used with any of the above commands:

Long Short Description
--version -V Display current Apache Module Manager version
--apache-config -a Path to the Apache config file
--config -c Path to AMM config file
--help -h Display help information

Environment Variables

These environment variables can be used to change different config options:

Variable Description
AMM_CONFIG Path to an AMM config file
AMM_APACHE_CONFIG Path to the Apache config file

TODO/Ideas

  • Automated testing
  • Better Linux support/testing
  • Support for multiple Apache config files (file traversing?)
  • Allow for multiple modules to be enabled/disabled at the same time
  • Automated Apache config file backups
  • Implement module so that AMM can be used by other packages
  • Implement add and remove commands to add/remove LoadModule lines from config

Frequently Asked Questions

Doesn't a2enmod/a2dismod do the same thing?

Currently, yes. I built this before I knew that a2enmod/a2dismod could be installed on macOS. However, AMM has a nicer interface and I would like to extend the functionality of it in the near future.

Don't you mean httpd instead of Apache?

Yes, however plenty of people refer to it as Apache and you know what I'm talking about.

License

MIT. See the license.md file for more info.