Programing

index.php가 기본적으로로드되지 않음

lottogame 2020. 8. 15. 09:45
반응형

index.php가 기본적으로로드되지 않음


방금 CentOS, Apache 및 PHP를 설치했습니다. 내 사이트 http://example.com/myapp/을 방문하면 "금지됨"이라고 표시됩니다. 기본적으로 index.php 파일을로드하지 않습니다.

http://example.com/myapp/index.php를 방문하면 정상적으로 작동합니다.

그 문제를 해결하는 방법을 아십니까?


index.php를 인덱스 파일로 인식하도록 Apache를 구성해야합니다.

이 작업을 수행하는 가장 간단한 방법 ..

  1. 웹 루트에 .htaccess 파일을 만듭니다.

  2. 줄 추가 ...

DirectoryIndex index.php

다음은 문제에 관한 리소스입니다 ...
http://www.twsc.biz/twsc_hosting_htaccess.php

편집 : 아파치가 .htaccess 파일을 허용하도록 구성되어 있다고 가정합니다. 그렇지 않은 경우 아파치의 구성 파일 (httpd.conf)에서 설정을 수정해야합니다.


.htaccess 파일에 'DirectoryIndex index.php'를 추가하는 동안 작동 할 수 있습니다.

노트:

일반적으로 .htaccess 파일을 사용해서는 안됩니다.

이것은 http://httpd.apache.org/docs/1.3/howto/htaccess.html 에서 인용되었습니다 . 이것은
이전 버전의 아파치를 지칭하지만 원칙은 여전히 ​​적용됩니다.

httpd.conf에 다음을 추가하면 (액세스 권한이있는 경우) 더 나은 형식으로 간주되고 서버 오버 헤드가 줄어들고 똑같은 효과가 있습니다.

<Directory /myapp>
DirectoryIndex index.php
</Directory>

추측에 디렉토리 색인이 index.html 또는 일부 변형으로 설정되었다고 말하고 싶습니다.

DirectoryIndex index.html index.php

여전히 index.php보다 index.html 우선 순위를 부여합니다 (유지 보수 페이지를 표시해야하는 경우 편리함).


이것은 누군가에게 도움이 될 수 있습니다. 다음은 httpd.conf (Apache 버전 2.2 창)의 스 니펫입니다.

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

이제 index.html 파일을 찾지 못하면 index.php를 찾습니다.


다음을 사용하여 .htaccess 파일을 만들어보십시오.

DirectoryIndex index.php

편집 : 사실, 'php-apache'패키지 또는 두 가지 모두와 함께 설치 해야하는 것이 있습니까?


직접 관리 호스팅 사이트의 사이트와 동일한 문제가 발생했습니다. 나는 추가했다

DirectoryIndex index.php

사용자 지정 httd 확장 (사이트 httpd파일에 코드 추가 )으로 지정한 다음 사이트는 index.php기본적으로 를 실행합니다 .


정보 : 일부 Apache2 conf에서는 mods_enabled / dir.conf에 DirectoryIndex 명령을 추가해야합니다 (apache2.conf에는 없음).


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!


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.pl 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)

Done.


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

    C:\Apache24\conf

  2. Open the file named

    httpd.conf

  3. Go to the section

    <IfModule dir_module>
       DirectoryIndex index.html 
    
     </IfModule>
    
  4. 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


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>

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.

참고URL : https://stackoverflow.com/questions/2384423/index-php-not-loading-by-default

반응형