Mac自带PHP-7.1.23升级到7.4.1

98 篇文章 2 订阅
57 篇文章 0 订阅

升级

请移驾最新,最省心的教程:

Mac上最简单的brew自主安装Apache+PHP教程 (A2.4.41 + P7.4.1)

https://blog.csdn.net/qq285744011/article/details/103729227

 

 

精简步骤

# 自动安装最新版的PHP
brew install php
brew link --overwrite php
sudo nano /etc/apache2/httpd.conf
# 删掉原来的 LoadModule php7_module libexec/apache2/libphp7.so
# 增加以下四行:
LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so
<FilesMatch \.php$>
  SetHandler application/x-httpd-php
</FilesMatch>
# 将“DirectoryIndex index.html”,改为:
DirectoryIndex index.php index.html

sudo apachectl restart

# 再修改php.ini
sudo nano /usr/local/etc/php/7.4/php.ini
# 按需求改动一下, 例如:
short_open_tag = Off   >>> On
upload_max_filesize = 2M   >>> 8M
# 启用extension=mbstring 等等
# 保存,重启电脑, ok!

 

详细步骤

Mac升级自带PHP-7.1.23到7.4.1


ME865:~ rudon$ whereis php 
/usr/bin/php

ME865:~ rudon$ php -v
PHP 7.1.23

ME865:~ rudon$ sudo cp -p /etc/php.ini /etc/bak71-php.ini
Password:

ME865:~ rudon$ brew unlink php71
Error: No such keg: /usr/local/Cellar/php@7.1
ME865:~ rudon$ brew unlink php7123
Error: No such keg: /usr/local/Cellar/php7123
ME865:~ rudon$ 

原来Mac自带的PHP不用unlink


ME865:~ rudon$ brew install php
==> Pouring php-7.4.1.mojave.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 bin/pear
Target /usr/local/bin/pear
already exists. You may want to remove it:
  rm '/usr/local/bin/pear'

To force the link and overwrite all conflicting files:
  brew link --overwrite php

To list all files that would be deleted:
  brew link --overwrite --dry-run php

Possible conflicting files are:
/usr/local/bin/pear
/usr/local/bin/peardev
/usr/local/bin/pecl
==> /usr/local/Cellar/php/7.4.1/bin/pear config-set php_ini /usr/local/etc/php/7.4/php.ini system
==> /usr/local/Cellar/php/7.4.1/bin/pear config-set php_dir /usr/local/share/pear system
==> /usr/local/Cellar/php/7.4.1/bin/pear config-set doc_dir /usr/local/share/pear/doc system
==> /usr/local/Cellar/php/7.4.1/bin/pear config-set ext_dir /usr/local/lib/php/pecl/20190902 system
==> /usr/local/Cellar/php/7.4.1/bin/pear config-set bin_dir /usr/local/opt/php/bin system
==> /usr/local/Cellar/php/7.4.1/bin/pear config-set data_dir /usr/local/share/pear/data system
==> /usr/local/Cellar/php/7.4.1/bin/pear config-set cfg_dir /usr/local/share/pear/cfg system
==> /usr/local/Cellar/php/7.4.1/bin/pear config-set www_dir /usr/local/share/pear/htdocs system
==> /usr/local/Cellar/php/7.4.1/bin/pear config-set man_dir /usr/local/share/man system
==> /usr/local/Cellar/php/7.4.1/bin/pear config-set test_dir /usr/local/share/pear/test system
==> /usr/local/Cellar/php/7.4.1/bin/pear config-set php_bin /usr/local/opt/php/bin/php system
==> /usr/local/Cellar/php/7.4.1/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.4/

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.4.1: 517 files, 75.9MB
==> Caveats
==> apr
apr is keg-only, which means it was not symlinked into /usr/local,
because Apple's CLT package contains apr.

If you need to have apr first in your PATH run:
  echo 'export PATH="/usr/local/opt/apr/bin:$PATH"' >> ~/.bash_profile

==> apr-util
apr-util is keg-only, which means it was not symlinked into /usr/local,
because Apple's CLT package contains apr.

If you need to have apr-util first in your PATH run:
  echo 'export PATH="/usr/local/opt/apr-util/bin:$PATH"' >> ~/.bash_profile

==> libidn
Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/libidn
==> openldap
openldap is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have openldap first in your PATH run:
  echo 'export PATH="/usr/local/opt/openldap/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/openldap/sbin:$PATH"' >> ~/.bash_profile

For compilers to find openldap you may need to set:
  export LDFLAGS="-L/usr/local/opt/openldap/lib"
  export CPPFLAGS="-I/usr/local/opt/openldap/include"

==> curl-openssl
curl-openssl is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have curl-openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/curl-openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find curl-openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/curl-openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/curl-openssl/include"

For pkg-config to find curl-openssl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/curl-openssl/lib/pkgconfig"

==> gettext
gettext is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.

If you need to have gettext first in your PATH run:
  echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile

For compilers to find gettext you may need to set:
  export LDFLAGS="-L/usr/local/opt/gettext/lib"
  export CPPFLAGS="-I/usr/local/opt/gettext/include"

==> libffi
libffi 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 libffi you may need to set:
  export LDFLAGS="-L/usr/local/opt/libffi/lib"

For pkg-config to find libffi you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"

==> glib
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> icu4c
icu4c 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 icu4c 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 icu4c you may need to set:
  export LDFLAGS="-L/usr/local/opt/icu4c/lib"
  export CPPFLAGS="-I/usr/local/opt/icu4c/include"

For pkg-config to find icu4c you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"

==> libpq
libpq is keg-only, which means it was not symlinked into /usr/local,
because conflicts with postgres formula.

If you need to have libpq first in your PATH run:
  echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile

For compilers to find libpq you may need to set:
  export LDFLAGS="-L/usr/local/opt/libpq/lib"
  export CPPFLAGS="-I/usr/local/opt/libpq/include"

For pkg-config to find libpq you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/libpq/lib/pkgconfig"

==> 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.4/

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


ME865:~ rudon$ brew link --overwrite php
Linking /usr/local/Cellar/php/7.4.1... 24 symlinks created

ME865:~ rudon$ sudo nano /etc/apache2/httpd.conf
删掉旧的php7_module那行,添加新的一行如下:
#LoadModule php7_module libexec/apache2/libphp7.so
LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so

增加:
    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

将:
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
改为:
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

保存,重启apache,启用php:
ME865:~ rudon$ sudo apachectl restart
Password:
ME865:~ rudon$ brew services start php
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 14 (delta 0), reused 7 (delta 0), pack-reused 0
Unpacking objects: 100% (14/14), done.
Tapped 1 command (43 files, 59.2KB).
==> Successfully started `php` (label: homebrew.mxcl.php)

ME865:~ rudon$ PHP -v
PHP 7.4.1 (cli) (built: Dec 18 2019 14:47:11) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.1, Copyright (c), by Zend Technologies
ME865:~ rudon$ 


最后,在phpinfo()中,可以看到:
PHP Version 7.4.1


修改/usr/local/etc/php/7.4/php.ini:
short_open_tag = Off   >>> On
error_reporting = E_ALL   >>> E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
upload_max_filesize = 2M   >>> 8M
启用extension=mbstring 等等
date.timezone = Asia/Shanghai


保存,重启电脑,OK!

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rudon滨海渔村

花的越多,赚得越多...

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值