Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial PHP在Linux下执行exec

PHP在Linux下执行exec

Jun 23, 2016 pm 01:54 PM
exec linux php implement

PHP的版本为5.4

PHP代码如下:

<?phpexec('whoami', $r);var_dump($r);
Copy after login


root用户在服务器终端使用php test.php
输出结果如下,是正确的
[root@localhost htdocs]# php test.phparray(1) {  [0]=>  string(4) "root"}
Copy after login


但是在浏览器上输入http://192.168.x.x/test.php
输出为空。

感觉是linux服务器上的权限问题,但是又不知道哪个权限问题。
运行httpd的用户名为apache


回复讨论(解决方案)

whoami 显示登录名
浏览者是匿名(就是没有名字)访问网站的,所以显示为空是正确的

whoami 显示登录名
浏览者是匿名(就是没有名字)访问网站的,所以显示为空是正确的



改成exec('date', $r);也一样,我感觉是权限问题。在php.ini中的disable_functions不存在一个被禁用的函数

把错误输出 你就知道是不是权限问题了.

把错误输出 你就知道是不是权限问题了.



apache的access.log中,只有get请求。
apache的error.log中,没有错误产生。


把错误输出 你就知道是不是权限问题了.



apache的access.log中,只有get请求。
apache的error.log中,没有错误产生。

请打开 php 的错误输出



把错误输出 你就知道是不是权限问题了.



apache的access.log中,只有get请求。
apache的error.log中,没有错误产生。

请打开 php 的错误输出

错误输出是指php.ini中的 display_errors吗?
如果是的话,display_errors 已经  on

没有错误的话
那么你就chmod 吧 给个777 
无论是 whoami 还是date 都是可以输出结果的 在浏览器下
我在linux 下实测过了.剩下两个 人品和 权限  我想你应该更倾向于选择后者吧...

没有错误的话
那么你就chmod 吧 给个777 
无论是 whoami 还是date 都是可以输出结果的 在浏览器下
我在linux 下实测过了.剩下两个 人品和 权限  我想你应该更倾向于选择后者吧...



把上面的test.php改成777吗?改后还是没用,不管我把test.php的所有权改在apache还是root
-rwxrwxrwx. 1 root root       38 Jul 10 16:14 test.php


没有错误的话
那么你就chmod 吧 给个777 
无论是 whoami 还是date 都是可以输出结果的 在浏览器下
我在linux 下实测过了.剩下两个 人品和 权限  我想你应该更倾向于选择后者吧...



把上面的test.php改成777吗?改后还是没用,不管我把test.php的所有权改在apache还是root
-rwxrwxrwx. 1 root root       38 Jul 10 16:14 test.php
目录权限呢?都改改看看吧 想不出来还有什么其他的,你在什么Linux 下测试的,我在Ubuntu 下 一切都好...

测试过,一切正常。

我的环境是:
Centos 6.5 
PHP 5.4
Apache 2.4

Apache httpd的执行用户名(组)为非登录的apache:apache

nginx 
php 5.3
表示也没有输出

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

Can the Python interpreter be deleted in Linux system? Can the Python interpreter be deleted in Linux system? Apr 02, 2025 am 07:00 AM

Regarding the problem of removing the Python interpreter that comes with Linux systems, many Linux distributions will preinstall the Python interpreter when installed, and it does not use the package manager...

Four ways to implement multithreading in C language Four ways to implement multithreading in C language Apr 03, 2025 pm 03:00 PM

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

How to open web.xml How to open web.xml Apr 03, 2025 am 06:51 AM

To open a web.xml file, you can use the following methods: Use a text editor (such as Notepad or TextEdit) to edit commands using an integrated development environment (such as Eclipse or NetBeans) (Windows: notepad web.xml; Mac/Linux: open -a TextEdit web.xml)

See all articles