search
HomeBackend DevelopmentPHP Tutorialphp.ini配置文件详解

  首先看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
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
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

How to Register and Use Laravel Service ProvidersHow to Register and Use Laravel Service ProvidersMar 07, 2025 am 01:18 AM

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Customizing/Extending Frameworks: How to add custom functionality.Customizing/Extending Frameworks: How to add custom functionality.Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.