Determing the Execution Environment of Apache

I am having this error:

[Mon Dec 05 10:22:23 2011] [warn] mod_rewrite: Running external rewrite maps without defining a RewriteLock is DANGEROUS!
[Mon Dec 05 10:22:23 2011] [error] (13)Permission denied: mod_rewrite: could not start RewriteMap program /etc/httpd/conf.d/upsell_by_id.py

This error is associated with this line : RewriteMap upsells prg:/etc/httpd/conf.d/upsell_by_id.py

I realize that this probably means that the execution user for apache cannot execute these files. How do I determine what the execution environ ment is for apache? How do I make this file upsell_by_id.py executable to apache?

I get this error when I try to run the upsell_by_id.py as apache:
Traceback (most recent call last):
  File "/etc/httpd/conf.d/upsell_by_id.py", line 8, in <module>
    keyword_groups = pickle.load(open("/home/zumodo/upsell_backup/upsells.pkl", "rb" ) )
IOError: [Errno 13] Permission denied: '/home/zumodo/upsell_backup/upsells.pkl'

This is despite the fact that the file upsells.pkl appears to have all the neccessary permission:

-rwxrwxrwx.  1 skline skline 6.4M Dec  5 08:50 upsells.pkl

You actually have two errors there. The permissions one first:

Apache will need appropriate permissions in each of the directories leading up to the upsells.pkl file as well as on the file itself.

Try this to determine what permissions the directories have (note the spaces are important):

ls -ld /home/ /home/zumodo/ /home/zumodo/upsell_backup/

The Apache user will need the x permission on each of those directories. /home usually has the required permissions but it's quite common for everything in /home/* to have mode 750 (rwxr-x---) or even mode 700 (rwx------). Either of these would cause your problem. The permissions problem could easily be on the upsell_backup directory as well.

Move the upsells.pkl file to a more appropriate path (such as /var/www/) or change the permissions on the restrictive directory.

The error message about the RewriteLock is correct; not having one is dangerous.

Apache is either multi-threaded or spawns multiple children which means that any two of them can receive requests at the same time. The RewriteLock is used internally by Apache to make sure that only one child or thread is talking to the external process at a time. If you don't specify one, the output of the program can end up being mixed together, completely messing up your rewrite rules and possibly your entire server. The most likely result is that when your server gets busy you will generate a lot of 500 responses. Significantly worse results are possible.


For time being disable RewriteMap upsells line and see if apache starts or not. If it starts check user running apache.

Run following command.

ps axho user,comm|grep -E "httpd|apache"|uniq|grep -v "root"|awk 'END {print $1}'

This command will give you user running apache server. Then check ownership and permissions of the file. I think the file should be executable for the user running apache/httpd process.

Then by using following command set appropriate permissions and ownership of the file.

chown root.apache /etc/httpd/conf.d/upsell_by_id.py

chmod +x /etc/httpd/conf.d/upsell_by_id.py