Cpanel логи ошибок php

PHP error logs are one of the most useful tools for diagnosing web hosting issues. It’s often difficult to find the cause of unexpected behavior in WordPress® and other PHP applications. PHP error logs, including WordPress logs,  can help you to spot problems and identify the offending plugin, theme, or custom code. 

In this article, we describe what PHP error logs are and why they’re useful, before explaining how to use cPanel & WHM to activate and configure both WordPress logs and the PHP runtime’s logging functionality.  

What is a PHP Error Log?

A PHP error log lists warnings and error messages, which are generated by the language runtime and saved to a file. WordPress is written in PHP, so it handles WordPress’s error messages and logging. 

Errors occur for lots of reasons. A line of code might have a typo in it, or the code might be fine, but something unexpected happens when it’s executed. Either way, the developers want to let you know, so they write code to log a message to a file. Error logs are a time-ordered list of these messages. 

Error logs are incredibly useful for figuring out why WordPress isn’t behaving as you think it should. If it’s consuming excessive server resources, a plugin is broken, or pages don’t load, the logs can tell you why. If you’re in a “White Screen of Death” situation where WordPress isn’t working at all, the logs might be the only way to see what’s going on under the hood.

Before you can troubleshoot with logs, you’ll need to tell WordPress or PHP to start logging. Error logs are off by default because logging consumes server resources.  They can also be a security risk if the wrong person sees them; logs sometimes have clues about potential vulnerabilities. 

We’re going to look at two approaches to configuring error logging in cPanel. They are:

  • Activating WordPress logging via the wp-config file. 
  • Activating PHP logging via the php.ini file. 

Both can be done quickly in cPanel & WHM. 

WordPress Error Logs with Wpconfig.php

The wp-config.php file contains WordPress’s configuration, and, with a couple of lines of code, you can turn on debugging mode and tell WordPress to write errors to a log. 

First, fire up cPanel’s File Manager, which you will find in the main page’s Files section. 

Your WordPress site is probably in the root or a subdirectory of public_html, although it might be somewhere else if your server has a non-standard configuration.

Click on the directory containing the site and find the wp-config.php file in the right-hand pane. Select it and click Edit in the menu bar. 

The file opens in cPanel’s text editor. Scroll down to the line that reads: 

/* That's all, stop editing! Happy blogging. */

Add the following code above that line and then click Save:

define( 'WP_DEBUG', true );
	define( 'WP_DEBUG_LOG', true );
	define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

We’re telling WordPress to turn on debugging mode and output error messages to the log file. We also tell it not to display errors in the interface, because that’s not a good look for a production website. 

WordPress will now write error messages to a file called error.log in the wp-content directory, which is in the root directory of your WordPress site. 

You can use the cPanel File Manager and text editor to open this file and see the error messages. The most recent messages are at the bottom of the file. They tell you the type of error and which code triggered it, allowing you to track down the plugin or theme file responsible. 

When you have diagnosed the problem, be sure to delete the logging code you added to the configuration file. The error file will keep growing and will eventually consume a large chunk of your disk allocation. 

How To Log PHP Errors Beyond WordPress

The method outlined above is great if you want to manage logging through WordPress, but what if you want to log errors for other content management systems and applications? 

To achieve widespread logging, you can add code to the php.ini file, which you can edit in cPanel’s MultiPHP INI Editor. You will only be able to edit this file if your web hosting environment allows it. 

Select the Editor tab and then a location in the dropdown menu. cPanel displays the existing configuration file, which may be blank. 

Add the following to the text entry field and click Save

log_errors = true
error_log = /home/user1/logs/error.log
display_startup_errors = false
display_errors = false
html_errors = false
error_reporting = E_ALL
log_errors_max_len = 0

These directives tell the runtime to log errors to the file designated with error_log, which you should change to your preferred location. We’ve turned off startup errors because they are rarely relevant for debugging misbehaving applications. We also instruct PHP not to display errors in web pages because we don’t want users to see them. 

Click Save, and PHP will start to log errors to the file you chose. You can access the log via the cPanel File Manager or by logging in with SSH. 

The php.ini directives we used are suitable for most web servers, but you can use many other directives to configure PHP. To learn more, take a look at the list of php.ini directives in the language’s documentation and our MultiPHP INI Editor documentation.

