How do I change the root directory of an Apache server?
You need to change the DocumentRoot
setting in your httpd.conf
file. Chances are it will be under something like /etc/apache2/conf/httpd.conf
.
Use your favourite editor (I recommend Vim) and look for the DocumentRoot
and change it to /users/spencer/projects
. Also look a little further down for a setting that looks like this:
<Directory "/var/www">
You will also want to change what is in the quotes to your new directory. This gives Apache access to read from that directory when a user makes a request that call on it.
Now restart your Apache service (httpd -k restart
) and you should be good to go.
Apache 2 site configuration files are now typically kept in /etc/apache2/sites-available/
(Debian, Ubuntu, etc.).
I had to edit /etc/apache2/sites-available/default
. The lines are the same as mentioned by RDL.
Please note, that this only applies for Ubuntu 14.04 LTS (Trusty Tahr) and newer releases.
In my Ubuntu 14.04 LTS, the document root was set to /var/www/html
. It was configured in the following file:
/etc/apache2/sites-available/000-default.conf
So just do a
sudo nano /etc/apache2/sites-available/000-default.conf
and change the following line to what you want:
DocumentRoot /var/www/html
Also do a
sudo nano /etc/apache2/apache2.conf
and find this:
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
And change /var/www/html
to your preferred directory and save it.
After you saved your changes, just restart the Apache 2 web server and you'll be done :)
sudo service apache2 restart
If you prefer a graphical text editor, you can just replace the sudo nano
with a gksu gedit
.