Log in

View Full Version : uploading web file outside doc-root not working



mutago
10-05-2013, 02:09 PM
I uploaded my file oustside the root directory while leaving
only index.php in the public_html

here is my directory structure


/home/user
/myweb_application ----> my uploaded files
/access_log
/etc
/mail
/public_htm
/public_ftp
/tmp
/www

Here is how i configured it

1: inside /public_html I have index.php with the content as follow


<?php
require '../myweb_application/web_index.php';
?>

2: Inside /myweb_application i created 2 files for testing along with web_index.php making it 3 php files

web_index.php



<html><body>

<li> <a href="test1.php">Connect test1</a><br><br>
</li>

<li> <a href="test2.php">Connect test2</a><br><br>
</li>


</ul>
</body></html>



test1.php


<html>
I am test 1
</html>


test2.php



<html>
I am test 2
</html>




Finally, the directory becomes

/home/user
/myweb_application ----> my uploaded files
web_index.php
test1.php
test2.php

/access_log
/etc
/mail
/public_htm
index.php

/public_ftp
/tmp
/www



when i load the page as http://example.com
index.php loads web_index.php from outside the root


Look at my problem now

when i click on link CONNECT TEST1 of test1.php from web_index.php it says


The requested URL /test1.php was not found on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.


what could be the problem. Is it because test1.php and test2.php is outside the public_html what about web_index. php that is working. Can someone help to fix that

thank you

Beverleyh
10-05-2013, 02:45 PM
The public_html folder is where you should put all the files/pages associated with your primary domain - I'm not sure why you're creating folders above this. Folders above the public_html directory are usually part of the default server/account setup and are placed outside the public domain for security reasons. That is why you cannot access the pages you've put in the "../myweb_application/" folder in a browser. If you want the pages/other resources to be accessed over the Internet, you should move them all to the public_html folder (or a sub-folder within)

mutago
10-05-2013, 03:14 PM
Thank you so much Berverleyh. I have been reasoning that thing. My brain was just crashing. You see there is a lot of confusion on the internet. This programmer will say this, the other will that thereby creating confusion here and there. You have cleared me now.

I will also like if you could comment on this for setting of file/directory permission
the default settings is as followss
/home/user

/access_log = 750
/etc = 750
/mail = 750
/public_htm =750
/public_ftp =750
/tmp = 750
/www =755

some programmers suggest setting all the permission to be accessible by only the user as 600
some says 640
some says 700

what can you suggest that will be the best way to set the permission on each.

Thank You

Beverleyh
10-05-2013, 03:50 PM
Sadly I am not a server administrator - I'm a website technician by profession - so I mainly leave the server permissions to my server-trained colleagues, or as the web host sets them, depending on whether I'm in my day-time job or working on freelance projects in my spare time. I work mainly on Windows during the day (where it is not my role to change folder permissions - indeed anything security related has to be authorised by the network manager) and after-hours I work on Linux where, via my hosting accounts, I cannot access any folder above the domain root, although I can say with 100% certainty there that the public folder defaults there are 755 and files are 644.

Sorry I could not be of any more help.

mutago
10-05-2013, 11:01 PM
Thank you.

traq
10-06-2013, 05:46 AM
To offer a little bit of an answer to your original question, the reason your link doesn't work is because you file structure no longer matches the structure of your links. From example.com, <a href="link1.php"> will try to load example.com/link1.php, which, in your case, corresponds to /home/user/public_html/link1.php - there's no such file there.

If you want the request to work, you're going to have to tell the server where that file actually is (probably via mod_rewrite and/or a php "routing" script).

In most cases, you don't actually need to do this sort of thing. It can, however, provide an extra layer of security for web applications where you need to have control over which files people access, and how. If you'd like to explain more about what you're trying to accomplish, I might have some more specific answers for you.

mutago
10-08-2013, 07:18 PM
thanks