Ошибка fatal error require failed opening required

It’s not actually an Apache related question. Nor even a PHP related one.
To understand this error you have to distinguish a path on the virtual server from a path in the filesystem.

require operator works with files. But a path like this

                          /common/configs/config_templates.inc.php

only exists on the virtual HTTP server, while there is no such path in the filesystem. The correct filesystem path would be

/home/viapics1/public_html/common/configs/config_templates.inc.php

where

/home/viapics1/public_html

part is called the Document root and it connects the virtual world with the real one. Luckily, web-servers usually have the document root in a configuration variable that they share with PHP. So if you change your code to something like this

require_once $_SERVER['DOCUMENT_ROOT'].'/common/configs/config_templates.inc.php';

it will work from any file placed in any directory!

Update: eventually I wrote an article that explains the difference between relative and absolute paths, in the file system and on the web server, which explains the matter in detail, and contains some practical solutions. Like, such a handy variable doesn’t exist when you run your script from a command line. In this case a technique called «a single entry point» is to the rescue. You may refer to the article above for the details as well.

maler1988

Перехали на новый сервер, вылетела ошибка.

Fatal error: require_once(): Failed opening required ‘/home/bitrix/www/local/modules/custom.module/lib/exception.php’ (include_path=’.:/usr/share/pear:/usr/share/php’) in /home/bitrix/www/bitrix/modules/main/lib/loader.php on line 313 PHP Fatal error: Uncaught Error: Class ‘BitrixMainDiagExceptionHandlerLog’ not found in /home/bitrix/www/bitrix/modules/main/lib/diag/exceptionhandler.php:350

Проверил все пути вручную, файлы на месте. На сторонних форумах нашёл такое объяснение:

If you break apart your string «.:/usr/share/pear:/usr/share/php» using that character, you will get 3 parts
. (this means the current directory your code is in)
/usr/share/pear
/usr/share/ph
Any attempts to include()/require() things, will look in these directories, in this order.

Не пойму, в моём случае require_once() пытается найти файлы в /usr/share/pear и /usr/share/php ? Какие-то настройки на сервере надо править так? Или я не верно понимаю проблему?


  • Вопрос задан

    более трёх лет назад

  • 5635 просмотров

Пригласить эксперта

/usr/share/pear и /usr/share/php — это альтернативные пути для различных библиотек.
Проверьте права на чтение здесь ‘/home/bitrix/www/local/modules/custom.module/lib/exception.php’

Скорее всего, вы не учитываете регистр файлов, который под Windows не имеет значения, а под другими ОС имеет.
Попробуйте переименовать
/bitrix/modules/main/lib/diag/exceptionhandlerlog.php
в
/bitrix/modules/main/lib/Diag/ExceptionHandlerLog.php
Ну и другие файлы также (если там используется совместимый с PSR-4 автолоадер)

По какой-то загадочной причине пользователи похапе en masse не читают подробное объяснение ошибки, предоставленное интерпретатором РНР, предпочитая гадание на кофейной гуще.

Казалось бы, объяснение прямо под носом: ищем файл в папке local

/home/bitrix/www/local/modules/custom.module/lib/exception.php

в то время как в реальности файлы приложения лежат в папке bitrix

/home/bitrix/www/bitrix/modules/main/lib/loader.php

То есть можно предположить банально неверную конфигурацию приложения.


  • Показать ещё
    Загружается…

13 июн. 2023, в 15:10

25000 руб./за проект

13 июн. 2023, в 14:58

40000 руб./за проект

13 июн. 2023, в 14:45

3500 руб./за проект

Минуточку внимания

Comments

@andremaha

Seldaek

added a commit
to composer/getcomposer.org
that referenced
this issue

Mar 7, 2012

@Seldaek

Seldaek

added a commit
to composer/getcomposer.org
that referenced
this issue

Sep 10, 2012

@Seldaek

igorw

added a commit
to igorw/getcomposer.org
that referenced
this issue

Oct 24, 2012

@igorw

* upstream/master:
  Tweak messages a bit
  Fix padding on small widths
  Fix padding on .fork-and-edit icon
  Add windows installer instructions
  Oops
  Fix ionCube Loader check
  Fix installer for PHP 5.2
  Fix scripts to be quiet
  Add api docs, fixes composer/composer#1163
  Only warn for ioncube <4.0.9, fixes composer/composer#395
  Fixes variable names, only displays once
  Updates installer error messages to include PHP.INI path.

In this comprehensive guide, we will discuss how to solve the fatal error: require_once() failed opening required. This error is commonly encountered by PHP developers and can be frustrating to deal with. Following our step-by-step guide, you will be able to resolve this error quickly and efficiently.

Table of Contents

  1. Understanding the Error
  2. Common Causes of the Error
  3. Step-by-Step Solution
  4. FAQs
  5. Related Links

Understanding the Error

The require_once() function is used to include a PHP file in another PHP file. It ensures that the included file is only included once during the execution of the script. If the file cannot be found or opened, the require_once() function will trigger a fatal error and halt the execution of the script.

