MacOS M1使用Homebrew搭建PHP运行环境

      相关文章:MacOS M1安装Homebrew

      安装环境:Nginx1.21、PHP7.4、MySQL5.7

1、安装Nginx

#安装
brew install nginx

#开启
sudo nginx

#停止
sudo nginx -s stop

#重启
sudo nginx -s reopen 

#检查配置文件是否正确
sudo nginx -t

#指定配置文件
sudo nginx -c /opt/homebrew/etc/nginx/nginx.conf

#重新加载配置
sudo nginx -s reload

      启动Nginx后,浏览器访问 http://localhost:8080/ 如下,则Nginx安装成功:

       Nginx的默认配置文件在 /opt/homebrew/etc/nginx/nginx.conf,把默认端口改为80,如下:

#user  nobody;
worker_processes auto;
error_log  /opt/homebrew/var/log/nginx/error.log crit;

#pid        logs/nginx.pid;

events {
    use epoll;
    multi_accept on;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    access_log  /opt/homebrew/var/log/nginx/access.log  main;

    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.php index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            # nginx配置pathifo
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
    }
    include /opt/homebrew/etc/nginx/servers/*.conf;
}

      可以在 /opt/homebrew/etc/nginx/servers/ 目录下配置站点信息,修改配置文件后需要执行 nginx -s reload 命令重载配置文件,并执行 vi /etc/hosts 配置域名映射。

      另外如果需要关停MacOS自带的Apache服务,可执行以下命令:

sudo apachectl -k stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

2、安装PHP

#安装
brew install php@7.4
brew link php@7.4

#设置环境变量
echo 'export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/php@7.4/lib"
export CPPFLAGS="-I/opt/homebrew/opt/php@7.4/include"

#刷新
source ~/.zshrc

#查看php版本
php -v

#启动
brew services start php@7.4

#关闭
brew services stop php@7.4

#安装php版本切换工具
brew install brew-php-switcher

#切换版本
brew-php-switcher php@7.2

      安装相关扩展软件:

#安装Composer
brew install composer

#安装redis
brew install zstd
pecl install redis
redis-server -v

#安装mongodb
ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h 
pecl install mongodb

3、安装MySQL

#安装
brew install mysql@5.7

#配置环境变量
echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"'>> ~/.zshrc

#更新环境变量
source ~/.zshrc

#启动
brew services start mysql

#查看mysql版本
mysql --version

#连接测试
mysql -u root -p

#开启安全机制
/opt/homebrew/etc/mysql/bin/mysql_secure_installation


#配置文件位置
/opt/homebrew/etc/my.cnf

#停止
brew services stop mysql

#重启
brew services restart mysql

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李维山

帮到你就行 不差钱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值