Ubuntu | Apache - No permission to request ressource after changing DocumentRoot - apache

I am currently setting up a development environment with Apache and Ubuntu for a Git project.
However, when I adjust the documentRoot under sites-availabe, I get the message "403 Forbidden" by calling the site in the browser.
The default directory under /var/www/html can be displayed without any problems.
However, if I change the path to /var/www/my-project.com, I get the 403 message.
I also copied the permissions from the folder "html", so there shouldn't be any problems here.
000-default.conf
ServerAdmin xxx#xxx.xx
DocumentRoot /var/www/xxxxx.com
ServerName xxxxx.com
ServerAlias www.xxxxx.com
apache2.conf
<Directory />
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
/etc/hosts
127.0.0.1 localhost
127.0.1.1 hostname
127.0.0.1 xxxxx.com
Permissions of /var/www/xxxxx.com
drwxrwxr-x 7 user:www-data
I have also completely reinstalled Apache, but that didn't help either.
(Im using Ubuntu 20.04 with Apache 2.4)
I would be very grateful for any help.
Edit: Also after copying the files to the html directory ends up in 403 when calling specific files. But i still can call the standard index.html from apache.

I found my problem. Because im really new to Ubuntu i didn't recognized the broken Symlink. After recreating it with
ln -s sourceDirectory newLinkDirectory
all works just fine

Related

Apache 2.4 Httpd 403 Forbidden in Vagrant of Centos 7

After vagrant up with Centos7 and httpd (Apache 2.4) is installed, I test the testa.dev.conf in /etc/httpd/conf.d as
<VirtualHost *:80>
ServerName html.testa.dev
DocumentRoot "/var/www/html/testa.dev/htdocs"
<Directory "/var/www/html/testa.dev/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
and it can be accessed as http://html.test.dev while
the domain name is added to /etc/hosts in host
NO change in the default setting /etc/httpd/conf/httpd.conf
a test page /var/www/html/testa.dev/htdocs/index.html is created
However, when I'm trying to test other directories, it comes to 403 Forbidden. What I have done is
to create testb.dev.conf in /etc/httpd/conf.d as
<VirtualHost *:80>
ServerName html.testb.dev
DocumentRoot "/srv/www/testb.dev/htdocs"
<Directory "/srv/www/testb.dev/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
to create a test page /srv/www/testb.dev/htdocs/index.html
to grant permissions by
chown -R apache:apache /srv/www/testb.dev/htdocs
chmod -R 755 /srv/www/testb.dev/htdocs
My idea is straight forward. Just want to change /var/www to /srv/www. But it seems there still some configuration around I missed.

Directory 'static' gives 404 error

On a Windows machine running XAMPP I have a folder in my web root called 'static'. It and everything in it return a 404 error even though the folder is there.
If I change the name of the folder, e.g. 'statics', all is well. I have other servers (Ubuntu) running Apache and I do not have this problem.
The site is a copy of one of the sites on one of our Linux servers. What can I do or change to allow the directory to work as named?
EDIT vhosts.conf
<VirtualHost *:8080>
ServerAdmin jablanchard#foo.com
DocumentRoot "C:/xampp/htdocs/home/app/gateway"
ServerName localhost
ServerAlias 127.0.0.*
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>
<Directory C:/xampp/htdocs/home/app/gateway/>
# allow .htaccess overrides to work
AllowOverride All
DirectoryIndex login.html index.html index.php
</Directory>
# this matches a link to any project directory to the physical webui directory
AliasMatch ^/projects/([-\w]*)/(.*)$ /home/src/gateway/webui/$2
<Directory /home/src/gateway/webui>
DirectoryIndex home.html
Options All
AllowOverride All
Require all granted
</Directory>
I was getting ready to re-install XAMPP but made one last pass through the config files for Apache. I found the problem was this bit of code in the httpd.conf file -
Alias "/static" "C:/xampp/htdocs/static"
<Directory "C:/xampp/htdocs/static">
AllowOverride All
Require all granted
</Directory>
I am not sure if this is part of the XAMPP install as all of the edits I have made to this installation are in the vhosts file. Once commented out the static directory, as I have defined it, works properly now.

Apache Document Root adds leading default path

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.

Changing root directory in apache2 is giving 403 Forbidden error

Though there are many similar questions here but I could not fix my problem from them.
I have installed Apache/2.4.7 (Ubuntu) in my ubuntu(14.04). I have changed two configuration files to change the default DocumentRoot of apache which is /var/www
to /home/name/www. The files I have changed are /etc/apache2/apache2.conf and /etc/apache2/sites-available/000-default.conf. In apache2.conf I put
<Directory /home/name/www>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and in 000-default.conf I changed,
DocumentRoot /home/name/www
My /home/name/www file has necessary permissions.
drwxr-xr-x 3 www-data www-data www
But when I try to access localhost from browser I receive
You don't have permission to access / on this server. error. What have i missed?
For changing the default root directory of apache from /var/www to /home/<username>/www following changes worked for me.
I edited the following values of etc/apache2/apache2.conf file like this. Before editing the file it's a good practice to keep a backup of the original.
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /home/<username>/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Then I changed /etc/apache2/sites-available/000-default.conf file's DocumentRoot.
DocumentRoot /home/<username>/www
After that restart the apache server,
sudo service apache2 restart

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