William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

Apache 403 Forbidden Error and Solution

The Apache 403 Forbidden Error is quite normal: A 403 status code indicates that the client cannot access the requested resource. It means the permissions on the server do not allow what was being asked. If found this error, there are several ways to do quick fix.

(1) Accessible: privilege issue
For the web scripts (php or perl or whatever) in Linux:

  • for php script
    php interpreter (/usr/bin/php) needs the privilege to access and parse it, so make sure the php script is accessible and readable;
    Normally the directory (which hold php scripts) should have the privilege ‘775’ and the php script file itself is ‘664’.
  • for perl cgi script
    Make sure the perl script is executable: normally the directory (which hold php scripts) should have the privilege ‘775’ and the php script file itself is ‘775’.
    perl cgi is running by itself: in the first line of the perl cgi, is its shabang:
    #! /usr/bin/perl
    When executing, this command line forks a process to execute itself – the cgi process.

(2) httpd.conf

Usually for easy setup and access web application, I use a lot of aliases in httpd.conf, e.g.:
Alias /test “c:\…\desktop\william\projects\test\”
This maybe the simplest way to locate a web application in httpd.conf:
http://localhost/test/
This kind of configuration is easy and convenient. However make sure to configure it correctly.
There are 2 level of previlege assignment in httpd.conf:

(A) root dir:
The DOCUMENTROOT default can’t be access, in the local machine, we’d better to change the previlege like this:

      <Directory />
      Options Indexes FollowSymLinks Includes ExecCGI
      AllowOverride None
      Order deny,allow
      Allow from all
      </Directory> 

(B) individual dir:
Instead of above settings globally, the following just setup the privilege for ‘/test’:

      <Directory /test>
      Options Indexes FollowSymLinks Includes ExecCGI
      AllowOverride None
      Order deny,allow
      Allow from all
      </Directory>

Either of these 2 ways makes http://localhost/test/ work fine.

(3) make the interpreter searchable.

e.g., in Windows, if php.exe is not at the %PATH% env variables, the 403 error occurs. So double check php is available in the %PATH%:

Conrol Panel -> Advanced System settings -> Advanced -> Environment Variables -> System variables-> path:
path=%PATH%;C:\xampp\php\;
The interpreter php.exe is searchable, so the 403 issue is fixed.

(4) Make sure you have permission to use .htaccess file for Apache web server.
If Apache has overrides disabled. you will bump back with a 403 error.

The above solved my most 403 issues.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: