Python Shebang Line
Я пытаюсь выполнить скрипт на python как скрипт cgi, используя apache2. Однако вместо выполнения файл загружается. Я позволил моему файлу python быть исполняемым файлом. Я думаю, что это происходит, потому что моя линия Шебанга неверна. Итак, как мне узнать, какую правильную линию Шебанга добавить. У меня установлена Ubuntu 16.04 и python 3.5.2. Любая помощь / направление было бы очень полезно. Спасибо
РЕДАКТИРОВАТЬ
Добавление скрипта Python
#!/usr/bin/env python
import cgi
form = cgi.FieldStorage()
query = form.getvalue('query')
print("Content-type:text/html")
print()
print("<html>")
print("<head>")
print("<title>search results</title>")
print("</head>")
print("<body>")
print("\
<div style = 'position:absolute;text-align:center;width:100%;left:0%;top:0%;margin:0%;padding:0%;'>\
<h4 style = 'font-family:Arial;font-size:24px;color:dodgerblue;'>muGoogle</h4>\
<form class='form-wrapper' action='hello.py' method='get'>\
<input type='text' id='search' placeholder='Search docs related to...' required name = 'query' style = 'font-family:Arial;font-\size:14px;width:60%;height:40px;'/>\
<input type='submit' value='Submit' id='submit' style = 'height:40px'>")
print("<p> search results for: %s </p>" % query)
print("</body>")
print("</html>")
РЕДАКТИРОВАТЬ 2
Добавление HTML
<html>
<head>
<title>muGoogle</title>
<link type = 'stylesheet' ref = 'style.css'>
</head>
<body>
<div style = 'position:absolute;text-align:center;width:100%;left:0%;top:15%;margin:0%;padding:0%;'>
<h4 style = 'font-family:Arial;font-size:48px;color:dodgerblue;'>muGoogle</h4>
<form class='form-wrapper' action='query.py' method='get'>
<input type='text' id='search' placeholder='Search docs related to...' required name = 'query' style = 'font-family:Arial;font-size:14px;width:60%;height:40px;'/>
<input type='submit' value='Submit' id='submit' style = 'height:40px'>
</form>
</div>
</body>
</html>
РЕДАКТИРОВАТЬ 3
добавление файла конфигурации по умолчанию
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks MultiViews
AllowOverride None
</Directory>
<Directory /var/www/>
Options ExecCGI Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler cgi-script .py
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin/">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
1 ответ
Если файл загружается вместо запуска Apache, то модуль, необходимый для его запуска, не загружен Apache. Для Python есть несколько модулей, которые можно использовать. Кажется, здесь используется простой модуль CGI, поэтому сделайте так:
sudo a2enmod cgi
sudo service apache2 restart