How do I grant permission on an Apache 2.4 server? - apache

I have an Apache 2.4 server (WAMP) on my pc (running windows 10). It is fine when I connect to it on my pc (the host) but when I test it on another device it simply gives a 403 forbidden error and refuses to load. I have been trying so many solutions online with the config file but to no avail. How do I fix this?
Here is my httpd.conf file: http://pastebin.com/5B5Q31im
Please note that I am new to this.

Not a WAMP guy but a linux admin.... and your config file looks like Apache 2.2, 2.4 has some changes where it defines the top level document root directory, and the forbidden error is what usually reminds me I've copied an old config over to a new system...
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +FollowSymLinks +Multiviews
AllowOverride all
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Should be more like
DocumentRoot ${INSTALL_DIR}/www
<directory ${INSTALL_DIR}/www>
Options All
AllowOverride All
Require all granted
</directory>

Related

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

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

500 Internal Server Error when trying to enable use of .htaccess in Apache on Ubuntu

I am trying to get my .htaccess working on my Ubuntu-apache2-webserver.
For that I opened /etc/apache2/apache2.conf,
I removed the comment sign (#) before AccessFileName .htaccess
and replaced AllowOverride None by AllowOverride All in
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
I activated mod_rewrite via a2enmod rewrite and restarted the server.
But each time I am performing those changes and open an html-file placed inside of /var/www/html, I get a 500 Internal Server Error for Virtual Host 80.
The same thing happened to me when placing
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
before </VirtualHost> into the 000-default.conf-file instead of the /etc/apache2/apache2.conf.
Can anyone tell me what I am missing?
You're slightly off in your syntax for allowOverride. The Directory tag needs to be inside the VirtualHost tag. Like so:
<VirtualHost *:80>
DocumentRoot /var/www/html
ErrorLog /var/log/apache2/error.log
Options Includes
<Directory "/var/www/html">
AllowOverride All
</Directory>
</VirtualHost>
Also, make sure Apache has permissions to read and write to the directory /var/www/html

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

Apache2 Option index on centos 6.3

On a newly installed Centos 6.3
I imported the config from Ubuntu for a virtualhost. Here is the piece of config
DocumentRoot /otherhome/test.cofares.net
ServerName test.cofares.net
<Directory "/otherhome/test.cofares.net">
allow from all
Options +Indexes
</Directory>
A request to the http://test.cofares.net I get the folowwing error in the error log
Directory index forbidden by Options directive: /otherhome/test.cofares.net/
The directory index worked for a sub directory http://test.cofares.net/test is OK
Any suggestions what is missing?
The same config work well with Ubuntu Server 12.04.
Try this. And make sure to restart apache after applying:
<Directory "/otherhome/test.cofares.net">
Options +Indexes FollowSymLinks
AllowOverride all
Order Allow, Deny
Allow from All
Satisfy All
</Directory>
And perhaps try this with Satisfy Any instead:
<Directory "/otherhome/test.cofares.net">
Options +Indexes FollowSymLinks
AllowOverride all
Order Allow, Deny
Allow from All
Satisfy Any
</Directory>
EDIT: Those didn’t seem to work? Then try this. Note I am setting up the whole <VirtualHost> directive & removed quotes from the <Directory> directive:
<VirtualHost *:80>
DocumentRoot /otherhome/test.cofares.net
ServerName test.cofares.net
<Directory /otherhome/test.cofares.net>
Options Indexes FollowSymLinks
Allow from All
</Directory>
</VirtualHost>
After digging a little I noticed that thire is a global rule (in conf.d/welcome.conf) that prevent indexing the / directory of any virtual server
By removing it it is now ok
Here is the rule that must be change
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>

apache: don't have permission to access / on this server. when I am using virtualhost

For example, the document root of virtualHost is /var/www, and server name is aaa.com.
However, apache will tell me forbidden if I access the server with localhost and aaa.com. If I change the Directory option in http.conf to /var/www, apache will work well. I don't know why?
I want to set Directory option in every httpd-vhosts.conf, not in httpd.conf, how I can do it?
Here is my http.conf:
Here is my httpd-vhosts.conf:
In http.conf file you should define options for only <Directory />. All the options of VirtualHosts you should define in httpd-vhosts.conf files. Something like:
httpd.conf:
DocumentRoot "/var/www"
<Directory />
Order deny,allow
Deny from all
Options None
AllowOverride None
</Directory>
httpd-vhosts.conf:
ServerName aaa.com
DocumentRoot /var/www
<Directory /var/www>
Options FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
This configuration was valid for apache version 2.2
First check your apache version by typing apachectl -V in your terminal.
If it shows something like this
Server version: Apache/2.4.27 (Ubuntu)
Server built: 2018-04-18T14:20:05
then your apache version has updated but the conf you are using is deprecated.
So instead of
2.2 configuration:
Order allow,deny
Allow from all
use this:
2.4 configuration:
Require all granted
For further documentation related to the upgrade, follow the official docs:
http://httpd.apache.org/docs/current/upgrading.html
2.4 configuration:
<Directory />
Options All
AllowOverride All
</Directory>