Apache DocumentRoot won't change - linux

I am trying to change the DocumentRoot in httpd.conf from /var/www to /var/www/shop just so I can be organized. But even when I do that after restarting apache and httpd, I go to localhost and it still points to /var/www. My httpd.conf is basically the same as this file here:
http://www.devside.net/guides/config/linux/httpd-conf
I am running this on Debian.
Any ideas? Thanks

Debian uses various include files and a "site" concept, so httpd.conf isn't normally changed at all (the includes are). You likely changed the value before the "default" site changes it back to /var/www.

Related

How do I set up my public_html dir in EC2? [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
Improve this question
How can I change the document root of the Apache server? I basically want localhost to come from /users/spencer/projects directory instead of /var/www.
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.
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.
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.
This is for Ubuntu 14.04 (Trusty Tahr):
In file /etc/apache2/apache2.conf it should be as below without the directory name:
<Directory /home/username>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And in file /etc/apache2/sites-available/000-default.conf you should include the custom directory name, i.e., www:
DocumentRoot /home/username/www
If it is not as above, it will give you an error when loading the server:
Forbidden You don't have permission to access / on this server
The right way to change directory or run from multiple directories under different port for Apache 2 is as follows:
For Apache 2, the configuration files are located under /etc/apache2 and doesn’t use a single configuration file as in older versions but is split into smaller configuration files, with /etc/apache2/apache2.conf being the main configuration file. To serve files from a different directory we need a new virtualhost conf file. The virtualhost configuration files are located in /etc/apache2/sites-available (do not edit files within sites-enabled). The default Apache installation uses virtualhost conf file 000-default.conf.
Start by creating a new virtualhost file by copying the default virtualhost file used by the default installation of Apache (the one that runs at localhost on port 80). Change into directory /etc/apache2/sites-available and then make copy by sudo cp 000-default.conf example.com.conf, now edit the file by sudo gedit example.com.conf to:
<VirtualHost *:80>
ServerAdmin example#localhost
DocumentRoot /home/ubuntu/example.com
</VirtualHost>
I have deleted the nonimportant lines from the above file for brevity. Here DocumentRoot is the path to the directory from which the website files are to be served such as index.html.
Create the directory from which you want to serve the files, for example, mkdir example.com and change owner and default group of the directory, for example, if your logged in user name is ubuntu change permissions as sudo chown ubuntu:www-data example.com. This grants full access to the user ubuntu and allows read and execute access to the group www-data.
Now edit the Apache configuration file /etc/apache2/apache2.conf by issuing command sudo gedit apache2.conf and find the line <Directory /var/www/> and below the closing tag </Directory>, add the following below:
<Directory /home/ubuntu/example.com>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Now there are two commands to enable or disable the virtualhost configuration files, which are a2ensite and a2dissite respectively. Now since our example.com.conf file uses the same port(80) as used by the default configuration file(000-default.conf), we have to disable the default configuration file by issuing the command sudo a2dissite 000-default.conf and enable our virtualhost configuration file by sudo a2ensite example.com.conf
Now restart or reload the server with command sudo service apache2 restart. Now Apache serves files from directory example.com at localhost on default port of 80.
The a2ensite command basically creates a symbolic link to the configuration file under the site-enabled directory.
Do not edit files within sites-enabled (or *-enabled) directory, as pointed out in this answer.
To change the port and run from multiple directories on different ports:
Now if you need to run the directory on a different port, change the port number from 80 to 8080 by editing the virtualhost file as:
<VirtualHost *:8080>
ServerAdmin user#localhost
DocumentRoot /home/ubuntu/work
</VirtualHost>
and editing /etc/apache2/ports.conf and adding Listen 8080 just below the line Listen 80
Now we can enable the default virtualhost configuration file that runs on port 80 since example.com directory uses port 8080, as sudo a2ensite 000-default.conf.
Now restart or reload the server with command sudo service apache2 restart. Now both the directories can be accessed from localhost and localhost:8080.
If you couldn't find http.conf and followed Nick's way.
Restart Apache using sudo service apache2 restart.
I was working with LAMP and to change the document root folder, I have edited the default file which is there in the
/etc/apache2/sites-available folder.
If you want to do the same, just edit as follows:
DocumentRoot /home/username/new_root_folder
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/username/new_root_folder>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
After this, if you type "localhost" in the browser, it will load the /home/username/new_root_folder content.
For Apache 2 on Linux Mint 17.3 Cinnamon 64-bit, the following works:
In /etc/apache2/sites-available/ open the 000-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 folder /etc/apache2/ open file httpd.conf, and add a <Directory> tag referencing your directory and containing the exact same settings as the tag for var/www.
sudo vim /etc/apache2/apache2.conf
On my machine it looked like this:
<Directory /home/my_user_name/php/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
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).
Open the file /etc/apache2/apache2.conf and
search for <Directory /var/www/> and replace to your directory.
Open file /etc/apache2/sites-available/000-default.conf, search for DocumentRoot /var/www/html and replace it with your DocumentRoot.
In case you are using Ubuntu 16.04 (Xenial Xerus), please update the 000-default.conf file in the directory /etc/apache2/sites-available.
Here →
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/YourFolder
The following applies to Ubuntu 14.04 (Trusty Tahr) and later releases. Make sure to back up following files before making any changes.
Open /etc/apache2/apache2.conf and search for <Directory /var/www/> directive and replace path with /home/<USERNAME>/public_html. You can use * instead of .
Open /etc/apache2/sites-available/000-default.conf and change the DocumentRoot value property from /var/www/html to /home/<USERNAME>/public_html. Also <Directory /var/www/html> to <Directory /home/<USERNAME>/public_html.
Open /etc/mods-available/php7.1.conf. Find and comment the following code
php_admin_flag engine Off
Do not turn the php_admin_flag engine OFF flag on as the reason is mentioned in a comment above the Directive code. Also the PHP version can be 5.0, 7.0 or anything you have installed.
Create public_html directory in home/<USERNAME>.
Restart the Apache service by executing command sudo service apache2 restart.
Test by running a sample script on the server.
I had made the /var/www to be a soft link to the required directory (for example, /users/username/projects) and things were fine after that.
However, naturally, the original /var/www needs to be deleted - or renamed.
If someone has installed LAMP in the /opt folder, then the /etc/apache2 folder is not what you are looking for.
Look for httpd.conf file in folder /opt/lampp/etc.
Change the line in this folder and save it from the terminal.
If you're using Linux Mint (personal opinion, from all distributions this one is making me happy), follow this:
Go to folder /etc/apache2/sites-available and edit file 000-default.conf.
Search for DocumentRoot, example DocumentRoot /var/www/html. You change to your respective directory;
Open a terminal and type: sudo service apache2 restart
In Linux Mint, you go for file /etc/apache2/apache.conf. Replace /var/www with your respective path, and then restart the server (step 3).
That's it.
In Red Hat Linux 7.0: /etc/httpd/conf/httpd.conf

