Bii o ṣe le Mu Module Userdir Apache ṣiṣẹ lori RHEL/CentOS


Itọsọna Olumulo tabi Userdir jẹ modulu Apache kan, eyiti o fun laaye awọn ilana-pato olumulo lati gba nipasẹ olupin ayelujara Apache ni lilo http://example.com/~user/ sintasi.

Fun apẹẹrẹ, nigbati a ba muu module mod_userdir ṣiṣẹ, awọn akọọlẹ awọn olumulo lori eto naa yoo ni anfani lati wọle si akoonu ninu awọn ilana ile wọn pẹlu agbaye nipasẹ olupin ayelujara Apache.

Ninu àpilẹkọ yii, a yoo fihan ọ bi o ṣe le mu awọn olumulo olumulo Apache ṣiṣẹ (mod_userdir) lori RHEL, CentOS, ati awọn olupin Fedora nipa lilo olupin ayelujara Apache.

Itọsọna yii ṣe akiyesi pe o ti tẹlẹ ti fi sori ẹrọ olupin ayelujara Apache lori pinpin Linux rẹ. Ti o ko ba ṣe bẹ, o le fi sii nipa lilo ilana atẹle…

Igbesẹ 1: Fi Server HTTP Apache sii

Lati fi olupin ayelujara Apache sori ẹrọ, lo aṣẹ atẹle lori pinpin Linux rẹ.

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

Igbese 2: Jeki Awọn olumulo Olumulo Afun

Bayi o nilo lati tunto olupin ayelujara Apache rẹ lati lo module yii ni faili iṣeto /etc/httpd/conf.d/userdir.conf , eyiti o ti tunto tẹlẹ pẹlu awọn aṣayan to dara julọ.

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

Lẹhinna jẹrisi akoonu nkan bi isalẹ.

# 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>

Lati gba awọn olumulo diẹ laaye lati ni awọn koodu UserDir wọle, ṣugbọn kii ṣe ẹlomiran, lo eto atẹle ni faili iṣeto.

UserDir disabled
UserDir enabled testuser1 testuser2 testuser3

Lati gba gbogbo awọn olumulo laaye lati ni awọn koodu UserDir wọle, ṣugbọn mu eyi ṣiṣẹ si awọn olumulo diẹ, lo eto atẹle ni faili iṣeto.

UserDir enabled
UserDir disabled testuser4 testuser5 testuser6

Lọgan ti o ti ṣe awọn eto iṣeto bi fun awọn ibeere rẹ, o nilo lati tun bẹrẹ olupin ayelujara Apache lati lo awọn ayipada to ṣẹṣẹ.

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

Igbesẹ 3: Ṣiṣẹda Awọn ilana Olumulo

Bayi o nilo lati ṣẹda itọsọna public_html itọsọna/awọn ilana ni awọn ilana itọsọna olumulo/awọn olumulo. Fun apẹẹrẹ, nibi Mo n ṣẹda public_html itọsọna labẹ itọsọna ile olumulo olumulo tecmint.

# mkdir /home/tecmint/public_html

Nigbamii, lo awọn igbanilaaye ti o tọ lori ile olumulo ati awọn ilana ilana gbangba_html.

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

Paapaa, ṣeto ipo ti o tọ SELinux fun awọn olutọju afun ni Apache (httpd_enable_homedirs).

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

Igbesẹ 4: Idanwo Ifiranṣẹ Olumulo Afun

Ni ipari, ṣayẹwo Userdir nipa sisọ aṣawakiri rẹ si orukọ olupin olupin tabi adiresi IP ti o tẹle pẹlu orukọ olumulo.

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

Ti o ba fẹ, o tun le idanwo awọn oju-iwe HTML ati alaye PHP nipa ṣiṣẹda awọn faili wọnyi.

Ṣẹda /home/tecmint/public_html/test.html faili pẹlu akoonu atẹle.

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

Ṣẹda /home/tecmint/public_html/test.php faili pẹlu akoonu atẹle.

<?php
  phpinfo();
?>

Gbogbo ẹ niyẹn! Ninu àpilẹkọ yii, a ti ṣalaye bii o ṣe le mu ki module module Userdir gba awọn olumulo laaye lati pin akoonu lati awọn ilana ile wọn. Ti o ba ni awọn ibeere nipa nkan yii, ni ọfẹ lati beere ninu abala ọrọ ni isalẹ.