Centos You don't have permission - apache

So my im having difficulties with a website server. When i try to access it, i get the error "You don't have permission to access /index.html on this server."
However i've given rights to the folders and the files exactly as ive done with a different server that does the same thing. Only way ive found to get rid of the error is with a command :
chcon -R -t httpd_sys_content_t /var/www/html/
However the solution is not permanent, it seems to go away each time i use a jenkins build on the server.
<VirtualHost *:80>
Redirect / servername
</Virtualhost>
<Virtualhost _default_:80>
ServerName localhost
<Location "/server-status">
Require all granted
SetHandler server-status
Order Allow,Deny
Allow from ::1
Allow from 127.0.0.1
Allow from 192.168****/23
Allow from 192.168****
</Location>
ErrorLog logs/error.log
SetEnvIf Remote_Addr "::1" dontlog
SetEnvIf User-Agent ".*internal dummy connection.*" dontlog
CustomLog /var/log/httpd/access.log combined env=!dontlog
</VirtualHost>

Problem diverted.
I managed to solve this by editing /etc/selinux/config file in Centos 7 and turn selinux disabled. Reboot and problem went away for good.

Related

Apache VHost not working but seems to be configured correctly: Mac Os Ventura

The Problem
I've been trying to setup apache on my mac. I installed apache using brew and everything seems to work except when I actually try to navigate the url with my browser.
Anytime I navigate to http://parenting.localhost/ I just get a 404 error. To make things even more odd, if I just go to http://localhost/ (not using the vhost) it still writes the logs to the vhost log files. Clearly something is wrong, I just can't figure it out. Any help would be appreciated.
My Environment
My /usr/local/etc/httpd/extra/httpd-vhosts.conf:
<VirtualHost *:80>
ServerName parenting.localhost
ServerAlias parenting.localhost.com
DocumentRoot "/Users/joshteam/PhpstormProjects/parenting/public"
<Directory /Users/joshteam/PhpstormProjects/parenting/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /Users/joshteam/PhpstormProjects/parenting/storage/logs/error.log
CustomLog /Users/joshteam/PhpstormProjects/parenting/storage/logs/access.log combined
</VirtualHost>
My /etc/hosts:
127.0.0.1 parenting.localhost
127.0.0.1 parenting.localhost.com
I ensure the VHOST is enabled currently:
$ httpd -t -D DUMP_VHOSTS
VirtualHost configuration:
*:80 parenting.localhost (/usr/local/etc/httpd/extra/httpd-vhosts.conf:24)
What I'm Trying To Do
To navigate to http://parenting.localhost/ and for apache to execute the appropriate index.php within the vhost configuration. Instead I get a 404.

Enable PUT and DELETE methods on Apache 2.4

