前の記事「macOS(15.2)SequoiaでMAMP:[Homebrew]Apacheのインストール」において「新しいiMac(Sequoia, Apple M4)」にインストールした「Homebrew」にApacheをインストールしました。この記事では、Apacheインストール後にPHPを追加インストールした際のログを記載しています。
[HomeBrew]PHPのインストール
「brew install」コマンドで「php@8.3」をインストールしました。
% brew search php ==> Formulae brew-php-switcher php-cs-fixer php@8.3 phpmyadmin pup php php@8.1 phpbrew phpstan pop php-code-sniffer php@8.2 phpmd phpunit pcp % brew install php@8.3 : ==> Installing php@8.3 : To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php_module /opt/homebrew/opt/php@8.3/lib/httpd/modules/libphp.so <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.html The php.ini and php-fpm.ini file can be found in: /opt/homebrew/etc/php/8.3/ php@8.3 is keg-only, which means it was not symlinked into /opt/homebrew, because this is an alternate version of another formula. If you need to have php@8.3 first in your PATH, run: echo 'export PATH="/opt/homebrew/opt/php@8.3/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/opt/homebrew/opt/php@8.3/sbin:$PATH"' >> ~/.zshrc For compilers to find php@8.3 you may need to set: export LDFLAGS="-L/opt/homebrew/opt/php@8.3/lib" export CPPFLAGS="-I/opt/homebrew/opt/php@8.3/include" To start php@8.3 now and restart at login: brew services start php@8.3 Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/php@8.3/sbin/php-fpm --nodaemonize %
HomeBrewの指示に従い、「~/.zshrc」にphp@8.3の設定を追加しました。
% echo 'export PATH="/opt/homebrew/opt/php@8.3/bin:$PATH"' >> ~/.zshrc % echo 'export PATH="/opt/homebrew/opt/php@8.3/sbin:$PATH"' >> ~/.zshrc % echo 'export LDFLAGS="-L/opt/homebrew/opt/php@8.3/lib"' >> ~/.zshrc % echo 'export CPPFLAGS="-I/opt/homebrew/opt/php@8.3/include"' >> ~/.zshrc % source ~/.zshrc
「 ~/.zshrc」の内容
export PATH="/opt/homebrew/opt/php@8.3/bin:$PATH" export PATH="/opt/homebrew/opt/php@8.3/sbin:$PATH" export LDFLAGS="-L/opt/homebrew/opt/php@8.3/lib" export CPPFLAGS="-I/opt/homebrew/opt/php@8.3/include"
Apache2.4とPHP8.3の連携設定
Apache2.4とPHP8.3を連携するために、エディタ(nano)をroot権限で使用(sudo)してApacheの「httpd.conf」を修正しました。
% sudo nano /opt/homebrew/etc/httpd/httpd.conf
php_module(libphp.so)の読み込み設定を追記しました。
LoadModule php_module /opt/homebrew/opt/php@8.3/lib/httpd/modules/libphp.so
phpの拡張子を「.php」とする設定を追記しました。
<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>
DirectoryIndexに「index.php」を追記しました。
DirectoryIndex index.php index.html
PHPの設定(php.ini)の編集
HomebrewでインストールしたPHPを設定するファイルは、「php --ini
」コマンドで表示される”/opt/homebrew/etc/php/8.3/php.ini”です。エディタ(nano)をroot権限で使用(sudo)して「php.ini」の修正を行いました。
% php --ini Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.3 Loaded Configuration File: /opt/homebrew/etc/php/8.3/php.ini Scan for additional .ini files in: /opt/homebrew/etc/php/8.3/conf.d Additional .ini files parsed: /opt/homebrew/etc/php/8.3/conf.d/ext-opcache.ini % sudo nano /opt/homebrew/etc/php/8.3/php.ini %
タイムゾーンを”Asia/Tokyo”に設定しました。
;-; date.timezone = date.timezone = 'Asia/Tokyo'
error_reportingの値を以下に変更して、将来的にサポートされなくなる関数が使用されている時の警告を表示させないようにしました。
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
ポストとアップロードのMAXサイズを変更しました。
;-; post_max_size = 8M post_max_size = 20M ;-; upload_max_filesize = 2M upload_max_filesize = 20M
AoacheとPHPの連携動作確認
「brew services restart httpd」コマンドで、httpdを再起動しました。
% brew services restart httpd Stopping `httpd`... (might take a while) ==> Successfully stopped `httpd` (label: homebrew.mxcl.httpd) ==> Successfully started `httpd` (label: homebrew.mxcl.httpd) %
「”/Users/{username}/LocalSites/”」フォルダに新規作成した「phpinfo.php」がブラウザで表示できることを確認して、php8.3のインストールを完了しました。次は、MariaDBのインストールです。
// phpinfo.php <?php phpinfo(); ?>
macOS(15.1)SequoiaでMAMP:関連記事
- macOS(15.2)SequoiaでMAMP:[Homebrew]の再インストール
- macOS(15.2)SequoiaでMAMP:[Homebrew]Apacheのインストール
- macOS(15.2)SequoiaでMAMP:[HomeBrew]PHPのインストール(この記事)
- macOS(15.2)SequoiaでMAMP:[Homebrew]MariaDBのインストール
- macOS(15.2)SequoiaでMAMP:[Homebrew]phpMyAdminのインストール
コメント