Once you have used the logs to figure out your issue’s source, remove the code you just added or change the log_errors value to false to deactivate logging.

Efficient Issue Resolution with PHP Error Logs and cPanel

Logs are an enormously useful tool for diagnosing and fixing unexpected behavior in WordPress sites and other web applications. With cPanel & WHM, it’s straightforward to activate and deactivate logging, reducing the time you spend hunting down elusive issues. 

As always, if you have any feedback or comments, please let us know. We are here to help in the best ways we can. You’ll find us on Discord, the cPanel forums, and Reddit.

cPanel comes with an error log section that allows you to view errors generated by your website. In this article, we will review how to view your error logs for both Apache and PHP from within cPanel. For more information, we have a full guide that also lists the locations of cPanel logs for access, Apache, email, error, ftp, mysql, and WHM.

  • What is the Error Log?
  • cPanel Error Log
  • How do I Read Error Log?
  • PHP Error Logging
Don’t have time to read the article? Watch our walk-through video.

What is the Error Log?

cPanel states, “This function will display the last 300 errors for your site. This can be very useful for finding broken links or problems with missing files. Checking this log frequently can help keep your site running smoothly.” What this means is when your site is visited by someone, the server receives a request from that visitors browser and location to your server. When the visitor hits a section of your website and they cause an error, the error log will log the date, time, IP , page the error occurred and so forth. These errors could be caused for a number of reasons. Below are a few reasons why errors would be thrown.

  • Page Alias Changed (SEF URL’s or Permalinks changed)
  • File was deleted or renamed
  • SpamBots trying to manipulate a url
  • Missing error pages or robots.txt
  • Menu links changed with out redirecting
  • Old URLS cached in search engines

There are many reasons your site could have errors. Its a good idea to check you error log frequently to fix web crawler problems that effect your search engine ranking and website functionality.

You can find your cPanel Error log by following the steps below.

  1. Login into your cPanel.
  2. Go to Metrics > Errors.
    cPanel error log icon
  3. Your error log will display in the box. cPanel will display the last 300 errors through the Error Log interface.
    cPanel error log sample

How do I read error log?

Below is an excerpt of a typical error in the cPanel Error log. There are many different error types you may receive. The below is an error on a missing file with a brief description.

Date and Time logged Type Visitor IP Address [Fri May 17 21:07:47 2013] [error] [client 122.96.59.103] Location of the Error File does not exist: /home/userna5/public_html/400.shtml, Domain Referrer referer: https://example.com/?m=200911

PHP Error Logging

By default, InMotion disabled PHP error logging on all servers. In order to troubleshoot your PHP code, PHP errors can be enabled to display and log errors using your local php.ini file or ini_set() in a specific PHP file. Then, any errors will be logged within a file labeled error_log in the same directory that the script produced the error. For more information, see our full guide on How to Display and log errors for PHP.

php Error Log Sample

Within the file, you will see each error that was logged on a separate line. First, it will list the date and time that the error was produced, then the actual error. Reviewing this periodically will help you provide the best experience possible for your visitors to ensure that they are not seeing repeat errors on your website.

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 the PHP error log is stored would be a complicated bit of work. 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 distribution of Linux), including settings within Windows and Linux that affect the name and location of the PHP error log.

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. 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(). To view it, create a PHP file containing this:

<?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. That is because the PHP interpreter that runs on a web server is not the same PHP interpreter that runs from the command line, even when the command line is on the same machine as the web server. The answers already posted in here mostly are making an unstated assumption that PHP is running as part of a web server.

Sample output from phpinfo() via web server and web browser

The default for error_log is no value

Default error_log in php running as an Apache mod.

Whatever the value is, it comes from the php.ini files used to configure PHP. There can be many php.ini files. Finding your way among them is confusing at first, but you do not need to deal with this to find your PHP log.

If the output from phpinfo() shows a full path to a file, that is where the log is. You are lucky.

The trick is there usually is not a full path indicated in phpinfo(). When there is not a full path, the location depends on:

  1. Whether error_log is no value. If it is, the log file location will depend on the operating system and the mode PHP is running. 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.

  2. If there is a file name without a path, the location depends on whether the file name has the value syslog. If it syslog, then the PHP error log is injected into the syslog for the server, which varies by Linux distribution. A common location is /var/log/syslog, but it can be anywhere. Even the name of the syslog varies by distribution.

  3. If the name without a path is not syslog, a frequent home for the file is is the document root of the website (a.k.a., website home directory, not to be confused with the home directory for your account).

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.

