Reinforce the PHP environment)

Source: Internet
Author: User

Author: Albert
When PHP is running as an Apache module, Apache security plays a leading role. Therefore, if the configuration is correct, PHP should be a very secure environment, however, If PHP runs in CGI mode, it is not so secure.
The operations mentioned in this article are applicable to both Unix and Windows.
1. Run as an Apache module
Generally, Apache runs with "nobody" or "www". Therefore, PHP is safe as a module.
If PHP is in a VM environment, users may be at risk of browsing other user files. A simple script is as follows:
  
// Assume that the document root is in/usr/local/websites/mydomain
$ Location = ../; // go to the upper-level directory
$ Parent = dir ($ location );
// Display the current directory:/usr/local/websites
While ($ entry = $ parent-> read ()){
Echo $ entry.
;
}
$ Parent-> close ();
?>
In this way, you only need to modify $ location to view all the files of other users on the VM. To reduce this risk, we need to take a look at php. ini and modify the safe_mode, doc_root, and usr_dir parameters to restrict users to their own virtual host environments:
Safe_mode = On
Doc_root =/usr/local/apache/htdocs
User_dir =/home/Albert TXU/htdocs
II. As CGI
You need to be very careful when running PHP in CGI Mode, which may expose information that you do not want to know.
The first thing to note is to place the execution file outside the root directory of the document. For example,/usr/local/bin. Therefore, all CGI files must start:
#! /Usr/local/bin/php
To prevent the user from calling CGI directly, force CGI redirection in Apache:
Action php-script/cgi-bin/php. cgi
AddHandler php-script. php
The following URL
Http://example.com/mywebdir/test.htm
Convert:
Http://example.com/cgi-bin/php/mywebdir/test.htm
When compiling PHP in CGI mode, it is best to use the following options:
-- Enable-force-cgi-redirect
This article discusses the security of PHP. For details about the security, refer to the security
Http://www.php.net/manual/en/security.php
That chapter.


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.