How to change Apache root directory - apache

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.

Related

virtualhost keeps redirecting to deleted alias information

I have a DigitalOcean droplet (i.e. a VPS server), with Ubuntu 14.04 and Apache 2.2.
I had 4 virtualhosts configured, with 4 different domains pointing to 4 different folders, no problem.
I needed to point a 5th domain (let's call it www.someshop.tld) containing a PrestaShop installation.
I added the following Alias to the apache2/sites-available/domain1.conf file so that www.domain1.tld/someshop would lead to www/prestashop, and it worked fine
<VirtualHost *:80>
ServerName www.domain1.tld
DocumentRoot /www/directory1
Alias /someshop /www/prestashop #Alias line
</VirtualHost>
I did this as a temporary measure so I could have a working site publicly accessible, (so I could access www/prestashop publicly before I had configured www.someshop.tld DNS settings, 'A' record, Nameservers, etc.).
I now don't need to do this any more, so I deleted the Alias line from the .conf file so it looks like this:
<VirtualHost *:80>
ServerName www.domain1.tld
DocumentRoot /www/directory1
</VirtualHost>
and added a new someshop.conf that looks like this:
<VirtualHost *:80>
ServerName www.someshop.tld
DocumentRoot /www/prestashop
</VirtualHost>
I then re-enabled both the .conf files in apache2/sites-enabled, and restarted apache with service apache2 restart.
However, when I go to www.someshop.tld, it continues to do a URL redirect to www.domain1.tld/prestashop (where there's this message: "Not Found, The requested URL /someshop was not found on this server").
I waited for a couple of hours before posting this question because I thought it might just be a "propagation" issue. So far it's still doing this.
My question: is this something that should clear up by waiting for it, or do I need to fix something else? E.g., is there some way for me to flush the old virtualhost Alias information?
Have you tried removing the site from apache config?
$ sudo a2dissite test.com.conf #Remove symlink
$ sudo service apache2 reload
This would remove the symlink. You can then create the symlink again with the proper configurations that you like.

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.

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

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 :)

Error starting apache from terminal after removing MAMP

I removed MAMP recently.
When I try to start apache from Terminal using:
sudo apachectl -k restart
I am getting the message
Warning: DocumentRoot [usr/docs/dummy-host.example.com] does not exist.
First, make sure you're actually trying to execute the proper version of apachectl by issuing the following command:
which apachectl
(You don't want to see any MAMP references there).
Next, find your virtual hosts config (which is likely here if your MAMP references are gone)
/etc/apache2/extra/httpd-vhosts.conf
Make sure your virtual host definitions are good. (Sounds like you're referencing a bad one).
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/Users/yourusername/Sites/mysite"
ServerName mysite.local
ErrorLog "/private/var/log/apache2/mysite-error_log"
CustomLog "/private/var/log/apache2/mysite-access_log" common
</VirtualHost>
(If you're using a custom server name other than 'localhost' like I've defined above, just be sure your /etc/hosts file is up to date with that entry like this:
127.0.0.1 mysite.local
Don't forget to restart apache!
sudo apachectl restart
You probably need to go to apache config file (something like etc/apache2/apache2.conf) and set it an existing document root directory. That is usually done with DocumentRoot directive in this file, or one of the included virtual host config definitions.
Make sure you comment out all the lines inside the /etc/apache2/extra/httpd-vhosts.conf file otherwise you will get the errors.