RHCE Work With Apache HTTPD Web Service Part 2–How To Change Apache HTTPD Default Document Directory Dev Ops Lanka

How To Change Apache HTTPD Default Document Directory

Everybody is know /var/www/html is the default directory for the apache httpd.so lets chage the default directory.Lets create new folder inside /home/mydir

mkdir -p /home/mydir

And edit

nano /etc/httpd/conf/httpd.conf

Now we create index.html file inside /home/mydir/ folder

This is content for index file

This is new Directory

Now we restart apache httpd for new configuration

systemctl restart httpd

This should display the content This is new Directory

But this showing error Forbidden

because of context type does not match for new folder.normally  /var/www/html is universal folder for the apache httpd .lets check /var/www/html context type

ls -Z  /var/www/html

If the system is selinux enforcing mod it will consider about the context type.

lets take look at what is the context type of the new directory

new context type is not for httpd

so we can change context type in two ways.

first one is chcon but this will lost if you relabel the file system i will explain both ways but second one is semanage this will persist

chcon method.you do not need to memorize the syntax

search man page there is example and change example as you wish

man -k  semanage

this will show all the man pages related to the chcon

then

man semanage-fcontext

there is example how to with semanage copy context type  httpd_sys_content_t

change the context

chcon -t httpd_sys_content_t  /home/mydir/index.html

and open web browser

server0.example.com

Ok now we delete the /home/mydir folder and create /home/mydir/index.html with new content “Hello Sameera”

Now lets to with semanage-fcontext

Check context type with

ll -Z  /home/mydir

it is not httpd context type

Copy the example

man semanage-fcontext

 

semanage fcontext -a -t httpd_sys_content_t “/web(/.*)?”

change example as below

semanage fcontext -a -t httpd_sys_content_t “/home/mydir/.*)?”

Then

restorecon -R -v /home/mydir

Then it changed the context type to httpd

Check context type

ll -Z /home/mydir

now lets navigate to server0.example.com .This should show the new content

2 thoughts on “RHCE Work With Apache HTTPD Web Service Part 2–How To Change Apache HTTPD Default Document Directory Dev Ops Lanka

Leave a Reply

Your email address will not be published. Required fields are marked *