简体   繁体   English

PHP 在哪里存储错误日志? (PHP 5、Apache、FastCGI 和 cPanel)

[英]Where does PHP store the error log? (PHP 5, Apache, FastCGI, and cPanel)

I am on shared hosting and have cPanel , Apache, and PHP is run by FastCGI .我在共享主机上,有cPanel 、 Apache 和 PHP 由FastCGI运行。 Where does PHP store the error log? PHP 在哪里存储错误日志?

Is there another way I can find the error log on a shared hosting environment instead of having to go through entire site structure to look for error_log files?有没有另一种方法可以在共享托管环境中找到错误日志,而不必遍历整个站点结构来查找error_log文件?

I have access to the php.ini file (I am using PHP version 5.2.16).我可以访问php.ini文件(我使用的是 PHP 5.2.16 版)。

PHP stores error logs in /var/log/apache2 if PHP is an apache2 module.如果 PHP 是 apache2 模块,则 PHP 将错误日志存储在/var/log/apache2 Shared hosts are often storing log files in your root directory /log subfolder.共享主机通常将日志文件存储在您的根目录/log子文件夹中。 But...if you have access to a php.ini file you can do this:但是...如果您有权访问php.ini文件,您可以这样做:

error_log = /var/log/php-scripts.log

According to rinogo 's comment: If you're using cPanel, the master log file you're probably looking for is stored (by default) at根据rinogo的评论:如果您使用的是 cPanel,则您可能正在查找的主日志文件(默认情况下)存储在

/usr/local/apache/logs/error_log

If all else fails you can check the location of the log file using如果所有其他方法都失败了,您可以使用以下命令检查日志文件的位置

<?php phpinfo(); ?>

尝试phpinfo()并检查“error_log”

Linux Linux

php --info | grep error 

The terminal will output the error log location.终端会输出错误日志位置。

Windows视窗

php --info | findstr /r /c:"error_log"

The command prompt will output the error log location命令提示符会输出错误日志位置

To set the log location设置日志位置

Open your php.ini and add the following line:打开你的php.ini并添加以下行:

error_log = /log/myCustomLog.log

Thanks @chelmertez , @Boom for these (comments on the question).感谢@chelmertez@Boom (对问题的评论)。

On a LAMP environment the php errors are default directed to this below file.在 LAMP 环境中,php 错误默认指向以下文件。

/var/log/httpd/error_log

All access logs come under:所有访问日志都位于:

/var/log/httpd/access_log

How do find your PHP error log on Linux:如何在 Linux 上找到您的 PHP 错误日志:

eric@dev /var $ sudo updatedb
[sudo] password for eric:
eric@dev /var $ sudo locate error_log

/var/log/httpd/error_log

Another equivalent way:另一种等效方式:

eric@dev /home/eric $ sudo find / -name "error_log" 2>/dev/null

/var/log/httpd/error_log

It appears that by default php does not log errors anywhere, the error_log key in php.ini is commented out in all the install's I've seen.似乎默认情况下 php不会在任何地方记录错误,php.ini 中的error_log键在我见过的所有安装中都被注释掉了。

Generally I:一般我:

  1. look for php.ini files.寻找 php.ini 文件。 locate php.ini . locate php.ini
  2. Search these files for the error_reporting value;在这些文件中搜索error_reporting值;

    Which should be set to whatever amalgamation of php log levels are enough for you.哪个应该设置为 php 日志级别的任何合并对您来说就足够了。 , ,

    Eg: E_ALL & ~E_DEPRECATED & ~E_STRICT例如: E_ALL & ~E_DEPRECATED & ~E_STRICT

  3. Check the error_log value to make sure it points to an actual place and is not commented out.检查error_log值以确保它指向实际位置并且没有被注释掉。

    The default value doesn't give a full path, only a file name, I don't know where this path resolves to normally.默认值没有给出完整路径,只有文件名,我不知道这个路径通常解析到哪里。 Probably /var/log/ .可能/var/log/

It can also be /var/log/apache2/error.log if you are in google compute engine.如果您使用的是 google 计算引擎,它也可以是/var/log/apache2/error.log

