How to execute a shell script in PHP?

前端 未结 4 1830
暖寄归人
暖寄归人 2020-12-03 01:16

I have a script in /var/www/myscript.sh which creates folders and runs the command svn update for my projects. I need to execute this script by calling

4条回答
  •  悲&欢浪女
    2020-12-03 02:17

    If you are having a small script that you need to run (I simply needed to copy a file), I found it much easier to call the commands on the PHP script by calling

    exec("sudo cp /tmp/testfile1 /var/www/html/testfile2");
    

    and enabling such transaction by editing (or rather adding) a permitting line to the sudoers by first calling sudo visudo and adding the following line to the very end of it

    www-data ALL=(ALL) NOPASSWD:/bin/cp /tmp/testfile1 /var/www/html/testfile2
    

    All I wanted to do was to copy a file and I have been having problems with doing so because of the root password problem, and as you mentioned I did NOT want to expose the system to have no password for all root transactions.

提交回复
热议问题