IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> PHP知识库 -> MacOS M1使用Homebrew搭建PHP运行环境 -> 正文阅读

[PHP知识库]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
pecl install redis
redis-server -v

#安装mongodb
ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php@7.4/7.4.16/include/php/ext/pcre/pcre2.h
pech install mongodb

3、安装MySQL

#安装
brew install mysql@5.7

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

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

#查看mysql版本
mysql --version

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

#连接测试
mysql -u root -p

#配置文件位置
/usr/local/etc/my.cnf

#启动
brew services start mysql

#停止
brew services stop mysql

#重启
brew services restart mysql

  PHP知识库 最新文章
Laravel 下实现 Google 2fa 验证
UUCTF WP
DASCTF10月 web
XAMPP任意命令执行提升权限漏洞(CVE-2020-
[GYCTF2020]Easyphp
iwebsec靶场 代码执行关卡通关笔记
多个线程同步执行,多个线程依次执行,多个
php 没事记录下常用方法 (TP5.1)
php之jwt
2021-09-18
上一篇文章      下一篇文章      查看所有文章
加:2021-07-27 15:59:34  更:2021-07-27 15:59:59 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/3 9:40:34-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码