Search code examples
xampplocalhost

a PHP issue in LOCAL HOST / a "Fatal error: Uncaught Error: Failed opening required" occurs, directory problem


I'm new on this so thanks and sorry in advance

I'm having a issue trying to work with my localhost. (not sure how to describe the problem)

im working with github, making some changes with VSCode, using XAMPP for localhost.

///The problem:

I was working fine with those files before but now there's a new line of code in files .php

"<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/DatesUtilsPolyfen.php');"

When opening the files on my localhost, page is not working and showing this issue.

Warning: require_once(C:/xampp/htdocs/includes/DatesUtilsPolyfen.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\polyfen\sections\hello-bar.php on line 2

Fatal error: Uncaught Error: Failed opening required 'C:/xampp/htdocs/includes/DatesUtilsPolyfen.php' (include_path='\xampp\php\PEAR') in C:\xampp\htdocs\polyfen\sections\hello-bar.php:2 Stack trace: #0 C:\xampp\htdocs\polyfen\index.php(51): include() #1 {main} thrown in C:\xampp\htdocs\polyfen\sections\hello-bar.php on line 2

-Already deal by the moment, the problem is I need to add in "C:/xampp/htdocs/includes/DatesUtilsPolyfen.php'"
to be like this
C:/xampp/htdocs/POLYFEN/includes/DatesUtilsPolyfen.php'

so my localhost need to declarate the root folder inside of "htdocs", meanwhile in liveserver this not required. so the webpage works fine in github and in LiveServer, but now to work in my LocalHost have this problem where the directory path is different. I have no idea is this is a xampp or localhost directory or how to proceed.

Hope someone understand with patient what is my problem. It's not my code, a friend is helping me to learn but he don't know why this happen in my laptop so i need to find out myself.

Thanks

Lean B.

to work in my localHost i need to include a folder in the root. and then take it away to push the changes into github.

This is how it work live "C:/xampp/htdocs/includes/DatesUtilsPolyfen.php'"

and this is how i need to use to work in localHost C:/xampp/htdocs/polyfen/includes/DatesUtilsPolyfen.php'


Solution

  • To fix the problem I needed to create a Vhost for the specific project, another users told me that using one localhost for all is not a good setup. after creating a vhost with WAMP for the specific project, the issue dissapared. Because the project folder was in the end a subfolder of the root (localhost).