4

I need help solving , what says to be a permission error in the htdocs folder, because i needed to alter them to even add folders in the first place.

This is my init.php file:

<?php
//Start Session
session_start();

//Include Configuration
require_once('config/config.php');

//Helper Function Files
require_once('helpers/system_helper.php');
require_once('helpers/format_helper.php');
require_once('helpers/db_helper.php');

//Autoload Classes
function __autoload($class_name){
require_once('libraries/'.$class_name . '.php');
}
?>

I try to include it via `

When i run my index.php file i get this error:

Warning: require_once(../../htdocs/PHP-Wizard/helpers/system_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9

Fatal error: require_once(): Failed opening required '../../htdocs/PHP-Wizard/helpers/system_helper.php' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9

I tried going one folder up with ../ , but it doesn't work.

I looked around for a similar error to mine, but no luck. They all say No such file or directory in (path).

Could it be that it is the same error, or do i really need to change my permissions, if so, how can i do that?

Edit: When i use include_once('helpers/system_helper.php'); i get this error:

Warning: include_once(helpers/system_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9

Warning: include_once(): Failed opening 'helpers/system_helper.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9

Warning: include_once(helpers/format_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 10

Warning: include_once(): Failed opening 'helpers/format_helper.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 10

Warning: include_once(helpers/db_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 11

Warning: include_once(): Failed opening 'helpers/db_helper.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 11
Nikola Atanasov
  • 605
  • 1
  • 4
  • 11

2 Answers2

7

The problem was indeed the permissions, i'm guessing because i copied the folder.

I fixed it by chmod 777 on all the files in that folder, and now it works fine.

Thank you for your time attempting to help me.

Nikola Atanasov
  • 605
  • 1
  • 4
  • 11
1

I tested using relative paths and it works fine.

<?php

require_once '../test.php';

echo ' you';

Where test.php just contains echo "hello"; resulted in the expected "hello you".

I would guess your problem is with file permissions. Can you check what permissions are on your system_helper.php? It should be at least executable by the user php is running as (usually www-data). I could reproduce your error message by doing a chown root test.php and chmod 600 test.php so I would guess something like

chown www-data: system_helper.php

or

chmod g+rwx system_helper.php

should give you permission to run the script.

mickadoo
  • 3,337
  • 1
  • 25
  • 38
  • this is what it says when i type "ls -ld /opt/lampp/htdocs" drwxrwsrwx 6 root www 4096 Nov 16 23:18 /opt/lampp/htdocs – Nikola Atanasov Nov 25 '15 at 22:56
  • and this is what it says when i type "ls -ld /opt/lampp/htdocs/PHP-Wizard" --drwxr-xr-x 12 xy www 4096 Nov 25 21:34 /opt/lampp/htdocs/PHP-Wizard/ – Nikola Atanasov Nov 25 '15 at 23:02
  • these are my permission for system-helper.php:-rw------- 1 xy xy 1518 – Nikola Atanasov Nov 25 '15 at 23:11
  • I think you could look into [file permissions](https://www.linux.com/learn/tutorials/309527-understanding-linux-file-permissions) but for now if this is just a test project that won't be live it should be safe to run `sudo chmod a+rwx ` on all your project files. `chmod` is for changing file permissions. `a+rwx` means allow `a`ll users to `r`ead, `w`rite and e`x`ecute this file. You can see from your system-helper permissions that only the file owner has read and write permissions. If php is running as a different user then it won't be able to access this file. – mickadoo Nov 25 '15 at 23:47