LoginSignup
0
0

PHP include_pathの設定

Posted at

PHPにinclude_pathを追加するには

対象者

・ include_pathの追加方法が分からない
・ そもそもphp.iniってどこにあるんだっけ?

PHPバージョン

PHP 8.2.18

OS

macOS sonoma v14.4.1

php.iniファイルってどこにあるの?

phpファイルを探す方法はいくつかありますが、コンソールで確認してみましょう.
(webで確認する方法もありますが、やってることは同じです.)

$ php -r "echo phpinfo();" | grep "php.ini"
Configuration File (php.ini) Path => /opt/homebrew/etc/php/8.2
Loaded Configuration File => /opt/homebrew/etc/php/8.2/php.ini

phpinfoを見れば記述があるのですが、量が多いので、"php.ini"でgrepしています.

場所が分かったので、ファイルを見てみましょう.
今は、include_pathを確認したいので、以下のコマンドで確認してみます.

$ cat /opt/homebrew/etc/php/8.2/php.ini | grep include_path
;include_path = ".:/php/includes"
;include_path = ".;c:\php\includes"
; PHP's default setting for include_path is ".;/path/to/php/pear"
; Enables or disables file search in include_path optimization

先頭の「;」は全てコメントアウトなので、実質現在はinclude_pathが全く設定されていない状態になります.
では、編集しましょう.
iniファイルはテキストエディタで編集可能ですので、お好きなエディタ等で編集してください.

$ open /opt/homebrew/etc/php/8.2/

上記のコマンドでファイルが存在するディレクトリを開いて、ファイルを編集しましょう.

0
0
0

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