1

Im runninng lamp stack locally on my ubuntu 16.04 OS and Im getting problems when including files. My code in index.php:
<?php include('steamauth/steamauth.php'); ?> <?php include('steamauth/userinfo.php');?> my structure is:
index.php steamauth steamauth.php userinfo.php
Im getting the following error:
include(steamauth/userinfo.php): failed to open stream: No such file or directory in /var/www/html/index.php
include(): Failed opening 'steamauth/userinfo.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/index.php
I tried using the full path , adding webroot before the path , changing include_path in php.ini , but nothing seemed to work . what do i do ?

16
  • To test that there isn't a problem with your include, can you try putting the include files in the same folder as the index.php and change the includes to 'steamauth.php' and 'userinfo.php'? Let me know if that works? Commented Oct 27, 2017 at 20:45
  • If that works, put the files back in steamauth and change your includes to "{$_SERVER[DOCUMENT_ROOT]}/steamauth/steamauth.php" and "{$_SERVER[DOCUMENT_ROOT]}/steamauth/userinfo.php". NOTE: You must change the single quotes to double quotes to test this. Let me know if that works. Commented Oct 27, 2017 at 20:49
  • Next, create a test file "index.php" in the steamauth folder and simply put "<?php print "hello"; ?> in it. Then try and load [your domain]/steamauth/index.php in your browser. Does the page load? Commented Oct 27, 2017 at 20:52
  • This also seems to be a duplicate of your question 2 days ago (with a few minor changes). Next time you should add more details to your existing question rather than creating the question again. Commented Oct 27, 2017 at 20:55
  • the thing is i have 1 more file that i didnt mention called navbar.php and i can include it no problem. i can even access the index.php in steamauth folder that you wrote about . But i can not include those 2 files : userinfo.php and steamauth.php although they have the same permissions as the other files. Any ideas ? Commented Oct 27, 2017 at 21:03

1 Answer 1

1

Check folder pemission

Check that the Apache user has access to the include folder.

Check file permissions

Check that the permissions on the files that you are including can be read and executed by the Apache user.

Check PHP settings

It could be caused by one of the following PHP settings:

open_basedir: If this is set PHP won't be able to access any file outside of the specified directory (not even through a symbolic link).

safe mode: If this is turned on restrictions might apply.

Make path absolute

Check that $_SERVER["DOCUMENT_ROOT"] is correctly set for your domain by using:

print $_SERVER["DOCUMENT_ROOT"]; // Add to top of you index.php file. 

Then change your includes to:

$_SERVER["DOCUMENT_ROOT"] . '/sub_folder/file_to_include';

Check for typos and spelling mistakes

Carefully check that what you think you have called the folder and what you are using to include it are spelt the same.

BTW: You can just use the following in your index.php file:

<?php
include('steamauth/steamauth.php');
include('steamauth/userinfo.php');

You also don't need to add the closing ?> at the end of the file - it's actually good practice not to.

Sign up to request clarification or add additional context in comments.

11 Comments

i set them to 777 before. my permissions: drwxrwxrwx 2 www-data www-data 4096 окт 28 00:35 steamauth
i can access navbar.php when it is in the steamauth directory
Check file permissions of the include files can be read and executed by the Apache user.
i did all and the navbar.php file keeps loading with all the methods mentioned above , but the other 2 which are in the same directory dont and it gives me error: include(/var/www/html/userinfo.php): failed to open stream: No such file or directory in /var/www/html/index.php
-rwxrwxr-x 1 misho misho 1569 окт 28 00:35 navbar.php -rwxrwxrwx 1 www-data www-data 1835 окт 27 11:50 steamauth.php -rwxrwxrwx 1 www-data www-data 2510 окт 27 11:50 userInfo.php
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.