.htaccess access parent folder

I just installed Apaxy for a better and customizable folders views.
It works perfectly, but not in my virtualhost.
Folder (localhost) :
Virtualhost (local.dev.conf, access with local.dev):
<VirtualHost *:80>
ServerName local.dev
DocumentRoot /var/www/local.dev
</VirtualHost>
Unfortunately, in the virtualhost (local.dev) apaxy doesn't work.
I assume it's normal because the server try to find files in local.dev/themes/...
Or my 'themes' folder is in the parent folder, so it is possible to resolve this ?
Here is the .htaccess :
https://justpaste.it/t8yp
 Problem
Apache serves file from the directory /var/www/local.dev.
Solution
Moving the directory /var/www/theme into /var/www/local.dev would work. Nevertheless if, for any reason, you do not want to move theme you can link it using the command ln -s /path/to/theme /path/to/local.dev/theme.
IMHO
Moving the directory would be a better solution as linking it, would force the configuration to enable follow-symlink, as it can be considered as a security issue.

Configure httpd.conf to add new site on Apache Red Hat Linux

I have linux server (Red Hat Enterprise Linux Server release 5.3 (Tikanga)) with apache installed. It is already used for browsing some documents. Now I would like to add a new Directory (with a html page), so whenever the directory is browsed it can display the html page.
But I am not sure of where all to edit the httpd.conf file
Existing httpd.conf:
When I hit the url "http://servername/eng" it displays list of folders.
Now, I want to add a website to this existing, so when user hit the url "http://servername/builds" it should display a html page in the browser.I have added my "index.html" page in location "/var/www/html/builds/"
For this I added the below code to httpd.conf file
Please let me know what all modifications are required in the conf file
You can do it in a few different ways.
Putting index.html in /build
This requires you to have this setting:
DirectoryIndex index.html
(it should be there by default on most platform.)
Also for this to work, rather than putting new <Directory>, you should put the build/ directory in the directory that holds your http://example.com/ files. For instance:
/var/www/example.com/public_html/eng/
/var/www/example.com/public_html/builds/
/var/www/example.com/public_html/builds/index.html
Storing build/ in folder completely unrelated to example.com, but still be able to reach it via example.com/builds
For this, you need to rewrite the URLs so that example.com/builds redirects the user to the final URL. This is most easily achieved through mod_rewrite. You enable mod_rewrite module in your Apache's configuration, make sure that example.com can have .htaccess files through ensuring proper AllowOverride entry in example.com's <Directory> configuration, create /var/www//example.com/public_html/.htaccess (or similar) file, and fill it RewriteEngine On and RewriteRules you need. More on mod_rewrite in the Internet and in the documentation.
Completely separate virtual server, for example builds.example.com/
In this case, what you're looking for are virtual servers. These are not defined in httpd.conf or configuration itself, but usually have dedicated directory.
For example, to add builds.example.com that works for port 80, you'd need to create following entry:
<VirtualHost *:80>
ServerName builds.example.com
DocumentRoot /var/www/builds.example.com/public_html/
</VirtualHost>
Where to put this? Well, it depends on the platform. For Debian, you put this in a new file in /etc/apache2/sites-available/, e.g. /etc/apache2/sites-available/example.com, and symlink to it in /etc/apache2/sites-available (on Debian, you can do this easily with a2ensite <NAME_OF_FILE>. On your platform this procedure might be different, so look it up ("adding virtual servers on " would be a start). After adding virtual servers, you need to reload your Apache configuration.
Please let me know if this satisfies your question, if not, I'll edit the answer accordingly.

Set virtual directory as root in apache

In my linux server my www root of apache server is /var/www/html, I have a folder called blog in the above mentioned path. I have to access the the website in the blog folder by specifying http://myDomain/blog/. My question is I want to be able to access the website by specifying http://myDomain in the browser(without having to move the contents of the blog folder to www root). Is there any parameter which I can set in the config file so as to be able to achieve the mentioned objective.
Thanks.
Edited /etc/httpd/conf/httpd.conf file and search for DocumentRoot and change from
/var/www/html
TO
/var/www/html/blog
In your Apache httpd.conf file, just set the DocumentRoot as being /var/www/html/blog.

How do I change the root directory of an Apache server? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
Improve this question
How can I change the document root of the Apache server? I basically want localhost to come from /users/spencer/projects directory instead of /var/www.
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.
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.
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.
This is for Ubuntu 14.04 (Trusty Tahr):
In file /etc/apache2/apache2.conf it should be as below without the directory name:
<Directory /home/username>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And in file /etc/apache2/sites-available/000-default.conf you should include the custom directory name, i.e., www:
DocumentRoot /home/username/www
If it is not as above, it will give you an error when loading the server:
Forbidden You don't have permission to access / on this server
The right way to change directory or run from multiple directories under different port for Apache 2 is as follows:
For Apache 2, the configuration files are located under /etc/apache2 and doesn’t use a single configuration file as in older versions but is split into smaller configuration files, with /etc/apache2/apache2.conf being the main configuration file. To serve files from a different directory we need a new virtualhost conf file. The virtualhost configuration files are located in /etc/apache2/sites-available (do not edit files within sites-enabled). The default Apache installation uses virtualhost conf file 000-default.conf.
Start by creating a new virtualhost file by copying the default virtualhost file used by the default installation of Apache (the one that runs at localhost on port 80). Change into directory /etc/apache2/sites-available and then make copy by sudo cp 000-default.conf example.com.conf, now edit the file by sudo gedit example.com.conf to:
<VirtualHost *:80>
ServerAdmin example#localhost
DocumentRoot /home/ubuntu/example.com
</VirtualHost>
I have deleted the nonimportant lines from the above file for brevity. Here DocumentRoot is the path to the directory from which the website files are to be served such as index.html.
Create the directory from which you want to serve the files, for example, mkdir example.com and change owner and default group of the directory, for example, if your logged in user name is ubuntu change permissions as sudo chown ubuntu:www-data example.com. This grants full access to the user ubuntu and allows read and execute access to the group www-data.
Now edit the Apache configuration file /etc/apache2/apache2.conf by issuing command sudo gedit apache2.conf and find the line <Directory /var/www/> and below the closing tag </Directory>, add the following below:
<Directory /home/ubuntu/example.com>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Now there are two commands to enable or disable the virtualhost configuration files, which are a2ensite and a2dissite respectively. Now since our example.com.conf file uses the same port(80) as used by the default configuration file(000-default.conf), we have to disable the default configuration file by issuing the command sudo a2dissite 000-default.conf and enable our virtualhost configuration file by sudo a2ensite example.com.conf
Now restart or reload the server with command sudo service apache2 restart. Now Apache serves files from directory example.com at localhost on default port of 80.
The a2ensite command basically creates a symbolic link to the configuration file under the site-enabled directory.
Do not edit files within sites-enabled (or *-enabled) directory, as pointed out in this answer.
To change the port and run from multiple directories on different ports:
Now if you need to run the directory on a different port, change the port number from 80 to 8080 by editing the virtualhost file as:
<VirtualHost *:8080>
ServerAdmin user#localhost
DocumentRoot /home/ubuntu/work
</VirtualHost>
and editing /etc/apache2/ports.conf and adding Listen 8080 just below the line Listen 80
Now we can enable the default virtualhost configuration file that runs on port 80 since example.com directory uses port 8080, as sudo a2ensite 000-default.conf.
Now restart or reload the server with command sudo service apache2 restart. Now both the directories can be accessed from localhost and localhost:8080.
If you couldn't find http.conf and followed Nick's way.
Restart Apache using sudo service apache2 restart.
I was working with LAMP and to change the document root folder, I have edited the default file which is there in the
/etc/apache2/sites-available folder.
If you want to do the same, just edit as follows:
DocumentRoot /home/username/new_root_folder
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/username/new_root_folder>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
After this, if you type "localhost" in the browser, it will load the /home/username/new_root_folder content.
For Apache 2 on Linux Mint 17.3 Cinnamon 64-bit, the following works:
In /etc/apache2/sites-available/ open the 000-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 folder /etc/apache2/ open file httpd.conf, and add a <Directory> tag referencing your directory and containing the exact same settings as the tag for var/www.
sudo vim /etc/apache2/apache2.conf
On my machine it looked like this:
<Directory /home/my_user_name/php/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
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).
Open the file /etc/apache2/apache2.conf and
search for <Directory /var/www/> and replace to your directory.
Open file /etc/apache2/sites-available/000-default.conf, search for DocumentRoot /var/www/html and replace it with your DocumentRoot.
In case you are using Ubuntu 16.04 (Xenial Xerus), please update the 000-default.conf file in the directory /etc/apache2/sites-available.
Here →
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/YourFolder
The following applies to Ubuntu 14.04 (Trusty Tahr) and later releases. Make sure to back up following files before making any changes.
Open /etc/apache2/apache2.conf and search for <Directory /var/www/> directive and replace path with /home/<USERNAME>/public_html. You can use * instead of .
Open /etc/apache2/sites-available/000-default.conf and change the DocumentRoot value property from /var/www/html to /home/<USERNAME>/public_html. Also <Directory /var/www/html> to <Directory /home/<USERNAME>/public_html.
Open /etc/mods-available/php7.1.conf. Find and comment the following code
php_admin_flag engine Off
Do not turn the php_admin_flag engine OFF flag on as the reason is mentioned in a comment above the Directive code. Also the PHP version can be 5.0, 7.0 or anything you have installed.
Create public_html directory in home/<USERNAME>.
Restart the Apache service by executing command sudo service apache2 restart.
Test by running a sample script on the server.
I had made the /var/www to be a soft link to the required directory (for example, /users/username/projects) and things were fine after that.
However, naturally, the original /var/www needs to be deleted - or renamed.
If someone has installed LAMP in the /opt folder, then the /etc/apache2 folder is not what you are looking for.
Look for httpd.conf file in folder /opt/lampp/etc.
Change the line in this folder and save it from the terminal.
If you're using Linux Mint (personal opinion, from all distributions this one is making me happy), follow this:
Go to folder /etc/apache2/sites-available and edit file 000-default.conf.
Search for DocumentRoot, example DocumentRoot /var/www/html. You change to your respective directory;
Open a terminal and type: sudo service apache2 restart
In Linux Mint, you go for file /etc/apache2/apache.conf. Replace /var/www with your respective path, and then restart the server (step 3).
That's it.
In Red Hat Linux 7.0: /etc/httpd/conf/httpd.conf

Resources