How do I point Apache document root to a specific folder in Ubuntu? - apache

I have a site that the root points to /var/www
I have set up two folders under /var/www
/var/www/old
/var/www/new
for the old folder, I have used the following to deny any access:
touch /var/www/old/.htaccess && echo deny from all >> /var/www/old/.htaccess
I now want the server to point the root to /var/www/new so that when people visit http://example.com the content in /var/www/new will serve, what should I do?

In Ubuntu the Apache configuration is located at /etc/apache2. There should be two folders, sites-available and sites-enabled. Inside sites-enabled are symlinks to config files in sites-available.
You simply have to change the document root in your activated configuration. Thats probably /etc/apache2/sites-enabled/000-default
Have a look for DocumentRoot and change it to /var/www/new, then reload your apache.

depends a LOT on how your apache server is configured.
I don't have an Ubuntu machine around, but what you're looking for is the DocumentRoot directive. On RedHat based machines it's normally in /etc/httpd/conf/httpd.conf but if memory serves Debian based systems use apache instead of httpd.
If that doesn't work be sure to check in /etc/httpd/conf.d since the files there are loaded dynamically.
Hope this helps :)

Related

How can I change the site file directory for an apache server? (Raspberry Pi)

Right now it's '/var/www/html' but I want it to be '/home/pi/FTP'
I can probably just change it in the config file, but i can't manage to find it, thank you in advance.
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

How to change Apache root directory

I know that there are several other questions asking this. However, I still have problems.
I am trying to change my Apache root server directory from the default /var/www/html on my Debian server. To do this, I modified /etc/apache2/sites-available/000-default.conf to have DocumentRoot /var/www instead of DocumentRoot /var/www/html. After doing this and saving it, I ran apache2ctl restart to reload the server. However, the server still looks for files in /var/www/html instead of /var/www. Is there something else I need to change?
Just make sure you are "landing" in the VirtualHost you are modifying.
You can check the virtualhosts being loaded with this command:
apachectl -S
Note: It is not ServerRoot what you are describing, it is DocumentRoot, there is a big diffrence between each, so better name them properly.

Apache 2.4 Can only Use htdocs as webroot

I set up Apache 2.4 yesterday, and it is working with the htdocs folder I set up in my home directory. However, I do not want to use htdocs, I want to use a folder in my ~/Documents/web/<project> directory. I have tried altering /etc/apache2/httpd.conf and /etc/apache2/users/<username>.conf to no avail. Does anyone have any ideas?
FOR WINDOWS:
please try to modify <your-apache-dir>\conf\http.conf.
Open http.conf in the above directory
Search for DocumentRoot
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "c:/Apache24/htdocs"
Modify the above bolded path.
Restart your apache.
(Note: Restarting apache is important. Any changes you made in apache and php, you have to restart the apache.)
FOR OSX:
Other than modifying the /etc/apache2/httpd.conf and /etc/apache2/users/<username>.conf,
you need to do one more change, otherwise the WebSharing won't be able to turn on again. (according to David_Wang)
Open your httpd.config (Probably need to do this if you haven't change the permission access to this file)
sudo chmod 666 httpd.conf
Open httpd.config, and start editing.
sudo chmod 644 httpd.conf, when it's finished, proceed to step 2 (change it back to original permisson access)
Find DocumentRoot "/Library/WebServer/Documents", and change it to DocumentRoot "/Users/leiwang/Sites" or any other folders you want to.
One important thing is, you need to give the Read/Write permission to the folder you specified.
sudo chmod -R 747 foldername
(ref: change web root apache mac OS X)
You need to add a <Directory> section (with Requrie all granted) each time you add a new DocumentRoot if it's not within the original document root.

apache2 not using directory specified in site-available/joomla.conf

I am running a ubuntu server.
I installed apache according to this site:
https://help.ubuntu.com/community/Joomla
I then created a file called joomla.conf in the /etc/apache2/sites-available directory. It is the same as the default configuration except I changed the DocumentRoot line to DocumentRoot /var/www/joomla. That is the directory where my joomla site is.
Some websites were saying to change the <Directory> directive but my default file didn't have one so I added it, like this:
<Directory "/var/www/joomla">
</Directory>
I ran a2dissite 000-default and a2ensite joomla.conf.
/var/www/ originally contained a html directory. Even with the above steps having been performed, apache still loads from /var/www/html/index.html. I obviously haven't edited the right file or something, help is appreciated.
Another curious thing, I don't have an /etc/httpd directory, or a httpd.conf file in my apache directory. I don't know if I need that or not?
The problem was that I had edited the files in /etc/apache2/sites-enabled which was over-riding any changes made is sites-available/. The sites-enabled directory is only meant to contain symlinks to the files in sites-available.
To fix it I first removed the non-symlink files from sites-enabled then removed and and re-added the configuration with the following commands:
$ sudo a2dissite joomla
$ sudo a2ensite joomla
(joomla.conf is the name of my config file)
Then I restarted the server with sudo service apache2 reload.
You're missing a leading slash in your directive:
<Directory "var/www/joomla">
</Directory>
Instead, it should be
<Directory "/var/www/joomla">
</Directory>
Change this, disable/enable joomla.conf and restart your apache server.
If there are problems after fixing this - the full joomla.conf listing could help.
Instead of /etc/httpd in Ubuntu you have /etc/apache2. Instead of httpd.conf you have apache2.conf as a main configuration file. This is specific for Ubuntu, feels convenient after being used to it.

Apache and Cakephp application

I am running into issues with cakephp application running with CentOs. I did not change any setting in the default config other than added a file under conf.d which content as :
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/portal/
ServerName abc.mydomain.com
</VirtualHost>
When accessed, home page works i.e. app.mydomain.com shows up but none of the CSS,JS and img files are loaded which are under default structure
i.e. /var/www/portal/app/webroot/img
/var/www/portal/app/webroot/css
/var/www/portal/app/webroot/js
So I tried moving them right under /var/www/portal/ and that worked for homepage but clicking on any link on homepage just does 404. e.g. If link is abc.mydomain.com/test
In apache log I see the errors as 'File Does not exist : /var/www/portal/test' . It seems that apache is not sending the request to cakephp to process the url.
What could be wrong here? Most likely with the apache security settings but am not sure where to lool.
Is your AllowOverride set to all? Only then the CakePHP rewrite directives which are in .htaccess files start working. Alternatively, you can move them to the virtual host configuration and get them to work.
Ok, this is a common mistake. you should enable "rewrite" --> module rewrite. (this is of course a php module). in ubuntu you usually type sudo a2enmod rewrite. Check for CentOS command.