search
HomeBackend DevelopmentPHP TutorialSome common security configuration methods in php.ini_PHP tutorial
Some common security configuration methods in php.ini_PHP tutorialJul 13, 2016 pm 05:10 PM
php.iniaboutSafetyCommonly usedarticlemethodofConfiguration

The article briefly introduces how to make some common security configurations in php.ini. Students in need can refer to it.

(1) Turn on the safe mode of php

PHP’s security mode is a very important built-in security mechanism. It can control some functions in PHP, such as system(). It also controls the permissions of many file operation functions and does not allow certain keyword files. files, such as /etc/passwd, but the default php.ini does not open safe mode, let’s open it:

safe_mode = on

(2) User group security

When safe_mode is turned on and safe_mode_gid is turned off, the php script can access the file, and users in the same group can also access the file. And users in the same group can also access the file.

Recommended settings are:

safe_mode_gid = off

If we do not set it up, we may not be able to operate the files in the directory of our server website, for example, when we need to operate files.

(3) Home directory for executing programs in safe mode

If safe mode is turned on but you want to execute certain programs, you can specify the home directory of the program to be executed:

safe_mode_exec_dir = /usr/bin

Generally, there is no need to execute any program, so it is recommended not to execute the system program directory. You can point to a directory: and then copy the program that needs to be executed, such as:

safe_mode_exec_dir = /temp/cmd

However, I recommend not to execute any program, then you can point to our web directory:

safe_mode_exec_dir = /usr/www

(4) Include files in safe mode

If you want to include certain public files in safe mode, then change the options:

safe_mode_include_dir = /usr/www/include/

In fact, generally the files included in php scripts have been written in the program itself. This can be set according to specific needs.

(5) Control the directories that php scripts can access

Using the open_basedir option can control the PHP script to only access the specified directory. This can prevent the PHP script from accessing files that should not be accessed. Certain programs show the harm of phpshell. We can generally set it to only access the website directory:

open_basedir = /usr/www

(6) Close dangerous functions

If safe mode is turned on, function prohibition is not necessary, but we still consider it for safety. For example, if we feel that we do not want to execute PHP functions that have clear execution, including system(), or functions such as phpinfo() that can view PHP information, then we can prohibit them:

disable_functions = system, passthru, exec, shell_exec, popen, phpinfo, escapeshellarg, escapeshellcmd, proc_close, proc_open, dl

If you want to prohibit any file and directory operations, you can close many file operations

disable_functions = chdir, chroot, dir, getcwd, opendir, readdir, scandir, fopen, unlink, delete, copy, mkdir, rmdir, rename, file, file_get_contents, fputs, fwrite, chgrp,chmod, chown

The above only lists some of the more commonly used file processing functions. You can also combine the above execution command function with this function to resist most phpshells.

(7) Close the leakage of php version information in the http header

In order to prevent hackers from obtaining the PHP version information in the server, we can turn off the leakage of this information in the http header:

expose_php = off

For example, when a hacker telnet www.girlcoding.com:80, he will not be able to see PHP information

(8) Close registered global variables

Variables submitted in PHP, including those submitted using POST or GET, will be automatically registered as global variables and can be accessed directly. This is very unsafe for the server, so we cannot let it be registered as global variables. Just turn off the register global variable option:

register_globals = off

Of course, if this is set up, then reasonable methods must be used to obtain the corresponding variables. For example, to obtain the variable var submitted by GET, then $_GET['var'] must be used to obtain it. This PHP programmer needs to Notice.

(9) Turn on magic_quotes_gpc to prevent SQL injection

SQL injection is a very dangerous problem. It can cause the website backend to be invaded, or the entire server to fall, so be careful. There is a setting in php.ini:

magic_quotes_gpc = off

This is turned off by default. If it is turned on, it will automatically convert user-submitted sql queries, such as 'convert to', etc. This is very effective in preventing sql injection, so we recommend setting it to:

magic_quotes_gpc = off

There was a time when the program did not work when uploading locally, but it worked fine on the server~ It may also be caused by inheriting the core file of discuz, and there was a problem in obtaining the path. Later, I turned on this parameter and the problem was solved.

(10) Error message control

Generally, PHP will have an error message when it is not connected to the database or under other circumstances. Generally, the error message will contain the current path information of the PHP script or the SQL statement of the query. This kind of information is not safe after being provided to hackers. , so it is generally recommended that servers disable error prompts:

display_errors = Off

If you really want to display error messages, be sure to set the level of display errors, such as only displaying information above warnings:

error_reporting = E_WARNING & E_ERROR

Of course, I still recommend turning off error prompts.

(11) Error log

