Đăng nhập bằng tài khoản root:
su -KHởi động userdir
## OR ##
sudo -i
#a2enmod userdirChỉnh sửa nội dung các file sau:
root@serverwise:~# cat /etc/apache2/mods-enabled/userdir.confTiếp tục chỉnh sửa nội dung:
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
<Directory /home/*/public_html>
#AuthType basic
#Require valid-user
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
</IfModule>
# nano /etc/apache2/mods-available/php5.conf
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
SetHandler application/x-httpd-php-source
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Order Deny,Allow
Deny from all
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
Order Deny,Allow
Deny from all
</FilesMatch>
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
# php_admin_value engine Off
</Directory>
</IfModule>
Hoặc:
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_value engine Off
# </Directory>
#</IfModule>
</IfModule>
Note:
To allow a few users to have UserDir directories, but not anyone else, use the following:
UserDir disabled
UserDir enabled testuser1 testuser2 testuser3
To allow most users to have UserDir directories, but deny this to a few, use the following:
UserDir enabled
UserDir disabled testuser4 testuser5 testuser6
Khởi động lại apache:
#/etc/init.d/httpd restartTẠo thư mục public_html:
#mkdir /home/testuser/public_htmlSet quyền truy cập:
## home directory ##Truy cập bằng url: http://localhost/~testuser/ trên trình duyệt
chmod 711 /home/testuser
## public_html directory ##
chown testuser:testuser /home/testuser/public_html
chmod 755 /home/testuser/public_html
6 (Option). Set proper SELinux settings for Apache homedirs (httpd_enable_homedirs)
setsebool -P httpd_enable_homedirs true
Looks like older SELinux versions needs also following (example CentOS and Red Hat):
chcon -R -t httpd_sys_content_t /home/testuser/public_html
AllowOverride All <~~ userdir file config
Trả lờiXóaAllowOverride All <~~ Apache
CHo phep htaccess
Khoi dong apache truoc, roi enable mod sau:
Trả lờiXóaroot@serverwise:~# service apache2 restart
[ ok ] Restarting web server: apache2 ... waiting .
root@serverwise:~# a2enmod rewrite
Module rewrite already enabled