Home Backend Development PHP Tutorial php.ini配置文件详解

php.ini配置文件详解

Jun 23, 2016 pm 01:19 PM

  首先看php的配置文件,它在这个路径下

[root@zhangmengjunlinux ~]# vim /usr/local/php/etc/php.ini

  如果你不知道他在哪里的话,我们也有办法去查看

[root@zhangmengjunlinux ~]# /usr/local/php/bin/php -i |head

phpinfo()

PHP Version => 5.3.27


System => Linux zhangmengjunlinux.com 2.6.32-573.el6.i686 #1 SMP Thu Jul 23 12:37:35 UTC 2015 i686

Build Date => Dec 26 2015 22:16:02

Configure Command =>  './configure'  '--prefix=/usr/local/php' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-config-file-path=/usr/local/php/etc' '--with-mysql=/usr/local/mysql' '--with-libxml-dir' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--with-iconv-dir' '--with-zlib-dir' '--with-bz2' '--with-openssl' '--with-mcrypt' '--enable-soap' '--enable-gd-native-ttf' '--enable-mbstring' '--enable-sockets' '--enable-exif' '--disable-ipv6'

Server API => Command Line Interface

Virtual Directory Support => disabled

Configuration File (php.ini) Path => /usr/local/php/etc

Loaded Configuration File => /usr/local/php/etc/php.ini

这个命令也就是phpinfo,可以看到,所调用的php文件在哪里

Loaded Configuration File => /usr/local/php/etc/php.ini

  那我们就去配置php,就是去更改它的配置文件

[root@zhangmengjunlinux ~]# vim /usr/local/php/etc/php.ini 

  这个php是以“;”作为注释符号的,shell是用 #号,那我们常用的配置大概有这么多,首先第一个

disable_functions =eval,assert,popen.passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcrnd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close

disable_functions它默认是空的,要禁用的一些函数,那我们为了安全需要去禁用一些高风险的函数,有哪些上面已经列出来了,可以去看一下官方文档看看有什么含义

第二配置:关于它的错误日志,相关的搜索关键子/display_error

display_error=off默认是off的,如果我们把它改成on,它可以再页面也就是浏览器访问的页面里显示一些错误信息,不妨举个列子,假如把它改成display_error=on

#apachectl graceful 

然后我们故意把php的脚本写错

这一行aaaaaaaa在php看来是不识别的,保存退出

我们去浏览器刷新看一下,有一个错误提示,可以根据看提示找出脚本哪里出了问题



那我们在把display_error=on改成off在来刷新就成了一个白页了,看不到任何的错误,那么这个时候不知道哪里错了怎么办,第一个办法打开display_error,当然你在不知道什么情况的情况下看一看他的状态码按F12刷新出来错误500,还可以curl测试一下,500一般都是PHP的脚本程序有问题,打开display_error=on之后意味着别人能看到你的错误信息,所以我们想到了一种别的方法,首先把display_error=off,然后打开php的错误日志,log_error=on,如果是off我们改成on,另外我们去定义一下具体的error_log所在的路径

error_log=/usr/local/php/logs/php_error_log

那我们先来看一下路径存在不存在

[root@zhangmengjunlinux ~]# ls /usr/local/php/logs/

ls: 无法访问/usr/local/php/logs/: 没有那个文件或目录

[root@zhangmengjunlinux ~]# mkdir /usr/local/php/logs/

[root@zhangmengjunlinux ~]# ls /usr/local/phpp/logs

ls: 无法访问/usr/local/phpp/logs: 没有那个文件或目录

[root@zhangmengjunlinux ~]# chmod 777 /usr/local/php/logs/


没有那个目录我们创建一个,然后呢改它的权限为777,因为错误日志的用户是apache的所以我们要让它可以写,到这里还没有完我们要去配置日志的格式,第三日志的级别

error_reporting = E_ALL & ~E_NOTICE 

保存退出,从新加载apache

[root@zhangmengjunlinux ~]# ls /usr/local/php/logs/

[root@zhangmengjunlinux ~]# !vim

vim /usr/local/php/etc/php.ini

[root@zhangmengjunlinux ~]# apachectl restart

[root@zhangmengjunlinux ~]# vim /data/www/forum.php 

[root@zhangmengjunlinux ~]# apachectl restart

[root@zhangmengjunlinux ~]# ls /usr/local/php/logs/

php_errors.log

[root@zhangmengjunlinux ~]# cat /usr/local/php/logs/php_errors.log 

[02-Jan-2016 16:05:11 Asia/Chongqing] PHP Parse error:  syntax error, unexpected T_STRING in /data/www/forum.php on line 11

那在浏览器页面刷新,虽然我们看不到任何信息,但是我们会在/usr/local/php/logs/下产生了php_error.log有一个日志产生,我们cat一下,看到有错误信息,这就是如何去打开php的错误日志,并且不暴露信息

在一个知识点、open_basedir也是一个安全选项,举几个列子,咱们这个php apache要访问网站,它们去找到一个路径,我们有定义一个路径,比如/data/www,假如网站有一些漏洞,让不法分子获得了一些权限,他可以上传木马,木马可以获得服务器上的一些信息,比如说可以获得一些目录,文件,那么这个时候我们应该想到一个策略,为了以防万一,我们应该把它的权限限制死在某一个目录下,因为我们的网站是在/data/www下。怎么去做呢,就用这个选项

open_basedir=/data/www:/tmp,先来做一个错误的显示open_basedir=/data/www2:/tmp

保存退出, apache从新加载一下,去浏览器刷新一下的时候又是个白页,打开F12也是500,php可以这么做那么apache针对虚拟主机去做一些限制,每一个虚拟主机一open_basedir,每一个站点,每一个域名使用一个open_basedir怎么做它的配置很简单

#vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

 php_admin_value open_basedir "/data/www/:/tmp/"

我们可以把php.ini里的open_basedir给注释掉了,我们需要的是apache里的,它的好处在于我们可以区分不同的虚拟主机

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Apr 08, 2025 am 12:03 AM

There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

Explain the difference between self::, parent::, and static:: in PHP OOP. Explain the difference between self::, parent::, and static:: in PHP OOP. Apr 09, 2025 am 12:04 AM

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

See all articles