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.).
Set root directory on shared hosting for multiple projects
There are a few of "it depends", so I will address the most common setups.
1) How do you define "multiple projects"? Usually that means 1 project == 1 domain.
- Your provider should allow you to setup multiple domains on your web space. Each domain is then linked to 1 directory in your web space. This incurs fees, to pay for each domain.
- Ex. for 1and1 (not a publicity, it just happens have a sites on their setup): www.example1.com points to /example1, www.example2.com points to /example2, and so on. This is setup in their administration interface.
- Doing it like this is equivalent to setting up multiple
VirtualHost
sections.
2) 1 project == 1 domain prefix
- Depending how your hoster does it, you could setup prefix1.example.com points to /site1 and prefix2.example.com points to /site2.
- The user never sees /site1 or /site2 in their address bar.
- Again that is done in the administration interface of your provider.
3) 1 project == 1 sub-directory of one domain, you cannot edit .htaccess
- If you do not mind that, each project could be a sub-directory to the 1 domain you have.
- www.example.com/project1, www.example.com/project2, ...
- The user of your site must type in www.example.com/projectX to get access to the project. It is not hidden in the configuration, the user must explicitly input the project he wants in the browser address bar.
- This does not require any configuration in Apache, or at the hoster level. Simply put the different directories under the
DocumentRoot
directory of the entire domain. - This does not provide a "clean" separation of the sites, but it might be enough for your needs.
4) like 3), but you can edit .htaccess files
- In the
DocumentRoot
directory create a .htaccess file - In there, use
Alias
to tell Apache that requests to a sub-directory in the URL corresponds to another directory on disk, somewhere OTHER than underDocumentRoot
like in 3) - This scenario might be less probable since your hoster will probably only allow you to put content under the
DocumentRoot
anyway. - See https://httpd.apache.org/docs/2.4/mod/mod_alias.html
Have fun!
Related Topics
Mount Smb/Cifs Share Within a Docker Container
How to Compare Two Strings in Dot Separated Version Format in Bash
How to Make a Program Continue to Run After Log Out from Ssh
"Failed to Load Platform Plugin "Xcb" " While Launching Qt5 App on Linux Without Qt Installed
Is There Any API For Determining the Physical Address from Virtual Address in Linux
How to Escape Single Quotes in Bash/Grep
How to Loop Over the Output of a Shell Command
What's the Difference Between "Statically Linked" and "Not a Dynamic Executable" from Linux Ldd
"No Such File or Directory" Error When Executing a Binary
Pipe Only Stderr Through a Filter
Format and Then Convert Txt to CSV Using Shell Script and Awk
How to Measure the Actual Memory Usage of an Application or Process
What Happens to an Open File Handle on Linux If the Pointed File Gets Moved or Deleted
Fastest Way to Find Lines of a File from Another Larger File in Bash
How Are the Fs/Gs Registers Used in Linux Amd64
Hello, World in Assembly Language With Linux System Calls