Help us understand the problem. What is going on with this article?

Apacheのhttpd.confにPHPを設定する方法

More than 1 year has passed since last update.

PHPモジュールの設定はhttpd.confに書かなくていいというのを見て便利と思ったのでやってみた。

  • 環境
    • macOS Mojave バージョン10.14.3
    • Apache 2.4.37 (Unix)
    • PHP 7.3.1 (cli)

PHPの情報を確認する

$ which php
/usr/local/bin/php

$ php -v
PHP 7.3.1 (cli) (built: Jan 10 2019 13:15:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.1, Copyright (c) 1999-2018, by Zend Technologies

$ php --ini | grep php.ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.3
Loaded Configuration File:         /usr/local/etc/php/7.3/php.ini

PHP用の設定ファイルを作る

Includeで指定するディレクトリにPHP用の設定ファイルを作る。
今回の場合は、 /usr/local/etc/httpd/extraphp71.conf を作る.

PHP用の設定ファイルを作る
$ vi /usr/local/etc/httpd/extra/php73.conf

# httpd.confにをincludeする設定ファイル
#
# PHPの場所 : /usr/local/bin/php
# 対象バージョン : PHP 7.3.1 (cli) (built: Jan 10 2019 13:15:37) ( NTS )
#
# これ↓をhttpd.confに追記する
#Include /usr/local/etc/httpd/extra/php73.conf

#
# AddType allows you to add to or override the MIME configuration
# file specified in TypesConfig for specific file types.
#
AddType application/x-httpd-php .php

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
LoadModule php7_module "/usr/local/Cellar/php/7.3.1/lib/httpd/modules/libphp7.so"

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

#
# php.iniの場所
#
PHPIniDir "/usr/local/etc/php/7.3/php.ini"


# 保存して確認する。
$ ls -l /usr/local/etc/httpd/extra/ | grep php
-rw-r--r--  1 mana  apache   1224 12 21 00:26 php71.conf #<<< バージョン違いもあると便利
-rw-r--r--  1 mana  apache   1065  3  3 18:50 php73.conf

httpd.confに作った設定ファイルを設定する

httpd.confの一番最後
# PHPの設定
# Include /usr/local/etc/httpd/extra/php71.conf
Include /usr/local/etc/httpd/extra/php73.conf

見てみる

# 起動する
$ apachectl start

見てみる・・・できた!便利だ。
スクリーンショット 2019-03-03 19.26.00.png

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした