WHAT'S NEW?
Loading...
Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts
As of CentOS version 7, the mod_rewrite Apache module is enabled by default. We will verify this is the case with the httpd command and -M flag, which prints a list of all loaded modules:
  • httpd -M
Output
. . . remoteip_module (shared) reqtimeout_module (shared) rewrite_module (shared) setenvif_module (shared) slotmem_plain_module (shared) . . .
If the rewrite_module does not appear in the output, enable it by editing the 00-base.conf file with the vi editor:
  • sudo vi /etc/httpd/conf.modules.d/00-base.conf
Next, apply the configuration change by restarting Apache:
  • sudo systemctl restart httpd
With Apache installed and the mod_rewrite module enabled, we're ready to configure the use of a .htaccess file.
  • sudo vi /etc/httpd/conf/httpd.conf
Locate the <Directory /var/www/html> section and change the AllowOverride directive from None to All:
/etc/httpd/conf/httpd.conf
. . .
<Directory /var/www/html>
. . .
 # 
 # AllowOverride controls what directives may be placed in .htaccess files.
 # It can be "All", "None", or any combination of the keywords:
 # Options FileInfo AuthConfig Limit
 #
 AllowOverride All
. . .
</Directory>
. . .
Save and exit the file and then restart Apache to apply the change:
  • sudo systemctl restart httpd
Next, create a .htaccess file in the default document root, /var/www/html, for Apache.
Multiple processing modules (MPM) are responsible for handling web server connections that come to the server. They decide how to bind network ports on the machine, accept requests and dispatch children to handle the request. MPMs are of two types Prefork and Worker. Apache configurations by default ship in with Prefork MPM which is slower than Worker MPM. Switching to Prefork MPM will let us handle more traffic while using less memory.

CentOS 6x:

modify file: /etc/sysconfig/httpd

HTTPD=/usr/sbin/httpd.worker

CentOS 7x:

$ cat /etc/httpd/conf.modules.d/00-mpm.conf

    #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
    LoadModule mpm_worker_module modules/mod_mpm_worker.so
    #LoadModule mpm_event_module modules/mod_mpm_event.so

Restart
Create the home directory while creating a user

useradd -m THEUSERNAME
You can then set the password with:
passwd THEUSERNAME

You can disable logins to the account by setting the shell to /sbin/nologin

usermod -s /sbin/nologin THEUSERNAME


Enable usedir.conf of apache.
1
nano /etc/httpd/conf.d/userdir.conf
Change from:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<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 disabled
  
    #
    # 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>
  
<Directory /home/*/public_html>
        Options Indexes Includes FollowSymLinks
         Require all granted
</Directory>
To:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<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 disabled
  
    #
    # 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>
  
<Directory /home/*/public_html>
        Options Indexes Includes FollowSymLinks
         Require all granted
</Directory>
Then restart apache…
1
systemctl restart httpd.service

Create user’s public_html and assign permissions.
Then here’s the other new things, especially you are using SELinux


2
setsebool -P httpd_enable_homedirs true
chcon -R -t httpd_sys_content_t /home/THEUSERNAME/public_html
Create an index.html file
/home/THEUSERNAME/public_html/index.html

Change ownership 
Run the test by navigating to the following URL from your browser.