And you can view tail like this:你可以像这样查看尾巴:

tail -f /var/log/apache2/error.log

You should use absolute path when setting error_log variable in your php.ini file, otherwise, error logs will be stored according to your relative path.在 php.ini 文件中设置error_log变量时应使用绝对路径,否则错误日志将根据您的相对路径存储。

error_log = /var/log/php.errors

Other solution would be writing simple script which would list all error logs files from directory tree.其他解决方案是编写简单的脚本,该脚本将列出目录树中的所有错误日志文件。

php --info | grep error

This is helpful.这很有帮助。 commented by sjas on question. sjas 对问题发表评论。 so i included it as a answer.所以我把它作为答案。

NGINX usually stores it in /var/log/nginx/error.log or access.log. NGINX 通常将其存储在 /var/log/nginx/error.log 或 access.log 中。 (On Ubuntu in any case) (无论如何在 Ubuntu 上)

If you have build Apache and PHP from source, then the error logs by default is generated at your ${Apache install dir}/logs/error_log ie generally /usr/local/apache2/logs/error_log .如果您从源代码构建 Apache 和 PHP,那么默认情况下错误日志会在您的${Apache install dir}/logs/error_log即通常为/usr/local/apache2/logs/error_log Else, if you have installed it from repository, you will find it at /var/log/apache2/error_log .You can set the path in your php.ini also and verify it by invoking phpinfo() .否则,如果您已从存储库安装它,您将在/var/log/apache2/error_log找到它。您也可以在php.ini设置路径并通过调用phpinfo()验证它。

The best way is to look in your httpd.conf file and see what the default is.最好的方法是查看您的 httpd.conf 文件并查看默认值。 It could also be overridden by your specific virtual host.它也可以被您的特定虚拟主机覆盖。 I start by looking at /etc/httpd/conf/httpd.conf or /etc/apache2/httpd.conf and search for error_log.我首先查看/etc/httpd/conf/httpd.conf/etc/apache2/httpd.conf并搜索 error_log。 It could be listed as either /var/log/httpd/error_log or /var/log/apache2/error_log but it might also be listed as simply logs/error_log .它可以被列为 /var/log/httpd/error_log 或/var/log/apache2/error_log但它也可能被列为简单的logs/error_log

In this case it is a relative path, which means it will be under /etc/httpd/logs/error_log .在这种情况下,它是一个相对路径,这意味着它将在/etc/httpd/logs/error_log If you still can't find it check the bottom of your httpd.conf file and see where your virtual hosts are included.如果您仍然找不到它,请检查您的 httpd.conf 文件的底部并查看您的虚拟主机的位置。 It might be in /etc/httpd/conf.d/<- as "other" or "extra".它可能在 /etc/httpd/conf.d/<- 中作为“其他”或“额外”。 Your virtual host could override it then with ErrorLog "/path/to/error_log".您的虚拟主机可以使用 ErrorLog "/path/to/error_log" 覆盖它。

When configuring your error log file in php.ini, you can use an absolute path or a relative path.在 php.ini 中配置错误日志文件时,可以使用绝对路径或相对路径。 A relative path will be resolved based on the location of the generating script, and you'll get a log file in each directory you have scripts in. If you want all your error messages to go to the same file, use an absolute path to the file.将根据生成脚本的位置解析相对路径,并且您将在脚本所在的每个目录中获得一个日志文件。如果您希望所有错误消息都转到同一个文件,请使用绝对路径文件。

See more here: http://www.php.net/manual/en/ref.errorfunc.php#53025在此处查看更多信息: http : //www.php.net/manual/en/ref.errorfunc.php#53025

如果你使用 php5-fpm 日志默认应该在

/var/log/php5-fpm.log

无论你想在哪里,如果你将它设置为你的函数调用: error_log($errorMessageforLog . "\\n", 4, 'somePath/SomeFileName.som');

