2016-09-10 5 views
0

Здесь я прочитал несколько вопросов о том, как запустить скрипт bash из html. Большинство из них ссылались на php. I followed everything in here но нет. У меня нет опыта работы с html или php. Итак, я настроил все так, как должно быть (я думаю ...). Я установил nginx (и его рабочий тон). Я установил php и php-fpm.запустить скрипт bash из html

Моя простая веб-страница:

<!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)

Что я сделал не так?

ответ

0

Как я уже упоминал ранее, у меня нет опыта работы с 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> 
Смежные вопросы