从html中运行bash脚本


run bash script from html

我在这里阅读了几个问题如何从html运行bash脚本。他们中的大多数都把我推荐给php。我跟踪了这里的一切,但没有成功。我没有html或php的任何经验。所以我把一切都安排好了(我想……)我安装了nginx(它工作得很好)。我安装了php和php-fpm

我的简单网页是:

<!DOCTYPE html>
<html>
<head>
<title>My page</title>
</head>
<body>
<button type="button" onclick="run.php">Click Me!</button>
</body>
</html>

我默认的nginx服务器配置是:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    root /usr/share/nginx/html;
    index index.html index.htm;
    # Make site accessible from http://localhost/
    server_name localhost;
    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        #try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.html;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }
    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #   proxy_pass http://127.0.0.1:8080;    
    #}
    #error_page 404 /404.html;
    # redirect server error pages to the static page /50x.html
    #
    #error_page 500 502 503 504 /50x.html;
    #location = /50x.html {
    #   root /usr/share/nginx/html;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ '.php$ {
        fastcgi_split_path_info ^(.+'.php)(/.+)$;
    #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #   # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
    #   # With php5-fpm:
    #   fastcgi_pass unix:/var/run/php5-fpm.sock;
    #   fastcgi_index index.php;
    #   include fastcgi_params;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /'.ht {
    #   deny all;
    #}
}

我尝试了两个选项:单独使用php5-cgi/使用php5-fpm

我的php脚本应该触发按钮点击:

<?php
shell_exec("ls");
header('Location: https://www.google.com');
?>

但是什么也没有发生(现在,我只运行简单的ls)。当这将工作,我将更改为一些/path/script.sh)

我做错了什么?

所以正如我之前提到的,我没有任何html或php的经验。

问题是我分开了html和php文件。当组合时,一切都工作正常。

<?php
if ($_GET['run']) {
  # This code will run if ?run=true is set.
  exec("ls");
  header('Location: https://www.google.com');
}
?>
<html>
<head>
<title>My page</title>
</head>
<body>
<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
<a href="?run=true">Click Me!</a>
</body>
</html>