When PHP is running as an Apache module, the Apache security takes the lead, so if configured correctly, PHP should be a very secure environment, but if PHP is running in CGI, it's not so safe.
The actions mentioned in this article apply to both UNIX and Windows.
One, as the Apache module to run
Because generally speaking, Apache will be "nobody" or "www" to run, so PHP as a module is very safe.
If PHP is in a virtual host environment, it may create the risk that users can browse other user files. A simple script is as follows:
Assume that the document root is located in/usr/local/websites/mydomain
$location =. /; To the previous level directory
$parent = Dir ($location);
Display current directory:/usr/local/websites
while ($entry = $parent->read ()) {
Echo $entry.
;
}
$parent->close ();
?>
This allows the user to browse all other user's files on the virtual host as soon as the $location is modified. To reduce this risk, we need to look at the php.ini, modify the Safe_mode, Doc_root, and Usr_dir parameters, and limit the user to his own virtual host environment:
Safe_mode = On
Doc_root =/usr/local/apache/htdocs
User_dir =/home/albertxu/htdocs
Second, as a CGI
Running PHP in CGI requires great care and may reveal information you don't want to know.
The first thing to be aware of is that you must put the execution file outside the document root directory. For example/usr/local/bin, so all CGI files must begin with:
#!/usr/local/bin/php
The way to prevent users from calling CGI directly is to force CGI redirection in Apache:
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