I have just installed CentOS, Apache and PHP. When I visit my site http://example.com/myapp/, it says "forbidden". By default it's not loading the index.php file.
When I visit http://example.com/myapp/index.php, it works fine.
Any idea ho开发者_JAVA百科w to fix that issue?
Apache needs to be configured to recognize index.php as an index file.
The simplest way to accomplish this..
Create a .htaccess file in your web root.
Add the line...
DirectoryIndex index.php
Here is a resource regarding the matter...
http://www.twsc.biz/twsc_hosting_htaccess.php
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)
While adding 'DirectoryIndex index.php' to a .htaccess file may work,
NOTE:
In general, you should never use .htaccess files
This is quoted from http://httpd.apache.org/docs/1.3/howto/htaccess.html
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
</Directory>
Edit: At the time of edit, the v1.3 documentation is down. The v2.4 documentation (current version at time of edit) has a similar stance:
In general, use of
.htaccess
files should be avoided when possible. Any configuration that you would consider putting in a.htaccess
file, can just as effectively be made in a<Directory>
section in your main server configuration file.
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)
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
</IfModule>
now this will look for index.html file if not found it will look for index.php.
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
Go to the conf folder of your apache folder mine is
C:\Apache24\conf
Open the file named
httpd.conf
Go to the section
<IfModule dir_module> DirectoryIndex index.html </IfModule>
Add index.php to it as shown below
<IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
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
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?
This one works like a charm!
First
<IfModule dir_module>
DirectoryIndex index.html
DirectoryIndex index.php
</IfModule>
then after that from
<Files ".ht*">
Require all denied
</Files>
to
<Files ".ht*">
Require all granted
</Files>
After reading all this and trying to fix it, I got a simple solution on ubuntu forum (https://help.ubuntu.com/community/ApacheMySQLPHP). 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
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.pl 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!
精彩评论