Php uses exec to execute shell scripts

Source: Internet
Author: User
Php uses exec to execute shell scripts first: & nbsp; perform web-based operations on Linux, this allows you to perform basic operations on the web end, but now you are writing the code for creating a directory: & nbsp; $ mkdir_command & nbsp; ho php uses exec to execute shell scripts
Let's talk about what I want to do first:
Web-based operations in Linux allow you to perform basic operations on the web end, but now you are writing the code to create a directory:
$ Mkdir_command = "/home/myname/myshell/mkdir. sh/$ directory/$ name ";
Exec ($ mkdir_command, $ output, $ return );
.....
I also know that executing shell scripts on the web end is actually running with Apache permissions in Linux,
However, in Linux. sh has changed its permission to root at runtime. that is to say, any user who calls the file executes chmod 777 mkdir with the root permission. sh; chmod u + s mkdir. sh
However, the execution on the webpage is still unsuccessful.
In Linux alone, the execution is successful,
I hope you can express your comments or comments. thank you !!
------ Solution --------------------
Apache requires write permission on this directory
------ Solution --------------------
1. the web writes the results to a file. for example, you can create a file based on what you want to create.

2. linux root regularly calls shell to check whether there is any file that needs to be updated.
In this case, the root user is used to perform the operation.


Just create a timer.
------ Solution --------------------
You have to check whether you have the execution permission.
System/exec first executes a simple command such as ls and ifconfig to check whether the execution is successful.
Check the permission of the. sh file again.
------ Solution --------------------
In linux, enter do
Then we append the object at the end.
Apache ALL = NOPASSWD:/bin/sh
Then
Execute exec ("/usr/bin/sudo/bin/sh/xxx. sh") in php ")
/Xxx. sh is the script you want to execute

Let's take a look at this article to solve your problem.
Http://blog.csdn.net/vindo/article/details/3610587
------ Solution --------------------
Add sudo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.