Does anyone know how to change the document root of the Apache server? I basically want localhost
to come from /users/spencer/projects
directory instead of /var/www
.
Edit
I ended up figuring it out. Some suggested I change the httpd.conf
file, but I ended up finding a file in /etc/apache2/sites-available/default
and changed the root directory from /var/www
to /home/myusername/projects_folder
and that worked.
You need to change the
DocumentRoot
setting in yourhttpd.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: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.Edit: Apache2 site config files are now typically kept in
/etc/apache2/sites-available/
(Debian, Ubuntu, etc.).For apache2 on Linux Mint 17.3 Cinnamon 64-bit the following works:
In
/etc/apache2/sites-available/
open the000-default.conf
file, and change the Document Root to the absolute path of your directory.sudo vim /etc/apache2/sites-available/000-default.conf
In
/etc/apache2/
openhttpd.conf
, and add a<Directory>
tag referencing your directory and containing the exact same settings as the tag forvar/www
.sudo vim /etc/apache2/apache2.conf
On my machine it looked like this:
Note: In the first step you probably want to change Document Root in the
default-ssl.conf
file as well for SSL purposes. But as far as I can tell this isn't required to get a general development environment running.In apache version 2.4.18 (Ubuntu).
1.go to this file /etc/apache2/apache2.conf search for
<Directory /var/www/>
and replace to your directory ......2.go to /etc/apache2/sites-available/000-default.conf search for
DocumentRoot /var/www/html
and replace to your DocumentRoot....Please note, that this only applies for Ubuntu 14.04 LTS 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:So just do a
and change the following line to what you want:
Also do a
and find this
and change
/var/www/html
to your preferred directoryand save it.
After you saved your changes, just restart the apache2 webserver and you'll be done :)
If you prefer a graphical text editor, you can just replace the
sudo nano
by agksu gedit
.This is for Ubunutu 14.04:
In file
/etc/apache2/apache2.conf
it should be as below without the directory name:and in file
/etc/apache2/sites-available/000-default.conf
you should include the custom directory name i.e. www:If not as above it will give you an error when loading the server:
Forbidden You don't have permission to access / on this server