The error message might look something like this:

Fatal error: require_once(): Failed opening required 'path/to/your/file.php' (include_path='.:/usr/local/php/pear') in /home/user/public_html/index.php on line 10

In this guide, we will focus on resolving the «Failed opening required» part of the error message.

Back to top ↑

Common Causes of the Error

The «Failed opening required» error is usually caused by one of the following reasons:

  1. The file path specified in the require_once() function is incorrect.
  2. The file you are trying to include does not exist or has been deleted.
  3. The file permissions are incorrect, preventing the file from being accessed.
  4. The PHP include_path configuration is incorrect.

Back to top ↑

Step-by-Step Solution

Follow these steps to resolve the «Failed opening required» error:

Step 1: Verify the File Path

First, check if the file path specified in the require_once() function is correct. Ensure that you are using the right path, either absolute or relative, to the file you want to include.

For example, if your file structure looks like this:

- public_html/
    - index.php
    - includes/
        - config.php

Your require_once() function in the index.php file should look like this:

require_once('includes/config.php');

Step 2: Check if the File Exists

Make sure the file you are trying to include actually exists. Double-check the file’s location and verify that it has not been accidentally deleted or moved.

Step 3: Verify File Permissions

Check the file permissions of the file you are trying to include. The file should have read access for the user running the PHP script. You can change the file permissions using an FTP client or a command-line interface.

For example, to set the correct file permissions using the command line, navigate to the directory containing the file and run the following command:

chmod 644 config.php

Step 4: Check PHP include_path

If you have checked the file path, verified that the file exists, and ensured that the file has the correct permissions, but you are still encountering the error, the issue might be with the PHP include_path configuration.

You can check the current include_path by creating a new PHP file with the following content:

<?php
phpinfo();
?>

Run the script and look for the include_path entry in the «PHP Core» section. If the include_path is incorrect, you can change it in your php.ini file or by using the set_include_path() function in your PHP script.

After following these steps, the «Failed opening required» error should be resolved.

Back to top ↑

FAQs

1. What is the difference between require_once() and include_once()?

The main difference between require_once() and include_once() is the behavior when the specified file cannot be found or opened. require_once() triggers a fatal error and halts the script execution, while include_once() triggers a warning and continues to execute the script.

2. When should I use require_once() instead of include() or require()?

You should use require_once() when you want to include a file that contains important functions or configurations that your script relies on, and you want to ensure that the file is only included once during the script execution.

3. Can I use a URL in the require_once() function?

No, you cannot use a URL in the require_once() function. It only works with local file paths.

4. What are the security risks of using require_once()?

The security risks of using require_once() are minimal if you use it to include your own files. However, if user input is used to determine the file to include, it can lead to a security vulnerability called «Local File Inclusion (LFI).» Always validate and sanitize user input before using it in your require_once() function.

5. How can I debug require_once() issues?

To debug require_once() issues, you can use the following techniques:

  1. Use the file_exists() function to check if the file exists before including it.
  2. Use the is_readable() function to check if the file is readable before including it.
  3. Use the error_reporting() function to enable error reporting and display errors.

Back to top ↑

  1. PHP: require_once — Manual
  2. PHP: include_once — Manual
  3. Understanding PHP File Permissions and Ownership
  4. PHP: set_include_path — Manual
  5. PHP: Local File Inclusion (LFI) — OWASP

Back to top ↑

I’m getting the following errors on my WordPress site

Warning: require(/home/[site]/public_html/wp-includes/load.php): failed to open stream: No such file or directory in /home/[site]/public_html/wp-settings.php on line 19

Warning: require(/home/[site]/public_html/wp-includes/load.php): failed to open stream: No such file or directory in /home/[site]/public_html/wp-settings.php on line 19

Fatal error: require(): Failed opening required '/home/[site]/public_html/wp-includes/load.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/[site]/public_html/wp-settings.php on line 19

I’ve been troubleshooting for a few days but could really use some help.

File permissions:

wp-settings.php: 644

wp-config.php: 444

wp-includes: 755

wp-includes/load.php: 644

Anyone know what it could be? I’ve tried manually upgrading the files(deleting the old wp-files and updating), but still nothing. PHP version is 7.

Thanks!

asked Jan 21, 2018 at 16:22

Darthmaul's user avatar

1

I think there is a permission issue with these files
Reset the permissions or overwrite it from a fresh install. But be sure that it’s the same version.

All files should be 664.
All folders should be 775.
wp-config.php should be 660.

answered Jan 21, 2018 at 16:32

SWestphal's user avatar

4

Try uploading «load.php» in binary transfer mode.

Deactivate or delete plugins and try.

answered Jan 21, 2018 at 18:48

SWestphal's user avatar

1

Понравилась статья? Поделить с друзьями:
  • Ошибка fatal error out of memory
  • Ошибка fatal error on startup
  • Ошибка fatal error maximum execution time of
  • Ошибка fatal error loading pixel shader
  • Ошибка fatal error has occurred this connection is terminated