简体   繁体   中英

How to fix ‘No such file or directory’ error in PHP

I'm trying to run a php website on my localhost using xampp, but keep getting a 'No such file or directory' this is the warning i get:-

Warning: require_once(D:/wamp/www/ntany3/system/startup.php): failed to open stream: No such file or directory in C:\xampp\htdocs\ntany3\index.php on line 17

Fatal error: require_once(): Failed opening required 'D:/wamp/www/ntany3/system/startup.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\ntany3\index.php on line 17

// Startup
require_once(DIR_SYSTEM . 'startup.php');

I think you could add the path relative to current directory, like this:

require_once(__DIR__. '/system/startup.php');

Put below code in a new file and name it path.php Then upload it to your root directory and go www.example.com.com/path.php

and it'll tell you the full path.

$dir = dirname(__FILE__);
echo "<p>Full path to this dir: " . $dir . "</p>";
echo "<p>Full path to a .htpasswd file in this dir: " . $dir . "/.htpasswd" . "</p>";

Take that path and edit both config files .

Open your httpd.conf (it's apache config file) and edit it:

Where you have:

DocumentRoot "C:/xampp/htdocs"

Change to:

DocumentRoot "D:/wamp/www"

Your errors happen because you are getting the wrong path, this happens because your DocumentRoot in your apache config is pointing to an non-existent path...

I suggest you to use full path... eg:

require_once($_SERVER['DOCUMENT_ROOT'] . "/ntany3/system/startup.php");

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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