1

I have a python script (python.py) located in the /var/www/html/Python folder.

The script saves some images to another directory (/var/www/html/Data)

I have the -x file permission on the python.py script and -rw permission for all on the files where the output is saved.

I am running apache2 version 2.4

This is what my apache2.conf file looks like:

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

</Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FileMatch>

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

Since I am running version 2.4 my cgi conf is at : /ect/apache2/conf-available/serve-cgi-bin.conf

It looks like this:

<IfModule mod_alias.c>
    <IfModule mod_cgi.c>
        Define ENABLE_USR_LIB_CGI_BIN
    </IfModule>

    ScriptAlias /cgi-bin/ /var/www/html/Python
    <IfDefine ENABLE_USR_LIB_CGI_BIN>
        Define ENABLE_USR_LIB_CGI_BIN
    </IfDefine>

    <Directory "var/www/html/Python">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
        AddHandler cgi-script .py
        AddHandler default-handler .html.htm
    </Directory>
</IfModule>

I have enabled the cgi module by running the command

sudo a2enmod cgi

and restarted the server using

service apache2 restart

However despite all this, my Python script is still not executed and displays as a text file.

Can anybody help me? I can't figure out what I'm doing wrong.

cachemoi
  • 111
  • 3

2 Answers2

0

A stupid question: do you have a hardlink to /etc/apache2/conf-available/serve-cgi-bin.conf in the directory /etc/apache2/conf-enabled ?

Edit: In order to create a link, what you do is, in a command prompt, change to the /etc/apache2/conf-enabled directory, and type

ln /etc/apache2/conf-available/serve-cgi-bin.conf serve-cgi-bin.conf

You may have to sudo that command if you don't have file create permissions in that directory. You will have to restart apache once you've created that link, of course.

CharlesW
  • 31
  • 5
  • Sorry what do you mean by a hardlink? – cachemoi Apr 17 '16 at 19:18
  • Apache looks in `/etc/apache2/conf-enabled` to find out what modules are enabled. Your module is in `/etc/apache2/conf-available`. Normally there is a link in the "enabled" directory that points at the file in the "available" directory, Apache follows that link to find the file you've edited. Have you created that link? – CharlesW Apr 17 '16 at 19:30
  • This kind of looks more like a comment than an answer. I would suggest rephrasing or moving it to the comment section of the question. – Juan Carlos Coto Apr 17 '16 at 20:17
  • With only 6 rep, I can only comment on my own answers. – CharlesW Apr 17 '16 at 20:24
  • yes there seems to be a hard link to the file when i do ls -l – cachemoi Apr 17 '16 at 22:15
  • thanks for your help but by looking at the error logs i found out that it is a permission issue, even though i gave execution privileges to all users... I did run your command but it did not solve the issue – cachemoi Apr 18 '16 at 00:53
0

If it is a permissions issue, it may be that the permissions are too lenient. I know that Sendmail will refuse to accept certain configuration files if they are writable; I would not be surprised to find the same is true of Apache. Check that Apache's user does not have permission to write the .conf file.

CharlesW
  • 31
  • 5
  • so it turns out I had to give permissions with chown -R on the directories in which I was saving data – cachemoi Apr 18 '16 at 10:57