Apache Document Root adds leading default path - apache

This should be a very simple question to answer for people who knows apache.
I have an Ubuntu computer which I use as my server. I have worked with apache several times before, but never experienced this issue.
My owncloud.conf file in the sites-enabled folder looks like this:
1 <VirtualHost *:80>¬
2 ServerName owncloud¬
3 DocumentRoot "~/mybook/ownCloud"¬
4 <Directory ~/mybook/ownCloud/>¬
5 Options None¬
6 Order deny,allow¬
7 Allow from all¬
8 </Directory>¬
9 </VirtualHost>
But after enabling the site and restarting apache, I'm getting this error:
AH00112: Warning: DocumentRoot [/etc/apache2/~/mybook/ownCloud] does not exist
I've been looking, and I cannot seem to find where it's set that "/etc/apache2/" should be leading default path to all set document roots of the site config files.
Does anyone know how I can remove this default setting?

Forget the comment I made regarding Mac, what you have above will not work. If you installed Apache on Ubuntu and accepted the defaults the docroot is /var/www and I am assuming you want your /mybook/ownCloud mapped to docroot. That is how you should do it because the httpd will run with group permissions to the real docroot. That can be done using an alias as I have below. Look at the bottom, but also note that I specified the correct default docroot in the beginning before I mapped anything. You can change the docroot but you will have to make sure the permissions on the new directory structure are set correctly.
I aliased your /mybook/ownCloud/ to ownCloud. Also, I have other directives that I removed from the sites-enabled code below for clarity.
BTW, I have personally never used tildes within an Apache conf file like you have above, it could be confusing during startup.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /owncloud/ "/mybook/ownCloud"
<Directory "/mybook/ownCloud">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
EDIT:
There are other ways to configure a VHost, but this is basically how it is done. You no longer set a server wide docroot declaration in httpd.conf. The /etc/apache2/ path is the server home and in the absence of a docroot declaration in your sites-enabled it may have defaulted to Server Home when httpd started.

Related

How to properly set the allow and deny for apache 2.4 conf and vhosts

I need some advice on how to properly setup the vhosts file directives preferably without changing the apache2.conf contents. This is for apache 2.4.
Currently, I get AH01797: client denied by server configuration probably caused by the Require all denied in the apache2.conf.
apache2.conf:
<Directory />
Order Deny,Allow
Deny from all
Options None
AllowOverride None
Require all denied
</Directory>
vhosts file:
<IfModule mod_ssl.c>
<VirtualHost *:80>
ServerName sub.example.com
ServerAlias sub.example.com
<Directory /var/www/sub.example.com>
AllowOverride None
Allow from all
Require all granted
</Directory>
</VirtualHost>
</IfModule>
Thank you!
UPDATE
Adding this to the apache2.conf works, it just doesn't work in vhosts file. Any idea why?
<Directory /var/www/sub.example.com>
AllowOverride None
Allow from all
Require all granted
</Directory>
In 2.4, you shouldn't use Order, Deny, or Allow at all. Purge them and replace with Require.
UPDATE Adding this to the apache2.conf works, it just doesn't work in vhosts file. Any idea why?
Maybe the vhosts file isn't included in your configuration, or mod_ssl is not loaded so the whole thing is commented out? The IfModule doesn't make much sense here.

Virtual host not displaying correct files

Centos 7.1 and apache 2.4 - We have installed a new drive in our server and want to move all of our sites to that drive (mounted as /data) and sites are located in /data/vhosts
When trying to access the site we are presented with the apache welcome screen. I can confirm that the vhost is loaded as trying changing the permissions of the dir above results in a forbidden access. There is also an index.php file located in /data/vhosts/test.mydomain.com/public_html
# IP has been changed for example:
<VirtualHost 91.91.91.91:80>
DocumentRoot "/data/vhosts/test.mydomain.com/public_html"
ServerName test.mydomain.com
<Directory /data/vhosts/test.mydomain.com>
Options All
AllowOverride All
order allow,deny
allow from all
</Directory>
</VirtualHost>
UPDATE 1:
I have deleted the welcome.conf file in /etc/httpd/conf.d/ and I am not given a forbidden 403. It is important to note that this is a new drive and no permissions has been set on /data (or sub folders) for apache. I am not entirely sure if that makes a difference?
I have also made some slight alternations to the vhost conf file but no difference:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/data/vhosts/test.mydomain.com/public_html"
ServerName test.mydomain.com
<Directory "/data/vhosts/test.mydomain.com">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory /data/vhosts/test.mydomain.com/public_html>
Options Indexes FollowSymLinks Includes ExecCGI
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Stop Apache from serving content from apache root directory

