Xampp Access Forbidden php

PhpXampp

Php Problem Overview


I'm a windows user. I've been using xampp for quite a while but suddenly none of my .php files are working now! I get this error message:


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.4 (Win32) OpenSSL/0.9.8y PHP/5.4.16


I can see the list of my .php files in localhost/Practice (Practice is the folder where I've saved my files) The file even opens whenever I click on it. But when I click on any 'submit' button inside any of my files, it gives this error. Please help! I updated xampp from 1.8.1 to 1.8.2 but still the same problem persists!

Php Solutions


Solution 1 - Php

Try with this code below, add it in your virtual host config. Add this lines to httpd-vhosts.conf file:

<Directory "c:/<path-to-projects>/">
		Options Indexes FollowSymLinks MultiViews
		AllowOverride all
		Order Deny,Allow
		Allow from all
		Require all granted
</Directory>

I fixed the same issue by this way. Hope it helps.

Note:

after changes please test it in incognito because you redirected by cache

Solution 2 - Php

if used ubuntu operating system then check chmod of /Practice folder change read write permission

Open terminal press shortcut key Ctrl+Alt+T Goto

$ cd /opt/lampp/htdocs/

and change folder read write and execute permission by using chmod command

e.g folder name is practice and path of folder /opt/lampp/htdocs/practice

Type command

$ sudo chmod 777 -R Practice

what is chmod and 777 ? visit this link http://linuxcommand.org/lts0070.php

Solution 3 - Php

The way I resolved this was setup error logs correctly, first

<VirtualHost *:80>
    DocumentRoot "D:/websites/test/"
    ServerName test.dev
    ErrorLog "D:/websites/test/logs/error.log"
    CustomLog "D:/websites/test/logs/access.log" common
    <Directory D:/websites/test/>  
        AllowOverride none
        Require all granted  
    </Directory>
</VirtualHost>

After this error are being logged into "D:/websites/test/logs/" make sure to create logs folder yourself. The exact error that was recorded in error log was

> AH01630: client denied by server configuration:

Which pointed me to correct solution using this link which said for the above error

Require all granted 

is required. My sample sample code above fixes the problem by the way.

Solution 4 - Php

For XAMPP on Mac

sudo chmod -R 0777 /Applications/XAMPP/xamppfiles/htdocs/myprojectname

NOTE: remember to change 'myprojectname' to your actual project name. Also, make sure the project is on the root directory of htdocs or change the path accordingly.

Solution 5 - Php

The only solution that worked for me after spending hours researching online

sudo chmod -R 0777 /opt/lampp/htdocs/projectname

Solution 6 - Php

I am using xxamp using ubuntu 16.04 - and its working fine for me

<VirtualHost *:80>
    DocumentRoot "/opt/lampp/htdocs/"
    ServerAdmin localhost
    <Directory "/opt/lampp/htdocs">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Solution 7 - Php

Go in to your Xampp folder xampp/apache/conf/extra/httpd-xampp.c­onf

Edit the last paragraph:

#close XAMPP sites here 
.
.
.
Deny from all
.
.

to

#close XAMPP sites here 
.
.
.
Allow from all
.
.

or just watch this video: http://www.youtube.com/watch?v=ZUAKLUZa-AU.

Solution 8 - Php

Edit this file C:\xampp\apache\conf\httpd.conf Change:

AllowOverride none
Require all denied

To

AllowOverride All
Options  All
Allow from all
Order allow,deny

Restart apache

Solution 9 - Php

Did you change any thing on the virtual-host before it stop working ?

Add this line to xampp/apache/conf/extra/httpd-vhosts.conf

<VirtualHost localhost:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerAdmin localhost
    <Directory "C:/xampp/htdocs">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Solution 10 - Php

For me it was solved instantly by the following

  1. Going to C:\xampp\apache\conf\extra

  2. Editing inside the file httpd-xampp.conf

  3. Edit the file as follows:

find the following lines by cont+f:

Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
    AllowOverride AuthConfig
    Require local
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>

only change local ----> all granted, so it becomes like this

Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
    AllowOverride AuthConfig
    Require all granted
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>

After this the localhost will stop showing the error and will show admin panel. I found this solution in a video here: https://www.youtube.com/watch?v=MvYyEPaNNhE

Solution 11 - Php

I had this problem after moving the htdocs folder to outside the xampp folder. If you do this then you need to change the document root in httpd.conf. See https://stackoverflow.com/a/1414/3543329.

Solution 12 - Php

I had the same problem. So I got remembere. Yesterday I had commented this code in htttp-xampp.conf

Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
    <Directory "C:/xampp/phpMyAdmin">
#        AllowOverride AuthConfig
#        Require local
#        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </Directory>

SO I can access my localhost using other system on same network(LAN/WIFI) as it make localhost require local.

So I just make it like

Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
    <Directory "C:/xampp/phpMyAdmin">
        AllowOverride AuthConfig
#        Require local
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </Directory>

and now its working on my local machine and also localhost is accessible using other systems on same LAN/WIFI.

Solution 13 - Php

A. #LoadModule vhost_alias_module modules/mod_vhost_alias.so
B. <Directory />
    AllowOverride none
    Require all denied
</Directory>

Replace with:

A. LoadModule vhost_alias_module modules/mod_vhost_alias.so
B:
<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

From E:\xamp**apache\conf/httpd.conf**

Solution 14 - Php

I got the same error because somehow deleted the index.php and accessing the folder without index.php gave same error.

Solution 15 - Php

following steps might help any one

  1. check error log of apache2
  2. check folder permission is it accessible ? if not set it
  3. add following in vhost file /"> Options Indexes FollowSymLinks MultiViews AllowOverride all Order Deny,Allow Allow from all Require all granted
  4. last but might save time like mine check folder name(case sensitive "Pubic" is different form "public") you put in vhosts file and actual name. thanks

Solution 16 - Php

In my case I exported Drupal instance from server to localhost on XAMPP. It obviously did not do justice to the file and directory ownership and Apache was throwing the above error.

This is the ownership of files and directories initially:

enter image description here

To give read permissions to my files and execute permission to my directories I could do so that all users can read, write and execute:

sudo chmod 777 -R

but that would not be the ideal solution coz this would be migrated back to server and might end up with a security loophole.

A script is given in this blog: https://www.drupal.org/node/244924

#!/bin/bash

# Help menu
print_help() {
cat <<-HELP
This script is used to fix permissions of a Drupal installation
you need to provide the following arguments:

  1) Path to your Drupal installation.
  2) Username of the user that you want to give files/directories ownership.
  3) HTTPD group name (defaults to www-data for Apache).

