MacOS M1 MAX安装PHP7、Swoole和编译安装memcache扩展

一,修改homebrew源为中科大源
查看当前源
 $ git -C "$(brew --repo)" remote -v
 $ git -C "$(brew --repo homebrew/core)" remote -v
 $ git -C "$(brew --repo homebrew/cask)" remote -v
设置中科大源
#替换Homebrew
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git

#替换Homebrew Core
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

#替换Homebrew Cask
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

#更新
$ brew update

修改bottles
#对于 bash 用户:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

#对于 zsh 用户:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc
二,M1 MAX安装PHP7.4
#先查看PHP版本
$ brew search php
==> Formulae
brew-php-switcher   php-cs-fixer        php@7.3             phpbrew             phpmyadmin          pcp
php                 php-cs-fixer@2      php@7.4 ✔           phplint             phpstan             pup
php-code-sniffer    php@7.2             php@8.0             phpmd               phpunit

==> Casks
eclipse-php                   phpstorm                      phpwebstudy                   pop
安装php@7.4
#安装
$ arch -arm64 brew install php@7.4

#启动/重启
$ brew services start/restart php@7.4

#安装完成
==> php@7.4
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /opt/homebrew/opt/php@7.4/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:
    /opt/homebrew/etc/php/7.4/

php@7.4 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@7.4 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc

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


To restart php@7.4 after an upgrade:
  brew services restart php@7.4
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/php@7.4/sbin/php-fpm --nodaemonize
查看已安装扩展
➜  ~ php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
intl
json
ldap
libxml
mbstring
memcache
mysqli
mysqlnd
odbc
openssl
pcntl
pcre
PDO
pdo_dblib
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite
pgsql
Phar
phpdbg_webhelper
posix
pspell
readline
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
sqlite3
standard
swoole
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache
三,M1 MAX使用pecl安装swoole
使用arch -arm64命令安装
$ arch -arm64 pecl install swoole-4.4.5
解决报错

/opt/homebrew/Cellar/php@7.4/7.4.30/include/php/ext/pcre/php_pcre.h:25:10: fatal error: ‘pcre2.h’ file not found

$ ln -s /opt/homebrew/include/pcre2.h /opt/homebrew/Cellar/php@7.4/7.4.30/include/php/ext/pcre/pc
re2.h

#然后再次执行
$ arch -arm64 pecl install swoole-4.4.5

#安装成功后
$ brew services restart php@7.4
$ php -m

#查看swoole扩展信息
$ php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.4.5
Built => Jul 18 2022 19:04:27
coroutine => enabled
kqueue => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 3.0.5 5 Jul 2022
http2 => enabled
pcre => enabled
zlib => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 262144 => 262144
四,M1 MAX编译安装memcache扩展
安装zlib
$ arch -arm64 brew install zlib

#zlib安装后位置
/usr/local/opt/zlib
memcache-4.0.5.2.tgz
$ wget http://pecl.php.net/get/memcache-4.0.5.2.tgz

#解压后
cd memcache-4.0.5.2

#要注意arch -arm64命令
arch -arm64 phpize
arch -arm64 ./configure --with-php-config=/opt/homebrew/opt/php@7.4/bin/php-config --enable-memcache-session=yes --with-zlib-dir=/usr/local/opt/zlib
arch -arm64 make
arch -arm64 make install
修改php.ini
$ vim /opt/homebrew/etc/php/7.4/php.ini

#添加
extension="memcache.so"
重启PHP
brew services restart php@7.4
查看memcache扩展
➜  ~ php --ri memcache

memcache

memcache support => enabled
Version => 4.0.5.2
Revision => $Revision$

Directive => Local Value => Master Value
memcache.allow_failover => 1 => 1
memcache.max_failover_attempts => 20 => 20
memcache.default_port => 11211 => 11211
memcache.chunk_size => 32768 => 32768
memcache.protocol => ascii => ascii
memcache.hash_strategy => consistent => consistent
memcache.hash_function => crc32 => crc32
memcache.redundancy => 1 => 1
memcache.session_redundancy => 2 => 2
memcache.compress_threshold => 20000 => 20000
memcache.lock_timeout => 15 => 15
memcache.session_prefix_host_key => 0 => 0
memcache.session_prefix_host_key_remove_www => 1 => 1
memcache.session_prefix_host_key_remove_subdomain => 0 => 0
memcache.session_prefix_static_key => no value => no value
memcache.session_save_path => no value => no value
memcache.prefix_host_key => 0 => 0
memcache.prefix_host_key_remove_www => 1 => 1
memcache.prefix_host_key_remove_subdomain => 0 => 0
memcache.prefix_static_key => no value => no value
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值