我有一个位于/ var / www / html / Python文件夹中的python脚本(python.py)。
该脚本将一些图像保存到另一个目录(/ var / www / html / Data)
我对python.py脚本具有-x文件权限,并且在保存输出的文件上对所有文件具有-rw权限。
我正在运行apache2版本2.4
这就是我的apache2.conf文件的样子:
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
由于我运行的版本2.4我的cgi conf在:/ect/apache2/conf-available/serve-cgi-bin.conf
它看起来像这样:
<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>
我通过运行命令启用了cgi模块
sudo a2enmod cgi
并使用重新启动服务器
服务apache2重新启动
但是,尽pipe如此,我的Python脚本仍然没有执行,并显示为一个文本文件。
有谁能够帮助我? 我无法弄清楚我做错了什么。
一个愚蠢的问题:你有一个硬链接/etc/apache2/conf-available/serve-cgi-bin.conf目录/etc/apache2/conf-enabled ?
编辑:为了创build一个链接,你要做的是,在命令提示符下,转到/etc/apache2/conf-enabled目录,然后键入
ln /etc/apache2/conf-available/serve-cgi-bin.conf serve-cgi-bin.conf
如果在该目录中没有文件创build权限,则可能必须sudo该命令。 当然,您必须在创build链接后重新启动apache。
如果是权限问题,则可能是权限过于宽松。 我知道Sendmail会拒绝接受某些configuration文件,如果它们是可写的; 我不会惊讶地发现Apache也是如此。 检查Apache的用户没有写入.conf文件的权限。