Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Apache próbuje pobierać index.php z /var/www/html a nie z ~/public_html

10 views
Skip to first unread message

jivan...@poczta.onet.pl

unread,
Jun 16, 2016, 1:21:34 PM6/16/16
to
Używam Apache2 z userdirs pod Ubuntu.
Mam w /home/robert/public_html aplikację PHP (CodeIgniter).
Adres localhost/~robert/index.php działa. Adres localhost/~robert/index.php/announcement/index również.
Chciałbym usunąć index.php z urla. W tym celu zmodyfikowałem plik ~robert/public_html/.htaccess, tzn dopisałem:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt|denial\.html|resources|captcha)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Adres localhost/~robert otwiera się.
Problem: przy próbie otwarcia localhost/~robert/announcement/index mam 404 Not found.
W error.log'u Apache'a mam: script '/var/www/html/index.php' not found or unable to stat.
Nie wiem dlaczego Apache próbuje pobierać index.php z /var/www/html a nie z ~robert/public_html.
Byłbym wdzięczny za pomoc.

Grzegorz Staniak

unread,
Jun 16, 2016, 4:51:53 PM6/16/16
to
Ustawiłeś katalog główny serwera jako bazę rozwiązywania URLi.
Spróbuj:

RewriteBase /~robert/

GS
--
Grzegorz Staniak <gstaniak _at_ gmail *dot* com>

Jivanmukta

unread,
Jun 17, 2016, 4:27:57 AM6/17/16
to
Grzegorz Staniak wrote:
> Ustawiłeś katalog główny serwera jako bazę rozwiązywania URLi.
> Spróbuj:
> RewriteBase /~robert/

Dzięki za pomoc!

PawelS cbrbob(at)wbcd(dot)pl

unread,
Jun 18, 2016, 4:08:43 AM6/18/16
to
jivan...@poczta.onet.pl pisze:
Temat był już poruszany na pl.comp.www,
tak jak napisałeś:
> Na serwerze hostingowym działa OK, problem jest z localhostem.
> Chyba mam coś nie tak Apachem...

Poniżej konfiguracja, która powinna zadziałać:

/etc/httpd/httpd.conf

LoadModule userdir_module modules/mod_userdir.so
<IfModule mod_userdir.c>
# UserDir is disabled by default since it can confirm the presence
# of a username on the system (depending on home directory
# permissions).
#UserDir disable
# To enable requests to /~user/ to serve the user's public_html
# directory, remove the "UserDir disable" line above, and uncomment
# the following line instead:
#UserDir public_html
UserDir WWW
</IfModule>

Opcjonalnie można dodać (zgodnie z zakomentowanym przykładem):
<Directory /home/*/WWW>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
DirectoryIndex index.html index.html.var index.php
</Directory>

Uprawnienia dla katalogów są istotne (SELinux może spowodować 403):
drwxr-xr-x root root system_u:object_r:root_t:s0 //
drwxr-xr-x root root system_u:object_r:home_root_t:s0 /home/
drwx--x--x sp users user_u:object_r:user_home_dir_t:s0 /home/sp/
drwxr-xr-x sp users root:object_r:httpd_sys_content_t:s0 /home/sp/WWW/
-rw-r--r-- sp users root:object_r:httpd_sys_content_t:s0 /home/sp/WWW/index.php

http://example.org/~sp/
http://example.org/~sp/index.php
powyższe wywołania działają zgodnie z tym czego oczekujesz.
0 new messages