MacBook 重裝 Apache 和 PHP 7.2

20190718 本來是要做一個 php 的驗證碼,結果發現在我的 macbook 上死活不出圖片,但是在windows 上是可以的!斷定問題出在環境上!

macOS Mojave 10.14.5 
WEB: 自帶的 apache
PHP:自帶的 php 7.1

經過一大圈折騰,最終的結果是:重裝了 apache,重裝了 php7.2,原因在於蘋果10.14之後,內置的 apache,不再加載那些第三方組件庫!

原文如下

Detected macOS Mojave 10.14. There are serious issues with it, due to the original apache not loading
foreign libraries anymore. PHP within apache will most certainly not work anymore if you proceed!
The cli version still will.
See this issue at https://github.com/liip/php-osx/issues/249 for details and discussion
...

1、百度找資料

https://github.com/liip/php-osx/issues/249
上這裏找辦法!
這裏再抄寫一次最終的解決步驟

  1. macOS comes with pre-installed apache, following are the commands to stop it and prevent from autostart on boot:
    $ sudo apachectl stop
    $ sudo launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null

  2. Install apache through homebrew
    $ brew install httpd

  3. Check apache installation through the following command and the output should be /usr/local/bin/apachectl
    $ which apachectl

  4. Start apache through the following command
    $ sudo apachectl -k start

  5. Set apache to startup on bootload
    $ sudo brew services start httpd

  6. Re-install php from https://php-osx.liip.ch link.

2、我的錯誤

我是在先 brew install php 7.2 之後,纔看到的以上網址,所以,以上 step 6 我來回浪費了一些時間!因爲我在 step 6 最後都是失敗的!
https://php-osx.liip.ch/
這裏列舉了各個 php 版本的重裝 php 方式,我嘗試了 7.2 和 7.1

$ curl -s https://php-osx.liip.ch/install.sh | bash -s 7.2

****
[WARNING]
Detected macOS Mojave 10.14. There are serious issues with it, due to the original apache not loading
foreign libraries anymore. PHP within apache will most certainly not work anymore if you proceed!
The cli version still will.
See this issue at https://github.com/liip/php-osx/issues/249 for details and discussion
****
Restart this script with
 curl -s https://php-osx.liip.ch/install.sh | bash -s force 7.2
to really install it
****

$ curl -s https://php-osx.liip.ch/install.sh | bash -s force 7.2
經過漫長的下載、等待之後
錯誤如下:

當時沒有抄錄下來,大概記得是
did or could not .....

只好冷靜下來,一步一步的設置!
想回頭,回頭的繁瑣和繼續前行的難度,工作量都不小
(抱歉!我沒有使用 TM 的習慣!)

3、設置 apache

  1. 新的 apache 在哪裏?
    $ which apachectl

     /usr/local/bin/apachectl
    

    之前記錄過,舊的 apache 在

     /usr/sbin/httpd
    
  2. 測試一下
    打開瀏覽器,輸入 127.0.0.1:8080
    It works!

  3. 配置文件在哪裏
    安裝的時候沒有注意,一時暈乎!後來在 ps 命令下看到了

    $ ps -ef |grep httpd

     0    84     1   0  5:44下午 ??         0:00.13 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
    70   235    84   0  5:44下午 ??         0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
    70   236    84   0  5:44下午 ??         0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
    70   237    84   0  5:44下午 ??         0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
    70   238    84   0  5:44下午 ??         0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
    70   239    84   0  5:44下午 ??         0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
    70   618    84   0  5:53下午 ??         0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
    70   619    84   0  5:53下午 ??         0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
        70   620    84   0  5:53下午 ??         0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
       501   660   394   0  6:03下午 ttys000    0:00.00 grep httpd
    

$ cd /usr/local/opt/
$ ls -l

total 0
lrwxr-xr-x  1 dhbm  admin  22  7 18 17:05 apache-httpd -> ../Cellar/httpd/2.4.34
lrwxr-xr-x  1 dhbm  admin  22  7 18 17:05 apache2 -> ../Cellar/httpd/2.4.34
  ...
  lrwxr-xr-t  1 dhbm  admin  22  7 18 17:05 httpd -> ../Cellar/httpd/2.4.34
  ...

apache2 和 apache-httpd 找了,都不是!
只有找這個 httpd

$ cd /usr/local/etc/httpd/
$ ls -l

total 200
-rw-r--r--   1 dhbm  admin      0  7 18 21:09 Caveats
drwxr-xr-x  14 dhbm  admin    448  7 18 17:05 extra
-rw-r--r--   1 dhbm  admin  21958  7 18 21:24 httpd.conf
-rw-r--r--   1 dhbm  admin  13077  7 18 17:05 magic
-rw-r--r--   1 dhbm  admin  60847  7 18 17:05 mime.types
drwxr-xr-x   4 dhbm  admin    128  7 18 17:05 original

看文件清淡和創建時間,應該這就是新的 apache 配置的地方了!

$ vim httpd.conf
Listen 8080 改成 Listen 80

sudo apachectl -k restart
再次測試 127.0.0.1,還是可以顯示 It works!
查找 DocumentRoot,看到了現在的 root 位置!

DocumentRoot "/usr/local/var/www"
<Directory "/usr/local/var/www">

cd /usr/local/var/www
建立一個 info.php,然後

http://127.0.0.1/info.php
結果原文顯示了!說明 php 支持沒有安裝!

$ cat info.php
<?php
phpinfo();
?>

3、 安裝 php 7.2

  1. $ brew search php
    **記錄很重要,一定先保存下來,後續問題需要查看

     ==> Formulae
     brew-php-switcher
     php
     php-code-sniffer
     php-cs-fixer
     [email protected]
     [email protected]
     [email protected] ✔
     phplint
     phpmyadmin
     phpunit
     homebrew/linuxbrew-core/brew-php-switcher
     homebrew/linuxbrew-core/php
     homebrew/linuxbrew-core/php-code-sniffer
     homebrew/linuxbrew-core/php-cs-fixer
     homebrew/linuxbrew-core/[email protected]
     homebrew/linuxbrew-core/[email protected]
     homebrew/linuxbrew-core/[email protected]
     
     ==> Casks
     eclipse-php                netbeans-php               phpstorm
    
  2. $ brew install php72

     pdating Homebrew...
     Fast-forwarded master to origin/master.
     ==> Auto-updated Homebrew!
     Updated 1 tap (homebrew/cask).
     No changes to formulae.
     
     ==> Installing dependencies for php: apr, openssl, apr-util, argon2, aspell, autoconf, freetds, libffi, pcre, glib, gmp, icu4c, libpq, libsodium, libzip, unixodbc
     ==> Installing php dependency: apr
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/apr-1.6.3.h
     ######################################################################## 100.0%
     ==> Pouring apr-1.6.3.high_sierra.bottle.tar.gz
     ==> Caveats
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because Apple's CLT package contains apr.
     
     If you need to have this software first in your PATH run:
       echo 'export PATH="/usr/local/opt/apr/bin:$PATH"' >> ~/.bash_profile
     
     ==> Summary
     🍺  /usr/local/Cellar/apr/1.6.3: 60 files, 1.3MB
     ==> Installing php dependency: openssl
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openssl-1.0
     ######################################################################## 100.0%
     ==> Pouring openssl-1.0.2o_2.high_sierra.bottle.tar.gz
     ==> Caveats
     A CA file has been bootstrapped using certificates from the SystemRoots
     keychain. To add additional certificates (e.g. the certificates added in
     the System keychain), place .pem files in
       /usr/local/etc/openssl/certs
     
     and run
       /usr/local/opt/openssl/bin/c_rehash
     
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
     
     If you need to have this software first in your PATH run:
       echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
     
     For compilers to find this software you may need to set:
         LDFLAGS:  -L/usr/local/opt/openssl/lib
         CPPFLAGS: -I/usr/local/opt/openssl/include
     
     ==> Summary
     🍺  /usr/local/Cellar/openssl/1.0.2o_2: 1,792 files, 12.3MB
     ==> Installing php dependency: apr-util
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/apr-util-1.
     ######################################################################## 100.0%
     ==> Pouring apr-util-1.6.1_1.high_sierra.bottle.tar.gz
     ==> Caveats
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because Apple's CLT package contains apr.
     
     If you need to have this software first in your PATH run:
       echo 'export PATH="/usr/local/opt/apr-util/bin:$PATH"' >> ~/.bash_profile
     
     ==> Summary
     🍺  /usr/local/Cellar/apr-util/1.6.1_1: 54 files, 778.2KB
     ==> Installing php dependency: argon2
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/argon2-2017
     ######################################################################## 100.0%
     ==> Pouring argon2-20171227.high_sierra.bottle.tar.gz
     🍺  /usr/local/Cellar/argon2/20171227: 11 files, 590KB
     ==> Installing php dependency: aspell
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/aspell-0.60
     ######################################################################## 100.0%
     ==> Pouring aspell-0.60.6.1_1.high_sierra.bottle.tar.gz
     ==> Caveats
     Installation of the 'is' (Icelandic) and 'nb' (Norwegian) dictionaries is
     currently broken. They can be installed manually.
     
     See: https://github.com/Homebrew/homebrew-core/issues/28074
     ==> Summary
     🍺  /usr/local/Cellar/aspell/0.60.6.1_1: 267 files, 35.6MB
     ==> Installing php dependency: autoconf
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/autoconf-2.
     ######################################################################## 100.0%
     ==> Pouring autoconf-2.69.high_sierra.bottle.4.tar.gz
     Error: The `brew link` step did not complete successfully
     The formula built, but is not symlinked into /usr/local
     Could not symlink bin/autoconf
     Target /usr/local/bin/autoconf
     already exists. You may want to remove it:
       rm '/usr/local/bin/autoconf'
     
     To force the link and overwrite all conflicting files:
       brew link --overwrite autoconf
     
     To list all files that would be deleted:
       brew link --overwrite --dry-run autoconf
     
     Possible conflicting files are:
     /usr/local/bin/autoconf
     /usr/local/bin/autoheader
     /usr/local/bin/autom4te
     /usr/local/bin/autoreconf
     /usr/local/bin/autoscan
     /usr/local/bin/autoupdate
     /usr/local/bin/ifnames
     /usr/local/share/autoconf/Autom4te/C4che.pm
     /usr/local/share/autoconf/Autom4te/ChannelDefs.pm
     /usr/local/share/autoconf/Autom4te/Channels.pm
     /usr/local/share/autoconf/Autom4te/Configure_ac.pm
     /usr/local/share/autoconf/Autom4te/FileUtils.pm
     /usr/local/share/autoconf/Autom4te/General.pm
     /usr/local/share/autoconf/Autom4te/Getopt.pm
     /usr/local/share/autoconf/Autom4te/Request.pm
     /usr/local/share/autoconf/Autom4te/XFile.pm
     /usr/local/share/autoconf/INSTALL
     /usr/local/share/autoconf/autoconf/autoconf.m4
     /usr/local/share/autoconf/autoconf/autoconf.m4f
     /usr/local/share/autoconf/autoconf/autoheader.m4
     /usr/local/share/autoconf/autoconf/autoscan.m4
     /usr/local/share/autoconf/autoconf/autotest.m4
     /usr/local/share/autoconf/autoconf/autoupdate.m4
     /usr/local/share/autoconf/autoconf/c.m4
     /usr/local/share/autoconf/autoconf/erlang.m4
     /usr/local/share/autoconf/autoconf/fortran.m4
     /usr/local/share/autoconf/autoconf/functions.m4
     /usr/local/share/autoconf/autoconf/general.m4
     /usr/local/share/autoconf/autoconf/go.m4
     /usr/local/share/autoconf/autoconf/headers.m4
     /usr/local/share/autoconf/autoconf/lang.m4
     /usr/local/share/autoconf/autoconf/libs.m4
     /usr/local/share/autoconf/autoconf/oldnames.m4
     /usr/local/share/autoconf/autoconf/programs.m4
     /usr/local/share/autoconf/autoconf/specific.m4
     /usr/local/share/autoconf/autoconf/status.m4
     /usr/local/share/autoconf/autoconf/types.m4
     /usr/local/share/autoconf/autom4te.cfg
     /usr/local/share/autoconf/autoscan/autoscan.list
     /usr/local/share/autoconf/autotest/autotest.m4
     /usr/local/share/autoconf/autotest/autotest.m4f
     /usr/local/share/autoconf/autotest/general.m4
     /usr/local/share/autoconf/autotest/specific.m4
     /usr/local/share/autoconf/m4sugar/foreach.m4
     /usr/local/share/autoconf/m4sugar/m4sh.m4
     /usr/local/share/autoconf/m4sugar/m4sh.m4f
     /usr/local/share/autoconf/m4sugar/m4sugar.m4
     /usr/local/share/autoconf/m4sugar/m4sugar.m4f
     /usr/local/share/autoconf/m4sugar/version.m4
     /usr/local/share/info/autoconf.info
     /usr/local/share/man/man1/autoconf.1
     /usr/local/share/man/man1/autoheader.1
     /usr/local/share/man/man1/autom4te.1
     /usr/local/share/man/man1/autoreconf.1
     /usr/local/share/man/man1/autoscan.1
     /usr/local/share/man/man1/autoupdate.1
     /usr/local/share/man/man1/config.guess.1
     /usr/local/share/man/man1/config.sub.1
     /usr/local/share/man/man1/ifnames.1
     ==> Caveats
     Emacs Lisp files have been installed to:
       /usr/local/share/emacs/site-lisp/autoconf
     ==> Summary
     🍺  /usr/local/Cellar/autoconf/2.69: 71 files, 3.0MB
     ==> Installing php dependency: freetds
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/freetds-1.0
     ######################################################################## 100.0%
     ==> Pouring freetds-1.00.94.high_sierra.bottle.tar.gz
     🍺  /usr/local/Cellar/freetds/1.00.94: 2,094 files, 11.9MB
     ==> Installing php dependency: libffi
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/libffi-3.2.
     ######################################################################## 100.0%
     ==> Pouring libffi-3.2.1.high_sierra.bottle.tar.gz
     ==> Caveats
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because some formulae require a newer version of libffi.
     
     For compilers to find this software you may need to set:
         LDFLAGS:  -L/usr/local/opt/libffi/lib
     
     ==> Summary
     🍺  /usr/local/Cellar/libffi/3.2.1: 16 files, 297.0KB
     ==> Installing php dependency: pcre
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/pcre-8.42.h
     ######################################################################## 100.0%
     ==> Pouring pcre-8.42.high_sierra.bottle.tar.gz
     🍺  /usr/local/Cellar/pcre/8.42: 204 files, 5.3MB
     ==> Installing php dependency: glib
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/glib-2.56.1
     ######################################################################## 100.0%
     ==> Pouring glib-2.56.1.high_sierra.bottle.tar.gz
     🍺  /usr/local/Cellar/glib/2.56.1: 430 files, 23.7MB
     ==> Installing php dependency: gmp
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/gmp-6.1.2_2
     ######################################################################## 100.0%
     ==> Pouring gmp-6.1.2_2.high_sierra.bottle.tar.gz
     🍺  /usr/local/Cellar/gmp/6.1.2_2: 18 files, 3.1MB
     ==> Installing php dependency: icu4c
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/icu4c-62.1.
     ######################################################################## 100.0%
     ==> Pouring icu4c-62.1.high_sierra.bottle.tar.gz
     ==> Caveats
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because macOS provides libicucore.dylib (but nothing else).
     
     If you need to have this software first in your PATH run:
       echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
       echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.bash_profile
     
     For compilers to find this software you may need to set:
         LDFLAGS:  -L/usr/local/opt/icu4c/lib
         CPPFLAGS: -I/usr/local/opt/icu4c/include
     
     ==> Summary
     🍺  /usr/local/Cellar/icu4c/62.1: 250 files, 67.3MB
     ==> Installing php dependency: libpq
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/libpq-10.4.
     ######################################################################## 100.0%
     ==> Pouring libpq-10.4.high_sierra.bottle.tar.gz
     ==> Caveats
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because conflicts with postgres formula.
     
     If you need to have this software first in your PATH run:
       echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile
     
     For compilers to find this software you may need to set:
         LDFLAGS:  -L/usr/local/opt/libpq/lib
         CPPFLAGS: -I/usr/local/opt/libpq/include
     
     ==> Summary
     🍺  /usr/local/Cellar/libpq/10.4: 2,430 files, 26.9MB
     ==> Installing php dependency: libsodium
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/libsodium-1
     ######################################################################## 100.0%
     ==> Pouring libsodium-1.0.16.high_sierra.bottle.tar.gz
     🍺  /usr/local/Cellar/libsodium/1.0.16: 71 files, 945.1KB
     ==> Installing php dependency: libzip
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/libzip-1.5.
     ######################################################################## 100.0%
     ==> Pouring libzip-1.5.1.high_sierra.bottle.tar.gz
     🍺  /usr/local/Cellar/libzip/1.5.1: 134 files, 577KB
     ==> Installing php dependency: unixodbc
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/unixodbc-2.
     ######################################################################## 100.0%
     ==> Pouring unixodbc-2.3.6.high_sierra.bottle.tar.gz
     🍺  /usr/local/Cellar/unixodbc/2.3.6: 46 files, 1.8MB
     ==> Installing php
     ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/php-7.2.8.h
     ######################################################################## 100.0%
     ==> Pouring php-7.2.8.high_sierra.bottle.tar.gz
     Error: The `brew link` step did not complete successfully
     The formula built, but is not symlinked into /usr/local
     Could not symlink sbin/php-fpm
     /usr/local/sbin is not writable.
     
     You can try again using:
       brew link php
     ==> /usr/local/Cellar/php/7.2.8/bin/pear config-set php_ini /usr/local/etc/php/7
     ==> /usr/local/Cellar/php/7.2.8/bin/pear config-set php_dir /usr/local/share/pea
     ==> /usr/local/Cellar/php/7.2.8/bin/pear config-set doc_dir /usr/local/share/pea
     ==> /usr/local/Cellar/php/7.2.8/bin/pear config-set ext_dir /usr/local/lib/php/p
     ==> /usr/local/Cellar/php/7.2.8/bin/pear config-set bin_dir /usr/local/opt/php/b
     ==> /usr/local/Cellar/php/7.2.8/bin/pear config-set data_dir /usr/local/share/pe
     ==> /usr/local/Cellar/php/7.2.8/bin/pear config-set cfg_dir /usr/local/share/pea
     ==> /usr/local/Cellar/php/7.2.8/bin/pear config-set www_dir /usr/local/share/pea
     ==> /usr/local/Cellar/php/7.2.8/bin/pear config-set man_dir /usr/local/share/man
     ==> /usr/local/Cellar/php/7.2.8/bin/pear config-set test_dir /usr/local/share/pe
     ==> /usr/local/Cellar/php/7.2.8/bin/pear config-set php_bin /usr/local/opt/php/b
     ==> /usr/local/Cellar/php/7.2.8/bin/pear update-channels
     ==> Caveats
     To enable PHP in Apache add the following to httpd.conf and restart Apache:
         LoadModule php7_module /usr/local/opt/php/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/
     
     To have launchd start php now and restart at login:
       brew services start php
     Or, if you don't want/need a background service you can just run:
       php-fpm
     ==> Summary
     🍺  /usr/local/Cellar/php/7.2.8: 515 files, 79.1MB
     ==> Caveats
     ==> apr
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because Apple's CLT package contains apr.
     
     If you need to have this software first in your PATH run:
       echo 'export PATH="/usr/local/opt/apr/bin:$PATH"' >> ~/.bash_profile
     
     ==> openssl
     A CA file has been bootstrapped using certificates from the SystemRoots
     keychain. To add additional certificates (e.g. the certificates added in
     the System keychain), place .pem files in
       /usr/local/etc/openssl/certs
     
     and run
       /usr/local/opt/openssl/bin/c_rehash
     
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
     
     If you need to have this software first in your PATH run:
       echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
     
     For compilers to find this software you may need to set:
         LDFLAGS:  -L/usr/local/opt/openssl/lib
         CPPFLAGS: -I/usr/local/opt/openssl/include
     
     ==> apr-util
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because Apple's CLT package contains apr.
     
     If you need to have this software first in your PATH run:
       echo 'export PATH="/usr/local/opt/apr-util/bin:$PATH"' >> ~/.bash_profile
     
     ==> aspell
     Installation of the 'is' (Icelandic) and 'nb' (Norwegian) dictionaries is
     currently broken. They can be installed manually.
     
     See: https://github.com/Homebrew/homebrew-core/issues/28074
     ==> autoconf
     Emacs Lisp files have been installed to:
       /usr/local/share/emacs/site-lisp/autoconf
     ==> libffi
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because some formulae require a newer version of libffi.
     
     For compilers to find this software you may need to set:
         LDFLAGS:  -L/usr/local/opt/libffi/lib
     
     ==> icu4c
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because macOS provides libicucore.dylib (but nothing else).
     
     If you need to have this software first in your PATH run:
       echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
       echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.bash_profile
     
     For compilers to find this software you may need to set:
         LDFLAGS:  -L/usr/local/opt/icu4c/lib
         CPPFLAGS: -I/usr/local/opt/icu4c/include
     
     ==> libpq
     This formula is keg-only, which means it was not symlinked into /usr/local,
     because conflicts with postgres formula.
     
     If you need to have this software first in your PATH run:
       echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile
     
     For compilers to find this software you may need to set:
         LDFLAGS:  -L/usr/local/opt/libpq/lib
         CPPFLAGS: -I/usr/local/opt/libpq/include
     
     ==> php
     To enable PHP in Apache add the following to httpd.conf and restart Apache:
         LoadModule php7_module /usr/local/opt/php/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/
     
     To have launchd start php now and restart at login:
       brew services start php
     Or, if you don't want/need a background service you can just run:
       php-fpm
    

