25
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

apacheとphpを入れた環境でphpが動作せずにソースコードのまま表示される時

Last updated at Posted at 2016-05-31

apache,phpを単に入れただけではphpは動きません。
apacheの設定に手を加える必要があります。

apacheの設定を修正

※ こちら@oh-sky様のコメントを参考に修正しました。

[root@test-web ~]# vi /etc/httpd/conf/httpd.conf 

以下項目を追加
参考 : http://php.net/manual/ja/install.unix.apache2.php

httpd.conf
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

ついでにやっておいた方が良い設定

だいたい400行目あたりに「DirectoryIndex」という項目がある。

httpd.conf
DirectoryIndex index.html index.html.var

「index.php」を追記

httpd.conf
DirectoryIndex index.html index.html.var index.php

apacheの再起動

[root@test-web ~]# /etc/init.d/httpd restart   
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

[root@test-web ~]# 
25
27
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?