Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to start a program from web browers using php

    Hi. I'm trying to make a open source kiosk like system. When the web browser starts all programs, it will run in the browser using PHP. I've found this link: Program execution Functions. It's using:

    <?php
    $WshShell = new COM("WScript.Shell");
    $oExec = $WshShell->Run("WINWORD.exe", 7, false);
    ?>

    I was able to start Microsoft Word on Windows, but I need to be able to do this on Linux. This is what I've tried on my Linux server:

    <?php
    exec("/var/www/test.sh");
    ?>

    But nothing happens. I know that test.sh works because I ran if from the terminal. I use test.sh to start a Python script. The Python script starts a text editor. I've tested the Python script and it works. All I need know is how to start the script from PHP on Linux.

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,903
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Make sure you have full permissions on test.sh You might want to consider setting permissions at the start of the script and resetting them after the script is run, for security reasons. Also, you can try shell_exec.

    PS: You can try this.
    PHP Code:
    <?php



    $vals 
    shell_exec("dir -1Q");

    print 
    $vals;



    ?>
    Last edited by DrDOS; 11-20-2010 at 09:50 PM.

  • Users who have thanked DrDOS for this post:

    acrs (11-21-2010)

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    as you noticed linux is a little more secure than windows

    who is the owner of test.sh? it needs to be apache/www-data/httpd, whatever your apache runs as.

    if your script needs to run as root you need to add apache to the list of sudoers (see /etc/sudoers) and configure that file to allow apache (www-data/httpd whatever) to execute that script ... here is a very unsafe example that we use internally

    (part of) /etc/sudoers
    Code:
    # Cmnd alias specification
    #an alias for the stuff we want to allow
    Cmnd_Alias	MOUNTS = /bin/mount, /bin/umount
    #give www-data ability to use the command alias without a password ~~~~
    www-data	ALL = (root) NOPASSWD: MOUNTS
    PHP Code:
     $success = `sudo mount /dev/sdg1 /media/browse_backup`; 
    as you can imagine giving apache any root access is dangerous, so hopefully you wont have to, it depends what your script is trying to do.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • Users who have thanked firepages for this post:

    acrs (11-21-2010)

  • #4
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thumbs up Thanks to all

    ok i got it to work using firepages example

    (part of) /etc/sudoers
    Code:

    # Cmnd alias specification
    #an alias for the stuff we want to allow
    Cmnd_Alias MOUNTS = /bin/mount, /bin/umount
    #give www-data ability to use the command alias without a password ~~~~
    www-data ALL = (root) NOPASSWD: MOUNTS

    PHP Code:
    $success = `sudo mount /dev/sdg1 /media/browse_backup`;

    0 down vote accept


    I had to change the test.sh owner permission to www-data
    Last edited by acrs; 11-21-2010 at 12:21 PM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •