How to change document root of a domain on a Linux server

How to change document root of a domain on a Linux server

How to change document root of a domain on a Linux server

To change the document root of a domain on a Linux server, you’ll typically be working with a web server like Apache or Nginx. Here are the steps for both:

🔹 For Apache

  1. Locate the Virtual Host File
    The config files are usually in:
    • /etc/httpd/conf/httpd.conf (CentOS/RHEL)

    • /etc/apache2/sites-available/ (Ubuntu/Debian)

      2. Edit the Virtual Host Configuration

       

Look for:

3. Change the DocumentRoot Path
For example:

4. Update Permissions
Ensure the new directory has the correct permissions:

5. Enable the Site & Restart Apache

🔹 For Nginx

  1. Locate Your Server Block
    Typically in:

    • /etc/nginx/sites-available/ (Debian/Ubuntu)

    • /etc/nginx/conf.d/ or /etc/nginx/nginx.conf (CentOS/RHEL)

  2. Edit the Server Block

Look for:

3. Change the Root Directive
For example:

4. Update Permissions

5. Test and Reload Nginx

After successfully applying the above steps, you should be able to get your domain document root changed.

Note that depending on the directory you changed to domain document root, it will load.

Create Account



Log In Your Account