문제

This is my first post here and I hope I'm doing the right way.

I installed apache2 in my ubuntu 14.04 local machine for studying purposes and all my files are in my home public_html folder.

When I try to access a site like localhost/~{user}/test/index.php everything works fine, but when I try to access the same site with localhost/home/{user}/public_html/test/index.php I get the following error:

The requested URL /home/{user}/public_html/test/index.php was not found on this server.

Apache/2.4.7 (Ubuntu) Server at localhost Port 80

I tried to use:

$echo dirname(__FILE__);

But it returns /home/{user}/public_html/test.

So why can't I access the same file with both paths?

도움이 되었습니까?

해결책

Lets' consider the second URL:

http://localhost**/home/user/test/index.php**

If you look in Apache's configuration you will notice that there is a directive called "DocumentRoot". This directive specifies where apache will map the initial "/" in the URL to.

So, let's say that the DocumentRoot is set to /var/www/htdocs. When you request the path /home/user/test/index.php it will actially go looking for .... /var/www/htdocs/home/user/test/index.php, which I'm assuming doesn't exist. See DocumentRoot

Ok, so why does the first one work? Because of Apache's UserDir module. This little module checks the "/~user/test/index.php" part of the link. The tilde (~) is what does it :). It then maps /~user/ to /home/user/, thus Apache will look for the file at /home/user/test/index.php. Voilá.

Hope this helps.

다른 팁

I have the same problem. apache has been started. i stop apache and start nginx :

sudo service apache2 stop

sudo service nginx start
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top