It is recommended to record the error message after closing display_errors to facilitate finding the reason for the server operation:

log_errors = On

At the same time, you must also set the directory where the error log is stored. It is recommended that the root apache log be stored together:

error_log = /usr/local/apache2/logs/php_error.log

Note: The apache user or group must have write permissions for the file.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629662.htmlTechArticleThe article briefly introduces how to make some common security configurations in php.ini. Students in need can For reference. (1) Turn on the safe mode of php. The safe mode of php is a very important...
Statement
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
php.ini怎么关闭缓存php.ini怎么关闭缓存Mar 15, 2021 am 09:35 AM

php.ini关闭缓存的方法:1、找到并打开php.ini配置文件;2、找到“opcache.enable”和“opcache.enable_cli”选项,将其修改为“opcache.enable=0”和“opcache.enable_cli=0”;3、保存修改后的文件即可。

聊聊如何修改php.ini配置文件聊聊如何修改php.ini配置文件Mar 28, 2023 pm 05:34 PM

PHP.ini是一个PHP配置文件,它被用于控制PHP在服务器上的表现。此文件被用于设置一些变量的值,以便在运行时控制PHP。这篇文章将会向您展示如何修改PHP.ini配置文件的方式,以便控制PHP在您的服务器上的表现。

学习canvas框架 详解常用的canvas框架学习canvas框架 详解常用的canvas框架Jan 17, 2024 am 11:03 AM

探索Canvas框架:了解常用的Canvas框架有哪些,需要具体代码示例引言:Canvas是HTML5中提供的一个绘图API,通过它我们可以实现丰富的图形和动画效果。为了提高绘图的效率和便捷性,许多开发者开发了不同的Canvas框架。本文将介绍一些常用的Canvas框架,并提供具体代码示例,以帮助读者更深入地了解这些框架的使用方法。一、EaselJS框架Ea

研究表明强化学习模型容易受到成员推理攻击研究表明强化学习模型容易受到成员推理攻击Apr 09, 2023 pm 08:01 PM

​译者 | 李睿 审校 | 孙淑娟​随着机器学习成为人们每天都在使用的很多应用程序的一部分,人们越来越关注如何识别和解决机器学习模型的安全和隐私方面的威胁。 然而,不同机器学习范式面临的安全威胁各不相同,机器学习安全的某些领域仍未得到充分研究。尤其是强化学习算法的安全性近年来并未受到太多关注。 加拿大的麦吉尔大学、机器学习实验室(MILA)和滑铁卢大学的研究人员开展了一项新研究,主要侧重于深度强化学习算法的隐私威胁。研究人员提出了一个框架,用于测试强化学习模型对成员推理攻击的脆弱性。 研究

Spring注解大揭秘:常用注解解析Spring注解大揭秘:常用注解解析Dec 30, 2023 am 11:28 AM

Spring是一个开源框架,提供了许多注解来简化和增强Java开发。本文将详细解释常用的Spring注解,并提供具体的代码示例。@Autowired:自动装配@Autowired注解可以用于自动装配Spring容器中的Bean。当我们在需要依赖的地方使用@Autowired注解时,Spring将会在容器中查找匹配的Bean并自动注入。示例代码如下:@Auto

【整理总结】常见的PHP.ini提示报错及解决方法【整理总结】常见的PHP.ini提示报错及解决方法Mar 20, 2023 pm 04:56 PM

PHP是一种常用的服务器端脚本语言,广泛应用于Web开发领域。然而,在PHP开发过程中,我们经常会遇到各种问题。其中,PHP.ini提示报错是一个常见的问题。

深入聊聊前端限制用户截图的脑洞深入聊聊前端限制用户截图的脑洞Nov 07, 2022 pm 04:56 PM

​做后台系统,或者版权比较重视的项目时,产品经常会提出这样的需求:能不能禁止用户截图?有经验的开发不会直接拒绝产品,而是进行引导。

15个常用的币圈逃顶指标技术分析15个常用的币圈逃顶指标技术分析Mar 03, 2025 pm 05:48 PM

十五大比特币逃顶指标深度解析:2025年市场展望本文深入分析了十五个常用的比特币逃顶指标,其中比特币Rhodl比率、USDT活期理财和山寨币季节指数已于2024年触及逃顶区间,引发市场关注。面对潜在风险,投资者该如何应对?让我们逐一解读这些指标,并探讨合理的应对策略。一、关键指标详解AHR999囤币指标:由ahr999创建,辅助比特币定投策略。当前值为1.21,处于观望区间,建议谨慎。链接AHR999逃顶指标:AHR999囤币指标的补充,用于识别市场顶部。当前值为2.48,本周

See all articles

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 agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.