Skip to content

Instantly share code, notes, and snippets.

@andreyuhai
Last active January 8, 2019 23:54
Show Gist options
  • Save andreyuhai/298d5c23a7b14561cf3ef7eeae98ca0a to your computer and use it in GitHub Desktop.
Save andreyuhai/298d5c23a7b14561cf3ef7eeae98ca0a to your computer and use it in GitHub Desktop.
apache2 change the root directory to any other

How to change Apache's root directory to some other directory

You'll have to edit apache2.conf and 000-default.conf to change the document root of apache.

The Apache server is installed on var/www/html.This is the default root directory of apache.

Either change the root directory of Apache or move the project to /var/www/html.

To change Apache's root directory, run:

cd /etc/apache2/sites-available

Then open the 000-default.conf file using the command:

nano 000-default.conf

Edit the DocumentRoot option:

`DocumentRoot /path/to/my/project`

Then restart the apache server:

sudo service apache2 restart

If you get Forbidden You don't have permission to access / on this server after changing the root of apache then do follow these steps

  • Find the apache2.conf located in /etc/apache2 and open it using:

      nano apache2.conf
    
  • Use Ctrl+W and search for Directory (It should be in line 153) It should look like this

      <Directory />
          Options Indexes FollowSymLinks
          AllowOverride All
          Require all denied
      </Directory>
    
  • Change it to

      <Directory />
          Options Indexes FollowSymLinks Includes ExecCGI
          AllowOverride All
          Require all granted
      </Directory>
    
  • Restart apache

      sudo service apache2 restart
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment