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        [email protected]             phpbrew             phpmyadmin          pcp
php                 php-cs-fixer@2      [email protected] ✔           phplint             phpstan             pup
php-code-sniffer    [email protected]             [email protected]             phpmd               phpunit

==> Casks
eclipse-php                   phpstorm                      phpwebstudy                   pop
安装[email protected]
#安装
$ arch -arm64 brew install [email protected]

#启动/重启
$ brew services start/restart [email protected]

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

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

For compilers to find [email protected] you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"


To restart [email protected] after an upgrade:
  brew services restart [email protected]
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/[email protected]/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/[email protected]/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/[email protected]/7.4.30/include/php/ext/pcre/pc
re2.h

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

#安装成功后
$ brew services restart [email protected]
$ php -m

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

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
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/[email protected]/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 [email protected]
查看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

你可能感兴趣的:(PHP,macos,swoole,memcached,m1,max)