Search the httpd.conf file for ErrorLog by running cat <file location> | grep ErrorLog通过运行cat <file location> | grep ErrorLog在 httpd.conf 文件中搜索ErrorLog cat <file location> | grep ErrorLog cat <file location> | grep ErrorLog on the command line.命令行上的cat <file location> | grep ErrorLog For example:例如:

$ cat /etc/apache2/httpd.conf | grep ErrorLog

Output:输出:

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
ErrorLog "/private/var/log/apache2/error_log"

Find the line that starts with ErrorLog and there's your answer.找到以ErrorLog开头的行,这就是您的答案。

Note: For virtual hosts, you can edit the virtual hosts file httpd-vhosts.conf to specify a different log file location.注意:对于虚拟主机,您可以编辑虚拟主机文件httpd-vhosts.conf以指定不同的日志文件位置。

cPanel Error logs are located in: cPanel 错误日志位于:

/usr/local/cpanel/logs/ /usr/local/cpanel/logs/

/usr/local/apache/logs/ /usr/local/apache/logs/

By default Apche logs are located inside:默认情况下,Apche 日志位于:

/var/log/apache /var/日志/阿帕奇

or或者

/var/log/apache2 /var/log/apache2

If anyone is using custom log location then you can check it by running this command:如果有人正在使用自定义日志位置,那么您可以通过运行以下命令来检查它:

cat /etc/apache2/ conf /httpd.conf | cat /etc/apache2/ conf /httpd.conf | grep ErrorLog grep 错误日志

If you are getting error that apache2 directory does not exist then you can run this command to find correct location by:如果您收到 apache2 目录不存在的错误,那么您可以运行此命令以通过以下方式找到正确的位置:

whereis apache阿帕奇在哪里

or或者

whereis apache2 apache2 在哪里

something like this :像这样:

sudo locate error.log | xargs -IX grep -iH "errorlog" X

or或者

sudo locate error_log | xargs -IX grep -iH "errorlog" X

or或者

sudo find / -iname "error?log" 2>/dev/null | xargs -IX grep -iH "errorlog" X
  1. you can go in File Manager check logs folder.您可以进入文件管理器检查日志文件夹。
  2. check Log file in public_html folder.检查 public_html 文件夹中的日志文件。
  3. check "php phpinfo()" file where log store.检查日志存储的“php phpinfo()”文件。

You are on share environment and cannot find error log, always check if cPanel has option Errors on your cPanel dashboard.您在共享环境中找不到错误日志,请始终检查 cPanel 仪表板上是否有错误选项。 If you are not being able to find error log, then you can find it there .如果您无法找到错误日志,那么您可以在那里找到它。

On cPanel search bar, search Error, it will show Error Pages which are basically lists of different http error pages and other Error is where the error logs are displayed.在 cPanel 搜索栏上,搜索 Error,它会显示 Error Pages,它基本上是不同 http 错误页面的列表,其他 Error 是显示错误日志的地方。

Other places to look on shared environment: /home/yourusername/logs /home/yourusername/public_html/error_log查看共享环境的其他地方:/home/yourusername/logs /home/yourusername/public_html/error_log

对于 centos 8 var/log/httpd/error_log

You can see the php errors for an account under:您可以在以下位置查看帐户的 php 错误:

/home/username/logs/domain_tld.php.error.log

