Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

macos 安装多版本PHP,composer

 Share


Recommended Posts

PHP版本切换网上有写博客用 brew-php-switcher 切换实际没生效,博客也是相互抄,看了袭浪费时间。讲一下我的思路,因为php 可以cli 和fpm 的方式。安装php 将不同版本添加命令到bin 实现cli模式可以调用不同版本;fpm通过修改配置文件,绑定不同端口,就可以同时运行不同版本的fpm,使用nginx 时配置文件写不用的fpm的端口号就可以使用不同版本的fpm了。用 homebrew 安装后软件目录也不同。Linux、windows也可以用类似方式实现。记录一下博客,方便后续有需要的人看,节约时间。

别跟我说docker!夏天macbook 开docker 热得一匹!

brew install php@7.4
## 等待brew 更新安装,太慢的,可以参考别人的博客换homebrew 的源
cd /usr/local/bin/
## php74 是我定义的命令文件名,其他版本自行定义名字。不过下文安装对应版本composer时要使用对应的命令名
ln -s  /usr/local/opt/php@7.4/bin/php php74
php74 -v
PHP 7.4.21 (cli) (built: Jul 12 2021 11:57:26) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies
## 到此php7.4 安装成功了, 然后我们修改7.4 fpm 的配置文件
vim /usr/local/etc/php/7.4/php-fpm.d/www.con
## 找到 listen = 127.0.0.1:9000 这一行,将端口改为 listen = 127.0.0.1:9001,wq 保存退出
## 启动php7.4 
brew services start php@7.4
## 然后查看端口, 发现9001 端口已经被php-fpm占用,配置 nginx时,可根据需要配置fpm的端口。
lsof -nP -iTCP -sTCP:LISTEN
php-fpm   20184 xxx    8u  IPv4 0x44b5422db725d7a3      0t0  TCP 127.0.0.1:9001 (LISTEN)
php-fpm   20187 xxx    9u  IPv4 0x44b5422db725d7a3      0t0  TCP 127.0.0.1:9001 (LISTEN)
php-fpm   20188 xxx    9u  IPv4 0x44b5422db725d7a3      0t0  TCP 127.0.0.1:9001 (LISTEN)

## 现在安装composer 
cd ~
php74 -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php74 -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php74 composer-setup.php
php74 -r "unlink('composer-setup.php');"

sudo mv composer.phar /usr/local/bin/composer74
## 运行composer74,出现composer字样表明安装成功!
    composer74
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/

重复以上步骤,指定不同版本如:brew install php@8.0,就可以安装其他版本的PHP 和 composer!
composer 改源的命令搜其他博客吧。

Link to post
Link to comment
Share on other sites

 Share

discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...