30/11/2020

Change Apache DocumentRoot CentOS 8

Change Apache DocumentRoot

1. Using your text editor (mine will be vim) open the Apache configuration file:

vim /etc/httpd/conf/httpd.conf

2. Find the DocumentRoot section:

3. Lets assume that you want the DocumentRoot to be /home/apache/test. Replace /var/www/html to /home/apache/test in the httpd.conf file.

4. Check if you have SELinux enabled:

getenforce


If the result is enforcing step 5 should be followed, else skip step 5.
5. You must make the context of the directory to be the same as the default apache DocumentRoot.
Create an index.html file if you do not yet have it and paste any html template (will be just for testing).
To check for the context of the default DocumentRoot run the following command:

ls -Z /var/www/html


Paste your content in your new DocumentRoot and run the same command again:

ls -Z /home/apache/test


As it can seen, the context are not the same; therefore to make it the same, run:

chcon -Rt httpd_sys_content_t /home/apache


6. Give ownership of DocumentRoot to Apache:

chown -Rt apache: /home/apache

7. Give permissions:

chmod 755 /home/apache

8. Restart Apache:

systemctl restart httpd

9. Test your website in browser.

One thought on “Change Apache DocumentRoot CentOS 8

Leave a Reply

Your email address will not be published.