Enter image description here

Это руководство объяснит, как создать файл журнала ошибок PHP в CPanel для вашего основного доменного имени. Это потребует от вас Добавьте и редактируйте файлы в файловом менеджере, в том числе .htaccess, чтобы следовать в этом руководстве. Если у вас есть проблемы с диагностикой на вашем сайте, это руководство может помочь предоставить еще одну информацию, включив журналы ошибок.

Редактирование вашего .htaccess

Шаг 1. Перейдите к файловому менеджеру в cPanel.

Шаг 2. Выберите папку public_html и папку для вашего домена.

Шаг 3. По умолчанию файл .htaccess скрыт. Нажмите на настройки на верхней правой части страницы, чтобы просмотреть настройки.

Шаг 4. Нажмите на кнопку Сохранить.

Шаг 5. Вернитесь в ваш файловый менеджер, щелкните правой кнопкой мыши файл .htaccess и выберите Изменить.

Шаг 6. Скопируйте и вставьте следующий код в свой файл .htaccess и нажмите Сохранить изменения:

php_flag display_errors выключен
php_flag log_errors Вкл.
php_value error_log /home/Username/public_html/phperror.log

Вам нужно будет изменить имя пользователя выше на имя пользователя CPanel

Это поместит журнал ошибок в файл с именем phperror.log в папке public_html или создайте ее, если файл не существует. Вы можете настроить расположение файла или имя файла, отредактировав путь к файлу.

Шаг 6b: Найдите свое имя пользователя cPanel / FTP на главной странице cPanel в правом верхнем углу главной страницы cPanel.

Вы можете добавить журнал ошибок для каждого домена, создавая отдельный файл .htaccess в корне документа домена.Вы можете объединить их, сохраняя путь к файлу, как показано выше для файла PHPPERROR.LOG, одинаково.

Проверьте свой журнал ошибок

Шаг 1. Создайте новый файл PHP с именем errortest.php в папке public_html и добавьте этот код, чтобы выдать ошибку:

\ <!? PHP
Функция Fun1 ()
{
ech «Покажите мне ошибку»;
}
Fun2 ();
эхо «фатальная ошибка !!»;
?>

Это даст ошибку из-за неправильного написания echo и вместо этого использования.

Шаг 2. Доступ к файлу с помощью вашего любимого браузера. Например, перейдите в файл из своего домена, EX. domain.com/errortest.php.

Это приведет к вошению ошибки в вашем файле ~ / pubblic_html / errortest.php, и на этой странице ничего не появится.

Просмотр файлов ошибок

Опция 1. Щелкните правой кнопкой мыши файл phperror.log и выберите просмотр.

Ваш PHP Error.Log должен выглядеть так, когда оно было создано.

Вариант 2. Вы также можете просматривать файл PHPPERROR.LOG, перейдем к ‘domain.com/phperror.log’ (заменить ‘domain.com’ с вашим фактическим доменом)

Написано Hostwinds Team  /  сентябрь 20, 2018

How to enable PHP error logging in cPanel

In order to check the PHP error log for your application and find any warnings/errors that are being displayed, firstly you need to make sure that PHP error logging is enabled. To enable PHP error logginig, firstly go to your cPanel and navigate to «Select PHP Version», under the Software menu.

Once you access the «Select PHP Version», you will be displayed with the following options:

Here we will need to go to «Switch to PHP Options» from the right side on the screenshot, so we could enable PHP error logging.

In PHP Options, you will be displayed with the following options:

You will need to click on E_ALL to change it. In this case, it is already enabled.

If you click on E_ALL, you will be displayed with a drop-down menu, from where you can enable it:

To enable error reporting, you need to select E_ALL. Once this option is selected, simply click on the «Apply» button and «Save» from the bottom of this page. 

All new PHP errors and warnings will be written in the root folder of your application in a file named «error_log».

That’s all! Now you learned how to enable error reporting from your cPanel.

Понравилась статья? Поделить с друзьями:
  • Core83 dll ошибка вылетает 1с 0xc0000005
  • Core temp ошибка
  • Copy running config startup config ошибка
  • Copy php ошибка
  • Copperbeard sea of thieves ошибка