2024年macbook 安装PHP7

1、查看php版本: php -v 5.5.29

2、使用homebrew安装php7

brew update #更新源

brew search php #查找源中的php,发现有php7.1版本,安装最新的php7.1

brew uninstall php@7.4

brew install php@8.1

3、install 成功后根据提示修改相应的文档

sudo chmod -R 777 /usr/local/var

brew services start php@8.1

brew services restart php@8.1

brew services stop php@8.1

4、macbook php降级

很多老项目都是跑在php7+的环境下的,但是brew已经不给安装了,会提示以下内容。

Error: php@7.4 has been disabled because it is a versioned formula
可以用tap添加个软件源码

1. 添加tap formulae

brew tap shivammathur/php

2. 安装

brew install shivammathur/php/php@7.4

brew install php@7.4
//临时切换版本
Brew link php@7.4
PHP -v

php -m 查看拓展信息

或者php-fpm

To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /usr/local/opt/php@8.1/lib/httpd/modules/libphp.so


    SetHandler application/x-httpd-php

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/8.1/

php@8.1 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@8.1 first in your PATH, run:
echo ‘export PATH="/usr/local/opt/php@8.1/bin:$PATH"’ >> ~/.profile
echo ‘export PATH="/usr/local/opt/php@8.1/sbin:$PATH"’ >> ~/.profile

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

To start php@8.1 now and restart at login:
brew services start php@8.1

Or, if you don’t want/need a background service you can just run:
/usr/local/opt/php@8.1/sbin/php-fpm –nodaemonize
————————————————

参考资料:https://blog.csdn.net/2301_79009223/article/details/133756700