Running a Unix shell script from PHP

Posted on 2006-04-20
Last Modified: 2006-11-18
Hey, Experts...

I can't kick off a unix shell script from inside my PHP web page...can I?  

Question by:bakum
    LVL 15

    Expert Comment

    You can, if your PHP is not in safe mode or restricted in a similar way by your web hosting provider. See

    Author Comment

    I've upped the point value here because while those commands are useful...what I want to run is a ~script~.  And I can't seem to make the script run.  The command returns no output, return value is 1.  

    It might bear upon the situation that the script makes an FTP connection and downloads any files that are in the remote directory.  Anyone think this is possible?  

    Here is the PHP code I'm trying to execute...$output never returns anything:

    $output = `sh >>logfile.txt`;
    echo $output;

    here is the works great when executed from the command line:


    ftp -n<<END_SCRIPT
    quote USER $USER
    quote PASS $PASSWD
    lcd releases
    mget  *.*

    exit 0

    LVL 15

    Accepted Solution

    $output will never get anything because you redirected all output to logfile txt. That is, if your sample runs anything at all - I'm not sure backticks (``) create an environment enough to find sh - try replacing it with /bin/sh

    Author Comment

    Outstanding.  Once again, this is truly an "EXPERTS" exchange.  


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now