20

I'm setting up an environment for wordpress on apache2, on a fresh install of ubuntu 12.04.

In order to get friendly URLS working, I'm trying to set up mod_rewrite. I followed some instructions I found on the net, and used a2enmod.

Now. after restarting apache, I'd like to check if the module is actually loaded.

The command that I've found for getting a list of loaded modules is this:

apache2 -t -D DUMP_MODULES

However, this returns an error:

apache2: bad user name ${APACHE_RUN_USER}

So, how do I actually list all loaded modules, or otherwise check to see if mod_rewrite has been enabled?

user124130
  • 201
  • 1
  • 2
  • 3

9 Answers9

19

KM01 meant apachectl but that will not give you what you need. That will control starting/stopping/restarting of the server, along with giving some status information. The php file option works, but requires some extra work on your part. Instead, try running php from the command line: $ php -i. This outputs what phpinfo() outputs, only on the command line.

You can get a list of compiled-in modules by running $ apache2 -l, but that doesn't help for viewing dynamically loaded modules using the LoadModule (or other) directives.

You can see what modules are being dynamically loaded by looking at the entries in /etc/apache2/mods-enabled/. Some have an additional conf file in the same directory for configuration. Those modules are NOT getting loaded twice. You can see a list of available modules to load dynamically by looking in /etc/apache2/mods-available/. You can enable them on the command line with $ a2enmod <module_name>. You can unload them with $ a2dismod <module_name>.

When you are done enabling/disabling, you must restart apache with $ service apache2 restart or $ apachectl graceful. You will need root (sudo) privileges to do most, if not all, of this work.

Chris Smola
  • 191
  • 1
  • 2
5

Instead of using apache2 command, do you have the apachectl command? It should be in the same location as apache2. Or you could execute the command with elevated privileges using sudo apache2 -t -D DUMP_MODULES

KM.
  • 1,746
  • 2
  • 18
  • 31
5

On centos 6.5+ at the terminal type

httpd -M | grep 'rewrite'

If in the answer, you can see rewrite_module (shared) it means it is installed.you can remove grep 'rewrite' and get the list of all modules for your Apache installation.

4

1) Type <?php phpinfo(); ?> in a php file and save it and run that file in the server.

2) And now you can the list of information, just search the word “mod_rewrite” from the browser’s search menu

3) If it is found under the “Loaded Modules” section then this module is already loaded as you see in the picture below, otherwise you need to go to the next step for enabling mod_rewrite module.

source:http://roshanbh.com.np/2008/04/check-enable-mod_rewrite-apache.html

user9517
  • 114,104
  • 20
  • 206
  • 289
Richard
  • 230
  • 4
  • 11
2

Just as @Richard explained, but what you actually need to do in order to achieve that is to have a file with the following contents:

<?php
    phpinfo();
?>

This prints out various information about your apache/php configuration. Other useful stuff that you will find there would be if imagick is installed or not. All loaded apache modules are there as well.

2

PHP info won't always show you whether or not it is enabled. Sorry!

However, this page over on Stack Overflow does get you pointed in the right direction.

Alternatively, here is some php to list them all out:

<?php foreach( apache_get_modules() as $module ) echo "$module<br />";  ?>
misterich
  • 41
  • 5
  • 2
    You're right, phpinfo (or via apache extension) solution works only if PHP is compiled/used as an Apache module. Not in *CGI, FPM, etc. Besides, mod_rewrite could be loaded (LoadModule) but rewriting could be denied, according to AllowOverride and/or Options. – julp Dec 11 '12 at 16:58
2

Just create mod_rewrite.php file in your root directory and place the below code in it:

<?php 
echo
"Mod_rewrite is activated!"
; ?>

Now rename your old .htaccess file

Just create new .htaccess file and place the below code.

RewriteEngine On
RewriteRule ^.*$ mod_rewrite.php

Now hit save.

Then visit your site you will get a message.

kenorb
  • 5,943
  • 1
  • 44
  • 53
Awais
  • 31
  • 1
1

When enabling a module on a Debian flavoured Linux server, apache will set up configuration files in the folder /etc/apache2/mods-enabled/

To enable mod_rewrite, the following coming command

sudo a2enmod rewrite

will setup the following files,

/etc/apache2/mods-enabled/rewrite.load
/etc/apache2/mods-enabled/rewrite.conf

to to check if the module is enabled you could simply do

ls /etc/apache2/mods-enabled/

anc check if the rewrite configuration files are present.

Aurovrata
  • 111
  • 4
0

On suse type as root in terminal httpd2 -M, that gives a list of loaded modules. httpd2 -l only gives the compiled in modules. This works for apache 2.4

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
Richard
  • 1
  • 1