Skip to content

Commit

Permalink
Happy New Year!
Browse files Browse the repository at this point in the history
A lot of changes:
- 'add' switch removed, except from 'site'.
- passing a pathname to a2enmod's -search will look for that file and
add it as a LoadModule line to the block of such lines beneath the
comment section titled "Dynamic Shared Object (DSO) Support".
- Modules of any type can be found in the main conf file.
- Modules from any location can be added / replaced.
- changes to README.
- Many cups of kindness yet had.
  • Loading branch information
enderandpeter committed Jan 1, 2014
1 parent 690b986 commit ac4ebfe
Show file tree
Hide file tree
Showing 2 changed files with 395 additions and 281 deletions.
83 changes: 40 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# win-a2enmod
A PowerShell script for working with modules and sites on the [Apache Web Server][] for Windows. It was inspired by the a2enmod perl script for Debian written by [Stefan Fritsch][]. It employs some similar tactics as the original a2enmod, such as a single script referred to by different names by way of symbolic links, but it was written independently and specifically for PowerShell as a way to provide a powerful script ideal for the Windows environment that employs the Linux philosophy of tools that do one thing and do it well.
A PowerShell script for working with modules and sites on the [Apache Web Server][] for Windows. It was inspired by the a2enmod perl script for Debian written by [Stefan Fritsch][]. It employs some similar tactics as the original a2enmod, such as a single script referred to by different names by way of symbolic links. It was written independently with PowerShell as a way to provide a powerful script ideal for the Windows environment that employs the Linux philosophy of tools that do one thing and do it well.

[Apache Web Server]: http://httpd.apache.org/
[Stefan Fritsch]: http://www.sfritsch.de/

## Why not just use XAMPP to manage Apache on Windows?
[XAMPP][] is a wonderful tool for managing your web server, but they don't always support the latest versions of the software
they bundle. For example, XAMPP 1.8.1 only supported Apache 2.4.3 (instead of the most recent stable version at the time, 2.4.4,
which they *"recommend over all previous releases"*). They will upgrade these programs in newer versions, but not always to the
most recent. Many web admins prefer the latest stable versions and this script lets you use a simple command line program that
which they *"recommend over all previous releases"*). They will upgrade these programs in newer versions, but not always to the most recent. Many web admins prefer the latest stable versions and this script lets you use a simple command line program that
offers similar functionality as the Debian utility.

[XAMPP]: http://www.apachefriends.org/en/xampp-windows.html
Expand All @@ -20,57 +19,54 @@ To use the `a2enmod`, `a2dismod`, `a2ensite`, and `a2dissite` commands, make sur
* Navigate to the directory with a2enmod.ps1
* Run setup.bat from the command line to create the symbolic links
* Run Powershell as an Administrator
* Run the command `set-executionpolicy unrestricted -scope process -f` to allow the execution of PowerShell scripts just in the current session
* Run the command `Set-Executionpolicy Unrestricted -Scope Process -Force` to allow the execution of PowerShell scripts just in the current session
* Make sure httpd.exe is in your path
* Make sure your Windows user account has full access to the ServerRoot directory as assigned in the main Apache config file

You will find it easiest to add the directory containing the script and symbolic links to your path so that you can refer to the commands directly by name rather than always saying `.\a2enmod`, for example.
Be sure to add the directory containing the script and symbolic links to your user or system environment path variable so that you can refer to the commands from anywhere.

## Usage

__a2enmod [[-mod] \<String\>] [[-search] \<String\>] [-a[dd]] [-norestart]__
__a2enmod [[-m[od]] \<String\> [[-s[earch]] \<String\>] [-r[eplace]] [-c[opy]] [-n[orestart]]]__
* _mod_ - The module to enable or add
* _search_ - The location in which to look for the module file if not found in the default directory (ServerRoot\modules)
* _add_ - Force script to copy the module file from the search location to the default directory
* _search_ - The path to the module.
* _replace_ - Replace the path in the LoadModule line for this module with the file path passed to _search_.
* _copy_ - A new module will be added and the file will be copied to the default modules directory.
* _norestart_ - Don't restart the web server on completion

