3

I'm trying to track down the cause of an intermittent Apache Internal Server Error during MediaWiki edits and uploads. Some sources tell me to check .htaccess for errors.

I can audit for .htaccess with:

sudo find /var -name '.htaccess' -exec ls -al {} \;

However, I don't know what the Apache command is to test the .htaccess file. That is, I don't know what to plug into the -exec part of find.

I've looked at apachectl and tried apachectl test, but it looks like a dead end:

$ apachectl test
Usage: /usr/sbin/httpd [-D name] [-d directory] [-f file]
                       [-C "directive"] [-c "directive"]
                       [-k start|restart|graceful|graceful-stop|stop]
                       [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
Options:
  -D name            : define a name for use in <IfDefine name> directives
  -d directory       : specify an alternate initial ServerRoot
  -f file            : specify an alternate ServerConfigFile
  -C "directive"     : process directive before reading config files
  -c "directive"     : process directive after reading config files
  -e level           : show startup errors of level (see LogLevel)
  -E file            : log startup errors to file
  -v                 : show version number
  -V                 : show compile settings
  -h                 : list available command line options (this page)
  -l                 : list compiled in modules
  -L                 : list available configuration directives
  -t -D DUMP_VHOSTS  : show parsed vhost settings
  -t -D DUMP_RUN_CFG : show parsed run settings
  -S                 : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
  -t -D DUMP_MODULES : show all loaded modules 
  -M                 : a synonym for -t -D DUMP_MODULES
  -t                 : run syntax check for config files
  -T                 : start without DocumentRoot(s) check
  -X                 : debug mode (only one worker, do not detach)

I have SSH access to the box, and that's how I perform the maintenance. There's no browser available, but I could probably work with lynx if required.

How do I test the various .htaccess shown below from the command line?


$ sudo find /var -name '.htaccess' -exec ls -l {} \;
-rw-r----- 1 root apache 180 Aug  9  2015 /var/www/html/wiki/images/.htaccess
-rw-r----- 1 root apache 14 Aug  9  2015 /var/www/html/wiki/images/deleted/.htaccess
-rw-r----- 1 root apache 14 May 25  2015 /var/www/html/wiki/languages/.htaccess
-rw-r----- 1 root apache 14 May 25  2015 /var/www/html/wiki/serialized/.htaccess
-rw-r----- 1 root apache 14 May 25  2015 /var/www/html/wiki/cache/.htaccess
-rw-r----- 1 root apache 14 May 25  2015 /var/www/html/wiki/includes/.htaccess
-rw-r----- 1 root apache 14 May 25  2015 /var/www/html/wiki/maintenance/archives/.htaccess
-rw-r----- 1 root apache 14 May 25  2015 /var/www/html/wiki/maintenance/.htaccess
-rw-r----- 1 root apache 180 Aug  9  2015 /var/www/html/.htaccess

$ apachectl -v
Server version: Apache/2.4.6 (CentOS)
Server built:   May 12 2016 10:27:23
  • What does the Apache error log say about these ISE messages? – roaima Jul 2 '16 at 22:50
  • ISE = Internal Server Error. Sorry, I thought it was obvious, but clearly not. – roaima Jul 2 '16 at 23:35
  • @Roaima - no need to apologize. All of us have day jobs; we suffer through the administration stuff at night. Details of the internal server error are given at Internal Server Error; enable debugging provides no additional information. The short of it is, there is no additional information, even with debugging info enabled (if I am reading the logs correctly). – user56041 Jul 2 '16 at 23:42
3

How do I test .htaccess from the command line?

Exactly the same way as if you were not on a command line, with an HTTP request.

There are common tools useful for that such as (but not limited to) curl and wget. Both of these tools include options to get the header received, HTTP return code and the full output.

If you need to integrate it in an automatic search, you would have to do a simple text substitution or mapping like:

basename `dirname /var/www/www.mysite.com/public`

... which outputs:

www.mysite.com

Based on your comments showing the actual path of ........

echo www.yoursite.com/`dirname /var/www/html/wiki/serialized/.htaccess|cut -d/ -f5-`

... would give you:

www.yoursite.com/wiki/serialized

So the final command could be:

wget $(echo www.yoursite.com/`dirname /var/www/html/wiki/serialized/.htaccess|cut -d/ -f5-`)
  • Of course, if the site has structure reflected in subdirectories, it's harder to know how far up to go. Instead, since the OQ says the sites all depend from /var/www/, you could use <code>echo pwd|cut -d/ -f 4</code> to extract the third directory (note 4 instead of 3, because field one is the empty string before the first /) – MAP Jul 2 '16 at 22:43
  • Thanks Julie. Please forgive my ignorance as I am an app sec guy, and not an admin. What I found online told me to visit a page with a browser. Its not clear to me if that tests each .htaccess on the system. Its also not clear to me how to turn each internal file path into an external URL. Also, doesn't Apache include a tool to do this? As many problems as incorrect .htaccess causes, it seems like Apache would provide a test and audit tool. Finally, what result am I looking for? Is it a simple HTTP 200? – user56041 Jul 2 '16 at 22:51
  • Thanks again Julie. I added additional information, and included all of the .htaccess on the system. As a concrete example, how do I test /var/www/html/wiki/serialized/.htaccess? – user56041 Jul 2 '16 at 23:02
  • @roaima: Oh, right, I keep forgetting that the markup conventions are different. But my command has backticks in it. How do I make that work? – MAP Jul 2 '16 at 23:03
  • Is it organized by subdomains like www.wiki.yoursite.com/serialized or www.yoursite.com/wiki/serialized? – Julie Pelletier Jul 2 '16 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy