By 001

2010-03-05 03:41:30 8 Comments

I have just installed CentOS, Apache and PHP. When I visit my site, it says "forbidden". By default it's not loading the index.php file.

When I visit, it works fine.

Any idea how to fix that issue?


@Martlark 2018-03-25 22:43:22

Same issue for me. My solution was that mod_dir was not enabled and apache2 was not issuing an error when reading the directive in my VirtualHost file:

DirectoryIndex index.html

Using the commands:

sudo a2enmod dir
sudo sudo service apache2 restart

Fixed the issue.

@TR_SLimey 2019-07-06 19:57:24

I think you mean a2enmod?

@MelPogz 2018-10-24 14:39:38

This one works like a charm!


<IfModule dir_module>
    DirectoryIndex index.html
     DirectoryIndex index.php

then after that from

<Files ".ht*">
    Require all denied


 <Files ".ht*">
    Require all granted

@Excellent Lawrence 2018-10-16 16:30:03

This post might be old but i am just posting it incase it helps some other person, I would not advise to Create a .htaccess file in your web root and change the index. I feel it is better to follow the steps

  1. Go to the conf folder of your apache folder mine is


  2. Open the file named


  3. Go to the section

    <IfModule dir_module>
       DirectoryIndex index.html 
  4. Add index.php to it as shown below

     <IfModule dir_module>
      DirectoryIndex index.html index.php

This way, it still picks index.html and index.php as the default index but giving priority to index.html because index.html came before *index.php. By this I mean in you have both index.html and index.php in the same directory, the index.html will be used as the default index except you write **index.php* before index.hml

I hope it helps someone... Happy Coding

@Dung 2018-04-11 19:56:41

Step by step and Full instruction for Ubuntu 16.04.4 LTS and Apache/2.4.18

"sudo -s"

"cd /etc/apache2/mods-enabled"

"vi dir.conf" and move index.php to right after DirectoryIndex like below and save file then restart apache server.

DirectoryIndex index.php index.html index.cgi index.xhtml index.htm

"service apache2 restart"

If you do not see dir.conf then you will need to load it (google for how to)


@John Rix 2018-01-05 00:19:03

I had a similar symptom. In my case though, my idiocy was in unintentionally also having an empty index.html file in the web root folder. Apache was serving this rather than index.php when I didn't explicitly request index.php, since DirectoryIndex was configured as follows in mods-available/dir.conf:

DirectoryIndex index.html index.cgi index.php index.xhtml index.htm

That is, 'index.html' appears ahead of 'index.php' in the priority list. Removing the index.html file from the web root naturally resolved the problem. D'oh!

@Maruf 2014-11-02 14:05:31

This might be helpful to somebody. here is the snippet from httpd.conf (Apache version 2.2 windows)

# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
<IfModule dir_module>
    DirectoryIndex index.html
    DirectoryIndex index.php

now this will look for index.html file if not found it will look for index.php.

@Phil Errington 2014-09-23 10:53:42

I had same problem with a site on our direct admin hosted site. I added

DirectoryIndex index.php

as a custom httd extension (which adds code to a sites httpd file) and the site then ran the index.php by default.

@Rupak Rokade 2014-04-15 08:22:44

After reading all this and trying to fix it, I got a simple solution on ubuntu forum ( The problem lies with libapache2-mod-php5 module. Thats why the browser downloads the index.php file rather than showing the web page. Do the following. If sudo a2enmod php5 returns module does not exist then the problem is with libapache2-mod-php5. Purge remove the module with command sudo apt-get --purge remove libapache2-mod-php5 Then install it again sudo apt-get install libapache2-mod-php5

@Zitun 2014-06-30 12:21:35

For info : in some Apache2 conf you must add the DirectoryIndex command in mods_enabled/dir.conf (it's not located in apache2.conf)

@M_M 2011-11-02 09:00:04

While adding 'DirectoryIndex index.php' to a .htaccess file may work,


In general, you should never use .htaccess files

This is quoted from
Although this refers to an older version of apache, I believe the principle still applies.

Adding the following to your httpd.conf (if you have access to it) is considered better form, causes less server overhead and has the exact same effect:

<Directory /myapp>
DirectoryIndex index.php

@Hayden Thring 2013-03-10 23:41:11

that's all fine and dandy if you have access to that file

@Matthew Johnson 2014-02-03 00:04:59

+1 for that. It's the preferred method unless you don't have access to httpd.conf.

@Alex W 2015-02-11 16:58:36

I believe adding this to the default-ssl configuration file is also fine, if you're using HTTPS.

@Ben Rowe 2010-03-05 03:54:44

At a guess I'd say the directory index is set to index.html, or some variant, try:

DirectoryIndex index.html index.php

This will still give index.html priority over index.php (handy if you need to throw up a maintenance page)

@Webnet 2013-05-03 13:46:29

Mine looks like this but is unfortunately downloading the index.php instead of executing it.

@Merey Nurlan 2019-12-09 01:02:29

@Webnet then you should consider changing Type and LoadModules to php so it read php […

@animuson 2010-03-05 03:49:25

Try creating a .htaccess file with the following

DirectoryIndex index.php

Edit: Actually, isn't there a 'php-apache' package or something that you're supposed to install with both of them?

@John Himmelman 2010-03-05 03:48:58

Apache needs to be configured to recognize index.php as an index file.

The simplest way to accomplish this..

  1. Create a .htaccess file in your web root.

  2. Add the line...

DirectoryIndex index.php

Here is a resource regarding the matter...

Edit: I'm assuming apache is configured to allow .htaccess files. If it isn't, you'll have to modify the setting in apache's configuration file (httpd.conf)

@staticsan 2010-03-05 03:51:09

It should probably be in the php.conf file that apache loads.

@John Himmelman 2010-03-05 04:25:56

I think you mean php.ini. Regardless, his apache isn't recognizing index.php as a directory index file. Whether its handling php files is another apache config issue.

@Navid Einackchi 2015-07-02 08:54:18

dont forget to restart apache!! as i did! :/

Related Questions

Sponsored Content

26 Answered Questions

[SOLVED] Nginx serves .php files as downloads, instead of executing them

  • 2014-08-31 10:24:17
  • Apeiron
  • 241416 View
  • 151 Score
  • 26 Answer
  • Tags:   php nginx php-5.5

20 Answered Questions

[SOLVED] Reference — What does this symbol mean in PHP?

18 Answered Questions

[SOLVED] PHP parse/syntax errors; and how to solve them

25 Answered Questions

[SOLVED] Apache is downloading php files instead of displaying them

  • 2013-08-24 19:10:18
  • Anthony Gainor
  • 264218 View
  • 90 Score
  • 25 Answer
  • Tags:   php apache centos

7 Answered Questions

[SOLVED] Redirect all to index.php using htaccess

  • 2013-08-23 15:06:58
  • David Ericsson
  • 300437 View
  • 125 Score
  • 7 Answer
  • Tags:   php .htaccess

20 Answered Questions

[SOLVED] Wildcards in a Windows hosts file

11 Answered Questions

[SOLVED] Nginx 403 forbidden for all files

7 Answered Questions

[SOLVED] How does PHP 'foreach' actually work?

1 Answered Questions

[SOLVED] index.php is not loading by default in apache2

  • 2017-05-24 23:54:39
  • FrostedCookies
  • 4263 View
  • 0 Score
  • 1 Answer
  • Tags:   php apache .htaccess

Sponsored Content