Locates the specified module and uncomments its LoadModule line to enable it. If the module is not in ServerRoot\modules, the script looks in _search_ or the current directory for the module. `-add` will force the script to either find the file in the current or specified location or fail.
Locates the specified module and uncomments its LoadModule line to enable it. A new module will be added if a path to a valid file is passed to `-search`. The new LoadModule line will be appended to the long list of enabled and disabled lines that usually comes with Windows Apache. `-copy`. will make a copy in the default modules folder. If `-mod` names a newly added module, it must be the same name specified by the module file. If referring to a module already specifed in the conf, it may be named by either the part before `_module`, the full module name, filename, or basename (filename without extension).

__a2dismod [[-mod] \<String\>] [-norestart]__
* _mod_ - The module to add
__a2dismod [[-m[od]] \<String\> [-n[orestart]]]__
* _mod_ - The module to disable
* _norestart_ - Don't restart the web server on completion

Adds a comment marker to the LoadModule line of the specified module to disable it.

***********

__a2ensite [[-mod] \<String\>] [[-search] \<String\>] [-a[dd]] [-norestart]__
* _mod_ - The conf file with a [Virtual Host] block that defines the site. Moved to sites-enabled (default directory) if not already there.
* _search_ - The location in which to look for the conf file if not found in the default directory
* _add_ - Force script to move the site conf file from the location to the default directory
__a2ensite [[-m[od]] \<String\> [-c[opy]] [-r[eplace]] [-n[orestart]]]__
* _mod_ - The conf file with a [Virtual Host] block that defines the site. Unless `-copy` is used, this names a basename or filename of a .conf file in ServerRoot\conf\sites-available.
* _copy_ - Copy the configuration file specified by `-mod` to sites-enabled.
* _replace_ - Delete the .conf file of the same name in sites-available.
* _norestart_ - Don't restart the web server on completion

Move the specified site's conf file to ServerRoot\conf\sites-enabled from either _search_ or the current directory if not found in ServerRoot\conf\sites-available. `-add` will force the script to either find the file in the current or specified location or fail.

Move or copy the file specified by `-mod` to ServerRoot\conf\sites-enabled. `-copy` tells the script that `-mod` will name the path to a file instead of naming a conf file already in ServerRoot\conf\sites-available. Use `-replace` to delete the .conf of the same name in sites-available.

[Virtual Host]: http://httpd.apache.org/docs/2.4/vhosts/

