Giunsa ang Pag-enable sa Apache Userdir Module sa RHEL/CentOS


Ang Direktoryo sa Gumagamit o Userdir usa ka module sa Apache, nga nagtugot sa mga direktoryo nga espesipiko sa user nga makuha pinaagi sa web server sa Apache gamit ang http://example.com/~user/ syntax.

Pananglitan, kung ang mod_userdir module gipagana, ang mga account sa tiggamit sa sistema maka-access sa sulud sa ilang mga direktoryo sa balay sa kalibutan pinaagi sa Apache web server.

Niining artikuloha, ipakita namo kanimo kung unsaon pag-enable ang Apache userdirs (mod_userdir) sa RHEL, CentOS, ug Fedora server gamit ang Apache web server.

Kini nga panudlo nagdahum nga ikaw adunay Apache web server nga na-install sa imong distribusyon sa Linux. Kung wala ka, mahimo nimo kini i-install gamit ang mosunud nga pamaagi…

Lakang 1: I-install ang Apache HTTP Server

Aron ma-install ang Apache web server, gamita ang mosunod nga command sa imong distribusyon sa Linux.

# yum install httpd           [On CentOS/RHEL]
# dnf install httpd           [On Fedora]

Lakang 2: I-enable ang Apache Userdirs

Karon kinahanglan nimo nga i-configure ang imong Apache web server aron magamit kini nga module sa configuration file /etc/httpd/conf.d/userdir.conf, nga na-configure na sa pinakamaayo nga mga kapilian.

# vi /etc/httpd/conf.d/userdir.conf

Dayon balido ang sulod nga sama sa ubos.

# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid.  This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
#
<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 enabled tecmint

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disabled" line above, and uncomment
    # the following line instead:
    #
    UserDir public_html
</IfModule>

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory "/home/*/public_html">
    ## Apache 2.4 users use following ##
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS

## Apache 2.2 users use following ##
        Options Indexes Includes FollowSymLinks        
        AllowOverride All
        Allow from all
        Order deny,allow
</Directory>

Aron tugotan ang pipila ka tiggamit nga adunay UserDir nga mga direktoryo nga ma-access, apan dili ni bisan kinsa, gamita ang mosunod nga setting sa configuration file.

UserDir disabled
UserDir enabled testuser1 testuser2 testuser3

Aron tugotan ang tanang tiggamit nga adunay UserDir nga mga direktoryo nga ma-access, apan i-disable kini sa pipila ka tiggamit, gamita ang mosunod nga setting sa configuration file.

UserDir enabled
UserDir disabled testuser4 testuser5 testuser6

Kung nahimo na nimo ang mga setting sa pag-configure sumala sa imong mga kinahanglanon, kinahanglan nimo nga i-restart ang Apache web server aron magamit ang bag-ong mga pagbag-o.

# systemctl restart httpd.service  [On SystemD]
# service httpd restart            [On SysVInit]

Lakang 3: Paghimo og mga Direktoryo sa Gumagamit

Karon kinahanglan ka maghimo ug public_html direktoryo/direktoryo sa mga direktoryo sa balay sa user/users. Pananglitan, ania ako nagmugna ug public_html nga direktoryo ubos sa tecmint nga direktoryo sa balay sa tiggamit.

# mkdir /home/tecmint/public_html

Sunod, gamita ang saktong permiso sa user home ug public_html directory.

# chmod 711 /home/tecmint
# chown tecmint:tecmint /home/tecmint/public_html
# chmod 755 /home/tecmint/public_html

Usab, ibutang ang husto nga konteksto sa SELinux alang sa mga homedir sa Apache (httpd_enable_homedirs).

# setsebool -P httpd_enable_homedirs true
# chcon -R -t httpd_sys_content_t /home/tecmint/public_html

Lakang 4: Test Enabled Apache Userdir

Sa katapusan, pamatud-i ang Userdir pinaagi sa pagtudlo sa imong browser sa server hostname o IP address nga gisundan sa username.

http://example.com/~tecmint
OR
http://192.168.0.105/~tecmint

Kung gusto nimo, mahimo usab nimo nga sulayan ang mga panid sa HTML ug impormasyon sa PHP pinaagi sa paghimo sa mosunod nga mga file.

Paghimo og /home/tecmint/public_html/test.html file nga adunay mosunod nga sulod.

<html>
  <head>
    <title>TecMint is Best Site for Linux</title>
  </head>
  <body>
    <h1>TecMint is Best Site for Linux</h1>
  </body>
</html>

Paghimo og /home/tecmint/public_html/test.php file nga adunay mosunod nga sulod.

<?php
  phpinfo();
?>

Kana lang! Sa kini nga artikulo, among gipasabut kung giunsa ang paghimo sa module sa Userdir aron tugutan ang mga tiggamit nga magpaambit sa sulud gikan sa ilang mga direktoryo sa balay. Kung adunay ka mga pangutana bahin sa kini nga artikulo, palihug ayaw pangutana sa seksyon sa komento sa ubos.