php.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里的,它的好处在于我们可以区分不同的虚拟主机

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

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-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

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' =>

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.

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

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov
