ブログ - (2号機) PHP7.2が使えるまで
brewでインストールしたphp7.2の詳細情報を確認.
DirectoryIndexの付け替え.phpの優先度を先にするのと,PHPのモジュールと拡張子の設定を追加.
作業前にファイルのバックアップを.
編集した結果のdiffをとる.
文法間違いがないか確認.
問題ないので,停止して,起動する.
PHPが動くか確認.
test.txtに結果を保存するようにして,curlコマンドを実行する.
中身を確認.
動きました.
$ brew info php72🆑
php@7.2: stable 7.2.17 [keg-only]
General-purpose scripting language
https://secure.php.net/
/usr/local/Cellar/php@7.2/7.2.17 (509 files, 75.7MB)
Built from source on 2019-04-11 at 01:27:23
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/php@7.2.rb
==> Dependencies
Build: httpd ✔, pkg-config ✔
Required: apr ✔, apr-util ✔, argon2 ✔, aspell ✔, autoconf ✔, curl-openssl ✔,
freetds ✔, freetype ✔, gettext ✔, glib ✔, gmp ✔, icu4c ✔, jpeg ✔, libpng ✔,
libpq ✔, libsodium ✔, libzip ✔, openldap ✔, openssl ✔, sqlite ✔,
tidy-html5 ✔, unixodbc ✔, webp ✔
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.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:
/usr/local/etc/php/7.2/
php@7.2 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have php@7.2 first in your PATH run:
echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.bash_profile
For compilers to find php@7.2 you may need to set:
export LDFLAGS="-L/usr/local/opt/php@7.2/lib"
export CPPFLAGS="-I/usr/local/opt/php@7.2/include"
To have launchd start php@7.2 now and restart at login:
brew services start php@7.2
Or, if you don't want/need a background service you can just run:
php-fpm
==> Analytics
install: 17,123 (30 days), 53,229 (90 days), 70,669 (365 days)
install_on_request: 16,922 (30 days), 52,686 (90 days), 70,069 (365 days)
build_error: 0 (30 days)
$
作業前にファイルのバックアップを.
$ cp /usr/local/etc/httpd/httpd.conf /usr/local/etc/httpd/httpd.conf.v001🆑
$
$ diff /usr/local/etc/httpd/httpd.conf.v001 /usr/local/etc/httpd/httpd.conf🆑
279c279,280
< DirectoryIndex index.html
---
> # DirectoryIndex index.html
> DirectoryIndex index.php index.html
531a533,537
> #for PHP72
> LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so
> <FilesMatch \.php$>
> SetHandler application/x-httpd-php
> </FilesMatch>
[pluto:server 20:08:49 /usr/local/etc/httpd/extra ]
$
$ apachectl configtest🆑
Syntax OK
$
$ apachectl stop🆑
$ apachectl start🆑
$ ps -ef|grep httpd🆑
501 77440 1 0 8:11PM ?? 0:00.05 /usr/local/opt/httpd/bin/httpd -k start
501 77441 77440 0 8:11PM ?? 0:00.00 /usr/local/opt/httpd/bin/httpd -k start
501 77442 77440 0 8:11PM ?? 0:00.00 /usr/local/opt/httpd/bin/httpd -k start
501 77443 77440 0 8:11PM ?? 0:00.00 /usr/local/opt/httpd/bin/httpd -k start
501 77444 77440 0 8:11PM ?? 0:00.00 /usr/local/opt/httpd/bin/httpd -k start
501 77445 77440 0 8:11PM ?? 0:00.00 /usr/local/opt/httpd/bin/httpd -k start
501 77450 77050 0 8:12PM ttys002 0:00.00 grep httpd
$
$ ls -la /usr/local/var/www/🆑
total 8
drwxr-xr-x 5 server admin 170 4 12 20:02 .
drwxrwxr-x 8 server admin 272 4 10 23:36 ..
drwxr-xr-x 6 server admin 204 4 10 23:36 cgi-bin
-rw-r--r-- 1 server admin 45 6 12 2007 index.html
-rw-r--r-- 1 server admin 22 4 12 20:02 index.php🈁
$ cat /usr/local/var/www/index.php🆑
<?php
phpinfo();
?>
$
$ curl -o test.txt localhost:8080/index.php🆑
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 101k 0 101k 0 0 8478k 0 --:--:-- --:--:-- --:--:-- 9249k
$
$ tail test.txt🆑
<p>
This program is free software; you can redistribute it and/or modify it under
the terms of the PHP License as published by the PHP Group and included in
the distribution in the file: LICENSE
</p>
<p>This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
</p>
<p>If you did not receive a copy of the PHP license, or have any questions
about PHP licensing, please contact license@php.net.
</p>
</td></tr>
</table>
</div></body></html>
$