Apache 2.4 Httpd 403 Forbidden in Vagrant of Centos 7 - apache

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.

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

PHP virtualhost's settings issue

I have a functional virtualhost set us
Listen 1234
<VirtualHost *:1234>
DocumentRoot "/Users/localuser/sites/testphp"
ServerName localhost
ErrorLog "/private/var/log/apache2/testphp-error_log"
CustomLog "/private/var/log/apache2/testphp-access_log" common
</VirtualHost>
<Directory "/Users/localuser/sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
PHP page is accessible by url localhost:1234.
Now I need to add another project, but I want to put it to different folder instead sites.
So I add another virtualhost settings as
Listen 1235
<VirtualHost *:1235>
DocumentRoot "/Users/localuser/Desktop/PE_RS/Projekty/php/hello-slim/public"
ServerName localhost
ErrorLog "/private/var/log/apache2/hello-slim-error_log"
CustomLog "/private/var/log/apache2/hello-slim-access_log" common
</VirtualHost>
<Directory "/Users/localuser/Desktop/PE_RS/Projekty/php/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
But in this case I'm getting for localhost:1235
Forbidden
You don't have permission to access / on this server.
I don't know if it does matter, but I have set in httpd-userdir.conf UserDir sites.
Thank you for any help.
In general, settings are all right. The issue is related to the folder/file permissions. I think that it was wrong to have PHP projects folder on Desktop. After move it into ~ and fix permissions by command sudo chmod -R 777 php (what is essential of this solution) all works!
Inspiration came from
askubuntu.com...

Set up a Virtual Host for Apache in CentOS

Is it possible to set up a Virtual Host for Apache in CentOS somewhere outside /var/www? (say /home/myuser/mywebsite)
I tried different alternatives but none worked.
This is the entry i added in my vhost file for testing:
<VirtualHost *:80>
ServerName testfer
DocumentRoot /home/builder/testfer
<Directory "/home/builder/testfer">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>

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>

Apache cannot access custom directory

I am using apache 2.4 and ubuntu 15.10.
I want to change default /var/www/html/ directory for my files into /home/myuser/mydir/. I know there are many tutorials, but it doesn't seem to work.
I changed 000-default.conf:
ServerAdmin webmaster#localhost
# DocumentRoot /var/www/html
DocumentRoot /home/myuser/mydir
# <Directory /var/www/html>
<Directory /home/myuser/mydir>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
I changed default-ssl.conf:
ServerAdmin webmaster#localhost
# DocumentRoot /var/www/html
DocumentRoot /home/myuser/mydir
I changed apache.conf:
# <Directory /var/www/html>
<Directory /home/myuser/mydir>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ls -l in /home/myuser/mydir is solid: -rwxrwxrwx
If I restart apache2 and access "localhost" in my browser I get:
Forbidden
You don't have permission to access / on this server.
Apache/2.4.12 (Ubuntu) Server at localhost Port 80
I don't know what else I can do.
Make /home/myuser/ world readable and world executable.