看到一些 conflicts 和 it was not symlinked into …,我心虛了!
沒有啓動新安裝的 php!還想回頭使用自帶的 php 7.1!

** 重要的啓動提示信息如下

To have launchd start php now and restart at login:
  brew services start php
Or, if you don't want/need a background service you can just run:
  php-fpm
==> Summary
🍺  /usr/local/Cellar/php/7.2.8: 515 files, 79.1MB
  1. $ sudo vim /usr/local/etc/httpd/httpd.conf
    從舊的目錄下( /etc/apache2 )的 httpd.conf
    找到 php 模塊,cp 到新的 httpd.conf

    $ sudo apachectl restart
    httpd: Syntax error on line 187 of /usr/local/etc/httpd/httpd.conf: Cannot load libexec/apache2/libphp7.so into server: dlopen(/usr/local/opt/httpd/libexec/apache2/libphp7.so, 10): image not found

*** 找不到 libphp7.so 了!

  1. 重新設置 php 7.2
    以上保存的 php 安裝記錄中找到 php 設置部分

     ==> php
     To enable PHP in Apache add the following to httpd.conf and restart Apache:
         LoadModule php7_module /usr/local/opt/php/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/
     
     To have launchd start php now and restart at login:
       brew services start php
     Or, if you don't want/need a background service you can just run:
       php-fpm
    

按照提示修改新的 httpd.conf

$ sudo apachectl restart
http://127.0.0.1/info.php

在這裏插入圖片描述
終於 ok 了!

4、後續問題

1. 中文目錄亂碼
2. 系統 php 版本和 web 的 php 版本不一樣
3. brew link 失敗
4. php 驗證碼不顯示圖片
文章太長了,下一個再繼續!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章