Mac安装多版本PHP和扩展

昨天 22:01 字数 2969 阅读 3301 已编辑

Nginx 和 Mysql 安装比较简单 直接brew install 即可。

Nginx

brew install nginx

MySQL

brew install mysql

PHP

安装低版本PHP,比如5.6 需要 tap一下

brew tap shivammathur/php

然后安装想要的版本即可

PHP5.6

brew install shivammathur/php/php@5.6

PHP7.4

brew install shivammathur/php/php@7.4

PHP8.1

brew install shivammathur/php/php@8.1

PHP扩展

主要记录一下低版本的PHP(7.2以前)的安装过程,新的可以直接使用pecl安装,方便快捷。

xdebug

curl -O https://pecl.php.net/get/xdebug-2.5.0.tgz

tar -xzf xdebug-2.5.0.tgz

cd xdebug-2.5.0

/opt/homebrew/opt/php@5.6/bin/phpize

./configure --with-php-config=/opt/homebrew/opt/php@5.6/bin/php-config  --enable-xdebug

make && make install

vim /opt/homebrew/etc/php/8.1/php.ini

zend_extension=/opt/homebrew/Cellar/php@8.1/8.1.13/pecl/20210902/xdebug.so

reids

同上
...

memcache

curl -O https://pecl.php.net/get/memcache-2.2.7.tgz

tar -xvf memcache-2.2.7.tgz

cd memcache-2.2.7

arch -arm64 /opt/homebrew/opt/php@5.6/bin/phpize

arch -arm64 ./configure --with-php-config=/opt/homebrew/opt/php@5.6/bin/php-config --with-zlib-dir=/opt/homebrew/Cellar/zlib/1.2.13

make && make install 

mcrypt

brew install libmcrypt

/opt/homebrew/opt/php@5.6/bin/phpize

./configure --with-php-config=/opt/homebrew/opt/php@5.6/bin/php-config --with-mcrypt=/opt/homebrew/opt/libmcrypt

make && make install

imap

/opt/homebrew/opt/php@5.6/bin/phpize

./configure --with-php-config=/opt/homebrew/opt/php@5.6/bin/php-config --with-imap=/opt/homebrew/opt/imap-uw --with-kerberos --with-imap-ssl=/opt/homebrew/opt/openssl

make && make install

配置版本PHP

PHP修改fpm的监听端口

vim /opt/homebrew/etc/php/5.6/php-fpm.conf

# 找到
listen = 127.0.0.1:9000
# 修改成
listen = 127.0.0.1:9056
vim /opt/homebrew/etc/php/7.4/php-fpm.d/www.conf

# 找到
listen = 127.0.0.1:9000
# 修改成
listen = 127.0.0.1:9074
vim /opt/homebrew/etc/php/8.1/php-fpm.d/www.conf

# 找到
listen = 127.0.0.1:9000
# 修改成
listen = 127.0.0.1:9081

重启PHP-FPM

brew services restart php@5.6
brew services restart php@7.4
brew services restart php@8.1

配置NGINX vhost

server{
    listen 80; 
    server_name test-lc.com;
    index index.html index.htm index.php;
    root /opt/homebrew/var/www/test;

    location / {
        try_files $uri $uri/ /index.php?r=$query_string;
    }

    location ~ \.php$
    {   
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.1:9074;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SERVER_NAME $host;
    }   

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|ttf|otf|woff)$ {
        expires    24h;
        access_log off;
    }

    location ~* \.(eot|ttf|woff|svg|otf)$ {
         add_header Access-Control-Allow-Origin *;
    }

    location ~ /\. {
        deny all;
    }

    access_log off;
}

主要是修改 fastcgi_pass 127.0.1:9074;,通过监听不同的端口,实现多版本共存。

5.6的项目

fastcgi_pass 127.0.1:9056;

7.4的项目

fastcgi_pass 127.0.1:9074;

8.1的项目

fastcgi_pass 127.0.1:9081;

然后重启NGINX即可

brew services restart nginx
0人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论
站长 @ 十七度
文章
384
粉丝
23
喜欢
195
收藏
31
排名 : 1
访问 : 147.28万
私信