LoginSignup
1
1

More than 5 years have passed since last update.

CentOS PHP

Last updated at Posted at 2017-09-10

javascriptでいろいろ遊んでいたらPHPを使って見たくなったので、
PHPの環境を構築したので、メモ

まず、必要なレジストリレポジトリを入れる。(EPELとRemi)

EPEL
yum install epel-release
Remi
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

PHP7をインストール

php7
yum --enablerepo=epel,remi,remi-php70 install php70

Apacheをインストール

apavhe
yum install httpd

これで下準備完了。
次にApacheの設定をする。
初期設定だと、phpはhtmlの拡張子で動かない(認識しない)ので、.htmlでもphpが動くように
Apacheの設定する
/etc/httpd/conf/httpd.conf
をvimでもgeditでもいいので開く
そして以下を追加すると.htmlは.phpと識別する

AddType application/x-httpd-php .html .htm
AddHandler application/x-httpd-php .html .htm

これで終了と思いきや

<?php echo '<p>Hello World</p>'; ?> 

表示されない。
なんと、よく見る<? ~ ?>は省略タグで、本来は
<?php ~ ?>
の略らしいので、Apacheの設定を変えて省略タグを使えるようにする(非推奨らしい)

etc/php.iniの

short_open_tag = Off

short_open_tag = On

にする

以上で、設定終了

1
1
1

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
1
1