__a2dissite [[-mod] \<String\>] [-norestart]__
* _mod_ - The conf file to move to sites-disabled
__a2dissite [[-m[od] \<String\> [-a[dd]] [-n[orestart]]]__
* _mod_ - The conf file in sites-enabled to be moved to sites-available
* _add_ - `-mod` will name a path to a file to be moved to sites-available
* _norestart_ - Don't restart the web server on completion

Move the specified site's conf file to ServerRoot\conf\sites-available from ServerRoot\conf\sites-enabled.
Move the specified site's conf file from ServerRoot\conf\sites-enabled to ServerRoot\conf\sites-available.

## Notes
Module and site names can only refer to files of type `.so` or `.conf`, respectively, and may be specified by either their basename or filename with extension. Modules can also be referred to by the part of their name following the prefix “mod_”.

The line `Include /conf/sites-enabled` will be added to your main conf file and the sites-available and sites-enabled directories will be created if they don't already exist. See the file at ServerRoot\conf\extra\httpd-vhosts.conf for an example Virtual Host configuration.
Whenever the _site_ scripts are run, the line `Include /conf/sites-enabled` will be added to your main conf file and the sites-available and sites-enabled directories will be created if they don't exist. See the file at ServerRoot\conf\extra\httpd-vhosts.conf for an example Virtual Host configuration.

All commands restart the web server on successful completion unless the `-norestart` flag is given.

a2enmod will not create a `LoadModule` line for new modules added with `-add`.

If you use `-norestart` when overwriting an enabled module with the `-add` option, the script will ask if you’d like to restart the web server in order to overwrite the file. Saying “No” will exit.
If you use `-norestart` when overwriting a module with `-copy` option, the script will ask if you’d like to restart the web server in order to overwrite the file. Saying “No” will exit.

The commands without parameters will display info about the modules or sites.

Expand All @@ -79,42 +75,43 @@ The commands without parameters will display info about the modules or sites.
a2enmod
Show information about enabled and disabled modules.

a2enmod ssl
Enable the mod_ssl.so module. If it’s not in the default modules folder, look for it in the current directory and copy it to the modules folder.
a2enmod sed
Enable the module whose name is *sed_module*.

a2enmod mod_ssl C:\my\folder
Enable the mod_ssl.so module, first looking for it in the default modules folder and then in `C:\my\folder`. If it’s in the specified folder, copy it to the default modules folder before enabling it.
a2enmod ssl_module C:\my\folder\mod_ssl.so -a
Add the line `LoadModule ssl_module "C:\my\folder\mod_ssl.so"` to the main configuration file and restart the web server.

a2enmod mod_ssl.so C:\my\folder –a
Copy the mod_ssl.so module from the specified folder into the default modules folder, then enable it.
a2enmod -mod ssl_module -search C:\my\folder\mod_ssl.so -copy
Copy the file passed to `-search` into the default modules folder, and add the line `LoadModule ssl_module "C:\my\folder\mod_ssl.so"` to the main configuration file. The module name for `-mod` must match its definition in the shared object file.

a2enmod ssl –norestart
Enable the mod_ssl.so module, but don’t restart the web server.
a2enmod rewrite –n
Uncomment the line `LoadModule rewite_module modules/mod_rewrite.so` from the the main configuration, but don’t restart the web server.

a2dismod ssl
Disable the mod_ssl.so module.
Disable ssl_module.

***********
a2ensite
Show information about enabled and disabled sites.

a2ensite mysite
Enables the site defined in the file mysite.conf. If it’s not in the sites-available folder, look for it in the current directory and move it to the sites-enabled folder.
Enables the site defined in the file ServerRoot\conf\sites-available\mysite.conf.

a2ensite mysite.conf C:\my\folder
Enable the mysite.conf site, first looking for the file in sites-available and then in `C:\my\folder`. If it’s in the specified folder, copy it to the default modules folder before enabling it.
a2ensite C:\my\folder\mysite.conf -add
Move the Virtual host configuration defined in C:\my\folder\mysite.conf to ServerRoot\conf\sites-enabled.

a2ensite mysite C:\my\folder –add
a2ensite C:\my\folder\mysite.conf -c
Copy mysite.conf from the specified folder into sites-enabled, then enable it.

a2ensite mysite –norestart
Enable the site in mysite.conf, but don’t restart the web server.
Move ServerRoot\conf\sites-available\mysite.conf to ServerRoot\conf\sites-enabled, but don’t restart the web server.

a2dissite mysite
Disable the mysite.conf site.
Disable ServerRoot\conf\sites-enabled\mysite.conf by moving it to sites-available and restarting the web server.

## Screenshot
<img src="http://aninternetpresence.net/github/win_a2en_usage.PNG" style="border:none"/>
## Screenshots
<img src="http://aninternetpresence.net/github/mod_screenshots.png" style="border:none"/>
<img src="http://aninternetpresence.net/github/site_screenshots.png" style="border:none"/>

## Disclaimer
This is a work in progress. Please feel free to contribute. You will inevitably notice some kinks and oddities in its operation, which I aim to improve. I would really like to get an optional GUI going or something like that, as it would be much nicer to run something to click these options rather than always type them. Please let me know if you have trouble using this, or have any suggestions. Pull requests are more than welcome. Thank you for trying out this project.
Loading

0 comments on commit ac4ebfe

Please sign in to comment.