I noticed this by chance earlier and after a quick Google, really couldn't find anything to help. I'm genuinely having trouble even explaining the problem!
When I access http://mydomain.com/error/README I appear to be getting the error readme found in /var/www/error/README. My virtual host for mydomain.com is document root is pointing to /var/www/html/mydomain, and /var/www/html/mydomain/error/ does not exist.
Naturally I feel this shouldn't be happening and although I haven't been able to replicate it, my main concern is that a user could in fact access anything off of /var/www/ not just /var/www/error/
Linux version: CentOS release 6.5 (Final)
Apache version: Apache/2.2.15
My virtual host file is:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/html/mydomain
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/html/mydomain/>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
LogLevel error
CustomLog /var/log/httpd/mydomain_access.log combined
ErrorLog /var/log/httpd/mydomain_error.log
</VirtualHost>
Naturally I feel this shouldn't be happening and although I haven't been able to replicate it, my main concern is that a user could in fact access anything off of /var/www/ not just /var/www/error/
You probably have the following directive in your httpd.conf:
Alias /error/ "/var/www/error/"
This just redirects all your error queries to /var/www/error (e.g. if you need www.example.com/error/README it would redirect me to one of the README in that director). Removing the alias should fix your problem.
If you are concerned about access to your other directories then I, as a complete newbie to apache, would recommend.
Auditing your httpd.conf and removing any aliases that you don't need.
Modifying your containers to have "Deny from all" and "AllowOverride None" in all of them.
If you have selinux enabled, then remove the httpd security contexts from those directories.

Adding a directory to Apache Server

I have a Windows XP system running XAMPP/Apache. I already have files on an external hard drive that I would like to serve up without moving them to the same drive as the Apache installation.
Here is what I've tried so far:
In the main HTTPD.conf file:
Alias /client_files D:/clients/files
<Directory D:/clients/files>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
But the only result I got was :
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.6
I also tried adding to the HTTPD-VHOSTS.conf file:
ServerName client_files
ServerAlias client_files
DocumentRoot "D:/clients/files"
And also:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "D:/clients/files"
ServerName client_files
ServerAlias client_files
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
But neither of these worked either. How in the world can I add another directory to an Apache installation and have it accesible via something like "localhost/client_files"?
Any suggestions?
UPDATE: [SOLVED]
As per #Pedro Nunes's answer below, I now have my httpd.conf file with this section at the end of the file and which includes the line "Require all granted" which Pedro answered with and which now solves the issue:
Alias /client_files D:/clients/files
<Directory D:/clients/files>
Require all granted
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
Have you tried Require all granted inside the directory section?
This will grant access to all requests.
This guide explains exactly how I have it setup on my windows xampp machine. http://www.delanomaloney.com/2013/07/10/how-to-set-up-virtual-hosts-using-xampp/
remember to give an absolute documentroot path as well as adding the 127.0.0.1 servername line to hosts in C:/Windows/System32/drivers/etc/hosts

Local sub-domains on httpd apache

I have on my machine wampp server installed that I use to run php applications.
There are many folder in the htdocs with inside my projects and I can see those in the browser at this url: localhost/folder-name/.
I'd like to see every project in a custom url like: dev.name-folder.com
With IIS is very easy to do that, can someone explain how do that with Apache, using wampp server?
Thanks.
You can change your C:\Windows\System32\drivers\etc\hosts file to map domain names like dev.name-folder.com to your local system. (Otherwise you'll have to use a DNS server).
To configure a vhost in apache create a file for each domain/project you'd like to serve:
<VirtualHost *:80>
ServerAdmin email#domain.tld
ServerName domain.tld
DocumentRoot /var/www/htdocs/domain.tld/html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/htdocs/domain.tld/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
ServerName is the domain name you'd like to serve your files under. DocumentRoot must be set to the absolute path to your files (here taken from a linux system).