You can set php error log globally and locally.您可以在全局和本地设置 php 错误日志。

  1. Globally through WHM:通过 WHM 在全球范围内:

    • WHM -->> MultiPHP INI Editor --> "Editor Mode" WHM -->> MultiPHP INI 编辑器 --> “编辑器模式”
    • Select the version of PHP you would like to set the error log选择您要设置错误日志的 PHP 版本
    • Edit the parameter error_log.编辑参数 error_log。 error_log = "/some/path" Change the filename to the desired error log file error_log = "/some/path" 将文件名更改为所需的错误日志文件
    • Save changes保存更改
  2. Locally though cPanel:在本地通过 cPanel:

    • CPanel -->> MultiPHP INI Editor --> "Editor Mode" CPanel -->> MultiPHP INI 编辑器 --> “编辑器模式”
    • Select the version of PHP you would like to set the error log选择您要设置错误日志的 PHP 版本
    • Edit the parameter error_log.编辑参数 error_log。 error_log = "/some/path" error_log = "/一些/路径"
    • Change the filename to the desired error log file将文件名更改为所需的错误日志文件

    Home directory will set the option for all domains, addons, and subdomains configured on the account A specific domain will limit the change to that domain, or, in the case of an addon domain, the addon and the matching subdomain主目录将为帐户上配置的所有域、插件和子域设置选项一个特定的域将限制更改到该域,或者,在插件域的情况下,插件和匹配的子域

    • Save changes保存更改
  3. If PHP-fpm is enabled:如果启用了 PHP-fpm:

    • WHM --> MultiPHP Manager WHM --> MultiPHP 管理器
    • Find the domain you'd like to change the error log location for找到您要更改错误日志位置的域
    • Click "Edit PHP-FPM"单击“编辑 PHP-FPM”
    • Change the log location in "The error log file (error_log)" relative to the folder "logs" within the user's home directory更改“错误日志文件 (error_log)”中相对于用户主目录中文件夹“logs”的日志位置
    • Save changes保存更改

Wordpress WordPress

Wordpress will direct error_log() messages to /wp-content/debug.log when WP_DEBUG_LOG is set to true.WP_DEBUG_LOG设置为 true 时,Wordpress 会将error_log()消息/wp-content/debug.log/wp-content/debug.log

See Wordpress Documentation for WP_DEBUG_LOG请参阅 WP_DEBUG_LOG 的 Wordpress 文档

For PHP-FPM just search config file for error_log :对于 PHP-FPM,只需在配置文件中搜索error_log

# cat /etc/php-fpm.d/www.conf | grep error_log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log

A bit late and a lot of great answers were given, but mine for some reason stored it in:有点晚了,给出了很多很好的答案,但我出于某种原因将其存储在:

/var/log/php-errors.log

I'm using Ubuntu Server 16.04 and PHP 7.1.28.我使用的是 Ubuntu Server 16.04 和 PHP 7.1.28。

On shared cPanel environment you cannot find error log, if your hosting provider don't provide any option in cPanel Dashboard.在共享 cPanel 环境中,如果您的托管服务提供商未在 cPanel 仪表板中提供任何选项,则您找不到错误日志。 You can search "error" and see if your provider have any.您可以搜索“错误”并查看您的提供商是否有任何错误。

Otherwise normally you will find a file called "error_log" on your public_html file, which have all the php error recorded.否则通常您会在 public_html 文件中找到一个名为“error_log”的文件,其中记录了所有 php 错误。

I can guarantee you, I am not the only person who has been driven to madness at least once in a frustrating search for a log file.我可以向你保证,我不是唯一一个在搜索日志文件的过程中至少有一次发疯的人。 It seems like it should be the easiest thing to find in the whole system.看起来它应该是整个系统中最容易找到的东西。

A definitive guide on where php error log is stored would be a complicated bit of work.关于 php 错误日志存储位置的权威指南将是一项复杂的工作。 The official php manual does not even try to address the whole topic, because there are dependencies on systems outside php, such as the operating system (linux vs. Windows, which distro of linux), including settings within Windows and linux that affect name and location of the php error log.官方的 php 手册甚至没有尝试解决整个主题,因为 php 之外的系统存在依赖关系,例如操作系统(linux vs. Windows,linux 的发行版),包括 Windows 和 linux 中影响名称和php错误日志的位置。

Until someone takes the time to write a complete, cross-system guide, the best you are going to get is general directions where you can inquire.在有人花时间编写完整的、跨系统的指南之前,您将获得的最好的方法是您可以查询的一般方向。 Every php developer has had to endure agony in this pursuit, with one exception.每个 php 开发人员都不得不忍受这种追求的痛苦,只有一个例外。 If you work in one place and the information is provided when you first need it, then you have the information need forever, that is, until you find yourself in a new working environment.如果您在一个地方工作并且在您第一次需要时提供信息,那么您将永远拥有所需的信息,也就是说,直到您发现自己处于一个新的工作环境中。 There are such fortunate people.有这么幸运的人。

