找到你要的答案

Q:error with exec() function in php

Q:在PHP exec()函数误差

I am having some issues running a program from a command line in php. Whenever I run the program in the command line, the proper file is created and it works perfectly. However when I go and put it in my php and use the exec() function, nothing happens.

In the end I want the user to be able to select the parameters he wants to run on the external program, but for now im just trying to run it with hard coded values in....

Here is the command that I use to run the program from the command line and its parameters.

 [path1] -p blastp -d [parameter1] -i [path2] -e [parameter2] -m 9 -o [path3]

 where [path1] is the path to ../blast-2.2.26/bin/blastall, 
       [path2] is the path to sample.fasta
       [path3] is the path for the output file (you may want to create another folder for generating the output)
       [parameter1] is the name of database chosen by the user from your page (eg. Human.db, Viruses.db, etc)
       [parameter2] is the E-value given by the user from your page(eg. 0.0001, 1, 1000, etc)

The actual code I would type into the command line would be

~/blast/blast-2.2.26/bin/blastall -p blastp -d db -i ~/temp/sample.fasta -m 9 -o output'

Here is my code so far.

<form method="POST", action="/~cs4380sp15grp4/home/blast.php">


<?php
    session_start();
    require_once '../secure/database.php';
    $mysqli = new mysqli($dbhost,$dbuser,$dbpass,$dbname);

    if($mysqli->connect_error){
            exit('CON Error: ' . $mysqli->connect_errno . ' ' . $mysqli->connect_error);
    }

    //Insert the values into the database

    if(isset($_POST['submit'])){


            $db = $_POST['database'];
            $evalue = $_POST['evalue'];
            $sequence = $_POST['BlastSearch'];



             exec('/students/groups/cs4380sp15grp4/blast/blast-2.2.26/bin/blastall -p blastp -d db -i /students/groups/cs4380sp15grp4/temp/sample.fasta -m 9 -o /students/groups/cs4380sp15grp4/temp/output');
    }





?>

So my exec function isnt working in my php page because that same command works in the terminal.

我有一些问题,从一个PHP的命令行程序。每当我在命令行中运行程序时,创建的文件是正确的,它是完美的。但是当我去把它放在我的PHP和使用exec()功能,什么都没有发生。

最后,我希望用户能够选择参数,他想运行的外部程序,但现在我只是试图运行它与硬编码值…

这里是命令,我用来运行程序从命令行和它的参数。

 [path1] -p blastp -d [parameter1] -i [path2] -e [parameter2] -m 9 -o [path3]

 where [path1] is the path to ../blast-2.2.26/bin/blastall, 
       [path2] is the path to sample.fasta
       [path3] is the path for the output file (you may want to create another folder for generating the output)
       [parameter1] is the name of database chosen by the user from your page (eg. Human.db, Viruses.db, etc)
       [parameter2] is the E-value given by the user from your page(eg. 0.0001, 1, 1000, etc)

我输入命令行的实际代码将是

~/blast/blast-2.2.26/bin/blastall -p blastp -d db -i ~/temp/sample.fasta -m 9 -o output'

这里是我的代码到目前为止。

<form method="POST", action="/~cs4380sp15grp4/home/blast.php">


<?php
    session_start();
    require_once '../secure/database.php';
    $mysqli = new mysqli($dbhost,$dbuser,$dbpass,$dbname);

    if($mysqli->connect_error){
            exit('CON Error: ' . $mysqli->connect_errno . ' ' . $mysqli->connect_error);
    }

    //Insert the values into the database

    if(isset($_POST['submit'])){


            $db = $_POST['database'];
            $evalue = $_POST['evalue'];
            $sequence = $_POST['BlastSearch'];



             exec('/students/groups/cs4380sp15grp4/blast/blast-2.2.26/bin/blastall -p blastp -d db -i /students/groups/cs4380sp15grp4/temp/sample.fasta -m 9 -o /students/groups/cs4380sp15grp4/temp/output');
    }





?>

所以我的EXEC功能不在我的PHP网页的工作,因为同样的命令在终端工作。

answer1: 回答1:

Does the Apache server user have access to this program? To make sure, try to run sudo chmod 755 /students/groups/cs4380sp15grp4/blast/blast-2.2.26/bin/blastall and try again.

Likewise, make sure that the Apache process has access to the input and output directories.

Apache服务器的用户是否可以使用该程序?确保,尝试运行sudo chmod 755 /学生/团体/ cs4380sp15grp4 /风/ blast-2.2.26/bin/blastall再试。

同样,确保Apache进程访问输入和输出目录。

php  database  command-line  exec