How to run shell_exex command at web site using php code.

Discussion in 'Programming/Scripts' started by AnilKumar, Jul 3, 2009.

  1. AnilKumar

    AnilKumar New Member


    Can anyone suggest how to overcome from this one.

    Shell_exec is perfectly run in the localhost,
    when i want to run that command at the web server, that is not executed.

    chmod 7777 -R \public\test\sleepingbaby.jpg

    presently that file has 0644 permission.

    i want to change that file permission to full access that is 7777.

    $cmd = "chmod 7777 -R \public\test\sleepingbaby.jpg";
    $res=shell_exec ($cmd);
    when i echo $res; then that not return any values.

    Please give any solution for it.

    Anil Kumar.
    Last edited: Apr 15, 2010
  2. id10t

    id10t Member

    Is that file owned by the user the webserver is running as? Also, you don't needt omake jpgs executable - 644 is proper permissions...
  3. Leszek

    Leszek Member

    Also check if shell_exec isn't blocked in php.ini.
  4. ffs123

    ffs123 New Member

    shell_exec cannot run under website apache user

    I have same problem

    I install imagemagic at server.
    and I can run

    convert test.pdf[0] test.jpg and runs fine. and get screen shot of the first pdf file.

    login as: root
    [email protected]'s password:
    Last login: Wed Nov 2 15:55:35 2011 from
    [[email protected] ~]# convert -density 300 -quality 100 /var/www/clients/client1/web1/a.pdf[0] /var/www/clients/client1/web1/test1.jpg

    convert -density 300 -quality 100 /var/www/clients/client1/web1/a.pdf[0] /var/www/clients/client1/web1/test1.jpg

    I cannot run under website with php
    I tested in my other cpanel server and works fine. But not ISPCONFIG.
    shell_exec function is enabled in php.ini

    e.g sample php command

    if($file_type == "pdf")
    shell_exec("convert -density 300 -quality 100 /var/www/clients/client1/web1/web/files/test.pdf[0]
    "/var/www/clients/client1/web1/web/thumbs/test.jpg 2>&1");
  5. falko

    falko Super Moderator ISPConfig Developer

    Are open_basedir restrictions active? If so, you should add the directory where convert is located to the open_basedir directories (on the Options tab of the website in ISPConfig).
  6. nbhadauria

    nbhadauria New Member

    Check that apache user can execute command chmod.

    Also check apache logs for errors..

    You might need to give sudo permission to apache for command chmod.

Share This Page