I'd like to enable on my Apache 2.4 under linux the PUT and DELETE methods. When clients try to invoke such methods I get a "405 Method Not Allowed" as answer.
On server side my PHP script handle such requests but it seems filtered by the server itself (that's makes the difference from the similar already answered question - Moreover other questions seems to refers to an old version of Apache).
Can I manage some configurations on .htaccess file or I have to modify the .conf files under /etc/apache2?
Thanks a lot.
Try the following changes on your server:
Open "/etc/httpd/conf/httpd.conf" and look for the following blocks:
<Limit GET POST OPTIONS PROPFIND>
Order allow,deny Allow from all
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND>
Order deny,allow Deny from all
</LimitExcept>
Then just add PUT and DELETE after PROPFIND. Then Restart httpd by "/sbin/service httpd restart" or service httpd restart.
Note: In some servers , mostly the ones with a control panel (DA,cPanel,..) you may change this file :/etc/httpd/conf/extra/httpd-directories.conf
I hope it solves your problem.
For Debian/Ubuntu.
In your conf:
<Location "/">
AllowMethods GET PUT
</Location>
In console:
sudo a2enmod allowmethods
sudo systemctl restart apache2.service
You can use allowmethods_module to enable that.
It's been available since apache version 2.3 but still experimental though.
<Location "/path/to/directory">
AllowMethods PUT DELETE
</Location>
I got the same error and the root cause is the redirects to https (80-443) are not occurring which one of the things are causing the docker client to fail while allowing the browser to work. I added below directives in Apache httpd (apache2) and it worked for me.
<VirtualHost *:80>
RedirectPermanent / https://%{SERVER_NAME}/
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
# General setup for the virtual host
ServerName example.org
ServerAdmin help#example.com
ErrorLog /tmp/error_log
SSLProxyEngine On
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
AllowEncodedSlashes NoDecode
ProxyPreserveHost On
ProxyPass / http://<BackendIP>/ connectiontimeout=10 timeout=3600
ProxyPassReverse / http://<BackendIP>/
</VirtualHost>

apache2 virtualhost configuration with two subdirectories

I'm running Apache 2.4 on Ubuntu 14.04 server. It's purpose is a mail server so it has postfix, dovecot and roundcube on it (amongst other things). I'm trying, and failing, to configure Apache to serve the pages that I want.
I have an SSL certificate installed and working correctly. I want to force all access over HTTPS so I have:
<VirtualHost *:80>
Redirect / https://mailserver.hni.ae/
</VirtualHost>
Both sets of files to be served are under /var/www/html, the first being /var/www/html/A and the other /var/www/html/B (let's say). I have configured my /etc/apache2/sites-available/000-default.conf (which has a symlink to ./sites-enabled) to be:
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/ssl/private/mycert.crt
SSLCertificateKeyFile /etc/ssl/private/mycert.key
ServerAdmin webmaster#mydomain.com
ServerName www.mydomain.com
DocumentRoot /var/www/html/
DirectoryIndex index.php
<Directory /var/www/html/A>
Options FollowSymLinks
AllowOverride None
Order Allow,Deny
Allow from all
</Directory>
<Directory /var/www/html/B>
Options FollowSymLinks
AllowOverride None
Order Deny,Allow
Deny from All
Allow from 192.168.1.1
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And that works. I can go to www.mydomain.com/B and it serves the login page for those pages (only when I access from the specified IP address), and www.mydomain.com/A and login to the pages from app A.
My problem: I want to be able to go to www.mydomain.com/C and just plain www.mydomain.com and be redirected to www.mydomain.com/A but when I use Redirect ... the server gets into a loop and tries to serve www.mydomain.com/AAAAAAA.... I suspect I should use the RedirectMatch temp ^/$... directive but can't get that to work either. Maybe something to do with the Redirect for :80 to :443 clashing? There is no .htaccess involved as I'm using AllowOverride None.
I've read the Apache 2.4 documentation thoroughly but just can't figure it out. Any suggestions?
You can use a RewriteRule. Add this to your VirtualHost:
RewriteEngine On
RewriteRule ^/(C/?|)$ /A [R,L]
Make sure mod_rewrite is enabled too.
Explanation:
Regex ^/(C/?|)$ will match /C optionally followed by a /, or just / i.e. the root of www.mydomain.com

Apache2 host two sites on the same server

I am trying to host subversion and wiki on the same site.
I have created two files in /etc/apache2/sites-available
in "subversion"
I have
<VirtualHost -myserverIP-:80>
ServerAdmin webmaster#localhost
ServerName svn.example.com
DocumentRoot /var/svn/repos
<Location /svn/repos>
DAV svn
SVNPath /var/svn/repos
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/passwords
Require valid-user
</Location>
</VirtualHost>
and in "wiki" I have
<VirtualHost -myserverIP-:80>
ServerAdmin webmaster#localhost
ServerName wiki
ServerAlias -myserverIP-
DocumentRoot /home/www/wiki/html
<Directory /home/www/wiki/html>
AllowOverride None
Options -Indexes -MultiViews -SymLinksIfOwnerMatch +FollowSymLinks
Order allow,deny
allow from all
</Directory>
<Location /wiki>
</Location>
<DirectoryMatch "^/home/www/wiki/html/(data|conf|bin|inc)/">
Order allow,deny
Deny from all
Satisfy All
</DirectoryMatch>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
ErrorLog /home/www/wiki/logs/error.log
CustomLog /home/www/wiki/logs/access.log combined
</VirtualHost>
However now, when I browse to the IP address of the server, I get the contents of the /var/svn/repos directory, wheras when I just had the wiki page, I got the wiki index page. I can actually go to -IPaddress-/svn/repos and see the SVN repository, but -IPaddress-/wiki does not work.
Thanks for the tips
Both your virtual hosts are on port 80 on the same machine. Apache can only guess which one you want to use. It is guessing the subversion one and browsing to the DocumentRoot specified.
You need to differentiate the virtual hosts, or browse to the server using the server name rather than IP.
Instead you could setup the SVN location inside your other virtual host.
Also consider using /etc/apache2/mods-available/dav_svn.conf depending on your Operating System.
However now, when I browse to the IP address of the server, I get the contents of the /var/svn/repos directory, wheras when I just had the wiki page, I got the wiki index page. I can actually go to -IPaddress-/svn/repos and see the SVN repository, but -IPaddress-/wiki does not work.
When you make a request to apache and the hostname you are using isn't defined by any ServerName or ServerAlias in any of the vhosts, apache returns the default vhost, which is always the first vhost in the file (or in the file with the name that's the smallest lexiconical order, e.g. 00-default_vhosts.conf). In your case, your SVN vhost is first so it is the "default" vhost. If you swap the 2 around the other one would be the "default" vhost.

WAMP 403 Forbidden message on Windows 7

I have installed WAMP version 2.1 on my windows 7 machine. When i browse to localhost in my browser, the WAMP server page is visible.
But when I browse to my IP in my browser, I get the message
403 Forbidden: You don't have permission to access / on this server.
Any suggestions?
The access to your Apache server is forbidden from addresses other than 127.0.0.1 in httpd.conf (Apache's config file) :
<Directory "c:/wamp/www/">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
The same goes for your PHPMyAdmin access, the config file is phpmyadmin.conf :
<Directory "c:/wamp/apps/phpmyadmin3.4.5/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
You can set them to allow connections from all IP addresses like follows :
AllowOverride All
Order allow,deny
Allow from all
I found a simpler fix...
Although the icon was green WAMP still needs to be "Put Online" (last item of menu when left-clicking icon).
After that I had access as normal.
For me the inclusion of "Require local" helped to solve Error 403. The alias config file looks like this:
Alias /mytest/ "C:/mytest/"
<Directory "C:/mytest/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require local
</Directory>
The solution for changing the permissions in the httpd.conf will work if you are OK with providing access to the WAMP server from outside.
If you do not want to do that then all you have to do is tell windows that the "localhost" domain points to 127.0.0.1. You can do that by editing the hosts file in your system directory.
The file is placed at : C:\Windows\System32\drivers\etc\hosts
by default windows 7 ships with :
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
You have to un-comment the mapping for localhost:
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
# ::1 localhost
Note: you will not be able to edit the hosts file as its a read-only file. To edit, you have to be the administrator, copy the file to some other location, edit it and then copy it back to the etc directory.
I do not recommend the change of the hosts file. Use the permissions of httpd.conf file. use the hosts file approach only if you do not want the server accessed from outside.
Try adding the following lines of code to the file httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin serveradmin#host.com
DocumentRoot "C:\wamp\www"
ServerName localhost
</VirtualHost>
Another thing I found out is that if your network adapter uses IPV6, it will not show as 127.0.0.1 but ::1
What I ended up doing is this:
<Directory "c:/wamp/www/">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
</Directory>
The same goes for your PHPMyAdmin access, the config file is phpmyadmin.conf :
<Directory "c:/wamp/apps/phpmyadmin3.4.5/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
</Directory>
For Wamp 3.1.3 and Apache 2.4 I simply had to change 1 line in my httpd-vhosts.conf file.
Open httpd-vhosts.conf
Change "Require local" to "Require all granted"
Restart all services
I was then able to get to my apache server from other computers.
Give credit to this video: https://www.youtube.com/watch?v=Sy_f6wBGnjI
if you have used localhost/phpmyadmin/
simply use
127.0.0.1/phpmyadmin/ for PHPMyAdmin
127.0.0.1/sqlbuddy/ for SQLBuddy
or if you have used localhost:8080/phpmyadmin/ then
127.0.0.1:8080/phpmyadmin/ for PHPMyAdmin
127.0.0.1:8080/sqlbuddy/ for SQLBuddy
Remember to remove dummy elements in httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
For Apache version 2.4.x simply replace Require local with Require all granted in httpd.conf file inside <Directory "c:/wamp/www/"> tag then Restart all services
There could many causes to this problems
What I have experienced are:
1) 127.0.0.1 localhost entry was duplicated in hosts file
2) Apache mod_rewrite was not enabled
Regardless of the cause, backing up your www folder, vhost configuration file (and httpd configuration file) will help.
And such process takes a few minutes.
Good luck
I read & tried All Fixes But Not one worked. At last i Found that the Wamp Server Logo Is Green But Need to Be "PUT ONLINE".
So simple & a Quick Fix After Checking Your PHPMyAdmin.Cofg & HttPD.cofg Just Click on PUT ONLINE
I tried the configs above and only this worked for my WAMP Apache 2.4.2 config. For multiple root site without named domains in your Windows hosts file, use http://locahost:8080, http://localhost:8081, http://localhost:8082 and this configuration:
#ServerName localhost:80
ServerName localhost
Listen 8080
Listen 8081
Listen 8082
#.....
<VirtualHost *:8080>
DocumentRoot "c:\www"
ServerName localhost
<Directory "c:/www/">
Options Indexes FollowSymLinks
AllowOverride all
Require local
</Directory>
</VirtualHost>
<VirtualHost *:8081>
DocumentRoot "C:\www\directory abc\svn_abc\trunk\httpdocs"
ServerName localhost
<Directory "C:\www\directory abc\svn_abc\trunk\httpdocs">
Options Indexes FollowSymLinks
AllowOverride all
Require local
</Directory>
</VirtualHost>
#<VirtualHost *:8082></VirtualHost>.......
I faced this issue with wamp on windows 7. Adding following code to httpd-vhosts.conf solved the issue for me.
<VirtualHost *:80>
DocumentRoot "F:/wamp_server/www/"
ServerName localhost
</VirtualHost>
Thanks for your question.
I'am using wamp 3 now.
And I find an simple answer to do this under your question.
But that answer should change a little on wamp 3.
The steps are as following:
Right click wamp icon
Choose Wamp Setting
Click the Menu item:online/offline
Left click wamp icon
You will find there is a new item called "Put online"
It took me forever to figure this out.
C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf
In this file you will notice several example virtual host files, that look like:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
Simply delete these entries and replace with:
<VirtualHost *:80>
ServerAdmin serveradmin#host.com
DocumentRoot "C:\wamp\www"
ServerName localhost
</VirtualHost>
You definitely need to make sure your other ducks are in a row but this for me with the solution that worked.
hi there are 2 solutions :
change the port 80 to 81 in the text file (httpd.conf)
and click 127.0.0.1:81
change setting the network
go to control panel--network and internet--network and sharing center
click-->local area connection
select-->propertis
check true in the -allow other .....
and --- allo other .....
I had this problem too. The route of my problem was I had made a mistake in my vhosts.conf file. If you are using vhosts this is another thing to check
This configuration in httpd.conf work fine for me.
<Directory "c:/wamp/www/">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 ::1
</Directory>
Make sure you aren't using a Windows' directory separator character (backslash) in your path names in your .conf file, even if you are on Windows. Apache doesn't understand them but will still start up and then output a 403 Forbidden Message.
wrong:
<Directory "c:\websites\my-website\">
right:
<Directory "c:/websites/my-website/">
Surprisingly, square brackets in DocumentRoot (and related, like <Directory>) paths can also cause error 403:
DocumentRoot "P:/TRY/web/fatfree/from_github/fatfree-master[bang]" failed with 403, while
DocumentRoot "P:/TRY/web/fatfree/from_github/fatfree-master" worked fine.
(I didn't bother figuring out the Apache path escaping, if any, just renamed the path instead. If anyone knows, comments are welcome.)
My solution was to disable encoding for encoded files (these files are green in windows). Ive got these files from MAC computer and it was encrypted by default.
Ive select these files > right click > properities > general tab > andvanced > uncheck encrypt files...
And voila it works.
I have tried all the stuff except clearing the mess in .htaccess file.
Go to www/ directory and make a copy of .htaccess file in another folder. Then clear all the lines in .htaccess original file.
And add this line,
RewriteEngine On
Then restart the server.
This has solved my problem and got access to all my localhost sites.
Hope it would solve yours too.
Also on Apache 2,4 you may need to add this to the directory directive in conf,
in case you decided to include httpd-vhosts.conf.
By default you can install wamp in C:\ but still choose to deploy your web development in another location.
To do this inside the vhosts.conf you can add this directive:
<Directory "e:/websites">
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Allow from all
Allow from localhost ::1 127.0.0.1
</IfDefine>
</Directory>
make sure that, the name of the file in the directory c:/wamp/apps/phpmyadmin3.1.3.1/, match the name (or version) in the phpMyAdmin.conf (Alias /phpmyadmin "c:/wamp/apps/phpmyadmin3.1.3.1/" )
I have found that if you are using ammps that for some reason its always forbidden when its in your root folder so i put it in the directory above my root folder and made a alias in the httpd.conf using this
Alias /phpmyadmin "C:/Program Files (x86)/Ampps/phpMyAdmin"
please note i am using ammps and i dont know for sure if it will work for others but its worth a try ;)