Thứ Tư, 21 tháng 5, 2014

// // 2 comments

Cài đặt và cấu hình userdir

KHởi động apache userdir
Đăng nhập bằng tài khoản root:
su -
## OR ##
sudo -i
KHởi động userdir 
#a2enmod userdir
 Chỉnh sửa nội dung các file sau:
root@serverwise:~# cat /etc/apache2/mods-enabled/userdir.conf
<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>
Tiếp tục chỉnh sửa nội dung:
# 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 restart
TẠo thư mục public_html:
#mkdir /home/testuser/public_html
Set quyền truy cập:
## home directory ##
chmod 711 /home/testuser
## public_html directory ##
chown testuser:testuser /home/testuser/public_html
chmod 755 /home/testuser/public_html
Truy cập bằng url: http://localhost/~testuser/ trên trình duyệt

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

2 nhận xét:

  1. AllowOverride All <~~ userdir file config
    AllowOverride All <~~ Apache

    CHo phep htaccess

    Trả lờiXóa
  2. Khoi dong apache truoc, roi enable mod sau:
    root@serverwise:~# service apache2 restart
    [ ok ] Restarting web server: apache2 ... waiting .
    root@serverwise:~# a2enmod rewrite
    Module rewrite already enabled

    Trả lờiXóa

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.