Usage: (sudo) bash ${0##*/} --drupal_path=PATH --drupal_user=USER --httpd_group=GROUP
Example: (sudo) bash ${0##*/} --drupal_path=/usr/local/apache2/htdocs --drupal_user=john --httpd_group=www-data
HELP
exit 0
}

if [ $(id -u) != 0 ]; then
  printf "**************************************\n"
  printf "* Error: You must run this with sudo or root*\n"
  printf "**************************************\n"
  print_help
  exit 1
fi

drupal_path=${1%/}
drupal_user=${2}
httpd_group="${3:-www-data}"

# Parse Command Line Arguments
while [ "$#" -gt 0 ]; do
  case "$1" in
    --drupal_path=*)
        drupal_path="${1#*=}"
        ;;
    --drupal_user=*)
        drupal_user="${1#*=}"
        ;;
    --httpd_group=*)
        httpd_group="${1#*=}"
        ;;
    --help) print_help;;
    *)
      printf "***********************************************************\n"
      printf "* Error: Invalid argument, run --help for valid arguments. *\n"
      printf "***********************************************************\n"
      exit 1
  esac
  shift
done

if [ -z "${drupal_path}" ] || [ ! -d "${drupal_path}/sites" ] || [ ! -f "${drupal_path}/core/modules/system/system.module" ] && [ ! -f "${drupal_path}/modules/system/system.module" ]; then
  printf "*********************************************\n"
  printf "* Error: Please provide a valid Drupal path. *\n"
  printf "*********************************************\n"
  print_help
  exit 1
fi

if [ -z "${drupal_user}" ] || [[ $(id -un "${drupal_user}" 2> /dev/null) != "${drupal_user}" ]]; then
  printf "*************************************\n"
  printf "* Error: Please provide a valid user. *\n"
  printf "*************************************\n"
  print_help
  exit 1
fi

cd $drupal_path
printf "Changing ownership of all contents of "${drupal_path}":\n user => "${drupal_user}" \t group => "${httpd_group}"\n"
chown -R ${drupal_user}:${httpd_group} .

printf "Changing permissions of all directories inside "${drupal_path}" to "rwxr-x---"...\n"
find . -type d -exec chmod u=rwx,g=rx,o= '{}' \;

printf "Changing permissions of all files inside "${drupal_path}" to "rw-r-----"...\n"
find . -type f -exec chmod u=rw,g=r,o= '{}' \;

printf "Changing permissions of "files" directories in "${drupal_path}/sites" to "rwxrwx---"...\n"
cd sites
find . -type d -name files -exec chmod ug=rwx,o= '{}' \;

printf "Changing permissions of all files inside all "files" directories in "${drupal_path}/sites" to "rw-rw----"...\n"
printf "Changing permissions of all directories inside all "files" directories in "${drupal_path}/sites" to "rwxrwx---"...\n"
for x in ./*/files; do
  find ${x} -type d -exec chmod ug=rwx,o= '{}' \;
  find ${x} -type f -exec chmod ug=rw,o= '{}' \;
done
echo "Done setting proper permissions on files and directories"

And need to invoke the command:

sudo bash /Applications/XAMPP/xamppfiles/htdocs/fix-permissions.sh --drupal_path=/Applications/XAMPP/xamppfiles/htdocs/rkmission --drupal_user=daemon --httpd_group=admin

In my case the user on which Apache is running is 'daemon'. You can identify the user by just running this php script in a php file through localhost:

<?php echo exec('whoami');?>

Below is the right user with right file permissions for Drupal:

enter image description here

You might have to change it back once it is transported back to server!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNirAv JaInView Question on Stackoverflow
Solution 1 - PhpRaphaël VOView Answer on Stackoverflow
Solution 2 - PhprahuldmView Answer on Stackoverflow
Solution 3 - PhpHammad KhanView Answer on Stackoverflow
Solution 4 - PhpVictor EjioguView Answer on Stackoverflow
Solution 5 - PhpAasim YazView Answer on Stackoverflow
Solution 6 - PhpRaj KumarView Answer on Stackoverflow
Solution 7 - PhpFlorian BraunView Answer on Stackoverflow
Solution 8 - PhpGiangimgsView Answer on Stackoverflow
Solution 9 - PhpChineduView Answer on Stackoverflow
Solution 10 - Phpmiberg81View Answer on Stackoverflow
Solution 11 - PhpMrMadsenView Answer on Stackoverflow
Solution 12 - PhpSeetpal singhView Answer on Stackoverflow
Solution 13 - PhpJay BharatView Answer on Stackoverflow
Solution 14 - PhpRishabh GuptaView Answer on Stackoverflow
Solution 15 - PhpimranView Answer on Stackoverflow
Solution 16 - PhpRaj Pawan GumdalView Answer on Stackoverflow