If the information is not given to you on a silver platter, so to speak, you have some hunting to do.如果信息不是在银盘上提供给你的,可以这么说,你有一些狩猎要做。 The hunt is not the longest you will face in your career, but it is not the simplest either.狩猎不是你职业生涯中最长的,但也不是最简单的。

As is evident from the many answers already posted, a smart place to begin is the output of phpinfo().从已经发布的许多答案中可以明显看出,一个明智的起点是 phpinfo() 的输出。 To view it, create a php file containing this:要查看它,请创建一个包含以下内容的 php 文件:

<?php
phpinfo();

Either browse to that file or run it from the command line.浏览到该文件或从命令行运行它。 If you do both, you likely will find the error_log is in different places, depending on command line vs. web server use of php.如果两者都执行,您可能会发现 error_log 位于不同的位置,具体取决于命令行与 Web 服务器对 php 的使用。 That is because the php that runs on a webserver is not the same php that runs from the command line, even when the command line is on the same machine as the web server.这是因为在 web 服务器上运行的 php 与从命令行运行的 php 不同,即使命令行与 web 服务器在同一台机器上。 The answers already posted in this thread mostly are making an unstated assumption that php is running as part of a web server.已经在这个线程中发布的答案主要是做出一个未声明的假设,即 php 作为 Web 服务器的一部分运行。
` ` 通过 Web 服务器和 Web 浏览器从 phpinfo() 输出的示例

The default for error_log is no value error_log 的默认没有值php 中的默认 error_log 作为 apache mod 运行。

Whatever the value is, it comes from the php.ini files used to configure php.无论值是多少,它都来自用于配置 php 的 php.ini 文件。 There can be many php.ini files.可以有很多 php.ini 文件。 Finding your way among them is confusing at first, but you do not need to deal with this to find your php log.在它们之间寻找方法起初令人困惑,但您无需处理此问题即可找到您的 php 日志。

If the output from phpinfo() shows a full path to a file, that is where the log is.如果 phpinfo() 的输出显示文件的完整路径,那就是日志所在的位置。 You are lucky.你很幸运。

The trick is there usually is not a full path indicated in phpinfo().诀窍是通常在 phpinfo() 中没有指示完整路径。 When there is not a full path, the location depends on:当没有完整路径时,位置取决于:

  1. Whether error_log is no value . error_log 是否为无值 If it is, the log file location will depend on the operating system and the mode php is running.如果是,日志文件位置将取决于操作系统和 php 运行的模式。 If php is running as an apache module, on linux the log often is in /var/log/apache2/error.log Another likely spot is in a logs directory in your account home directory, ~/logs/error.log如果 php 作为 apache 模块运行,则在 linux 上,日志通常位于 /var/log/apache2/error.log 另一个可能的位置在您帐户主目录中的日志目录中, ~/logs/error.log

  2. If there is a file name without a path, the location depends on whether the file name has the value syslog .如果存在没有路径的文件名,则位置取决于文件名是否具有值syslog If it syslog , then the php error log is injected into the syslog for the server, which varies by linux distro.如果是syslog ,则 php 错误日志被注入到服务器的 syslog 中,这因 linux 发行版而异。 A common location is /var/log/syslog, but it can be anywhere.一个常见的位置是 /var/log/syslog,但它可以在任何地方。 Even the name of the syslog varies by distro.甚至系统日志的名称也因发行版而异。

  3. If the name without a path is not syslog, a frequent home for the file is is the document root of the website (aka, website home directory, not to be confused with the home directory for your account).如果不带路径的名称不是 syslog,则该文件的常用主目录是网站的文档根目录(也称为网站主目录,不要与您帐户的主目录混淆)。

This cheat sheet has been helpful in some situations, but I regret to have to admit it is not nearly universal.这份备忘单在某些情况下很有帮助,但我很遗憾不得不承认它几乎不通用。 You have my condolences.你有我的哀悼。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM