mac m2芯片 安装nginx + php + mysql

1.安装homebrew:

系统本身就有(命令brew -v查看下),如果没有安装一下

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

2.安装nginx

brew install nginx

3.安装php

brew tap shivammathur/php
brew search php
brew install shivammathur/php/php@7.4

如果安装多个php版本,就修改下PHP端口配置:

我的路径是:/opt/homebrew/etc/php/7.4/php-fpm.d/www.conf

listen = 127.0.0.1:9000
改为
listen = 127.0.0.1:9074

4.修改nginx配置

sudo vim /opt/homebrew/etc/nginx/nginx.conf

#user  nobody;
worker_processes  1;
 
error_log  /var/logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    #gzip  on;
 
    include servers/*;
}

5.在 /opt/homebrew/etc/nginx下新建文件夹servers,在servers下新建新建test1.conf和test2.conf

mkdir servers
cd servers    
vim test1.conf

test1.conf配置内容

server {
    listen       80;
    server_name www.test1.cn;
    # 配置项目路径
    root  /Users/liuxiaoyun/www/test1; 
 
    #access_log  logs/host.access.log  main;
 
    location / {
        index  index.html index.htm index.php;
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
    }
 
    #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;
    }
 
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
    	# 9074上面设置的监听端口,加载php7.4
        fastcgi_pass   127.0.0.1:9074;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

test2.conf的配置

server {
    listen       80;
    server_name www.test2.cn;
    # 配置项目路径
    root  /Users/liuxiaoyun/www/test2; 
 
    #access_log  logs/host.access.log  main;
 
    location / {
        index  index.html index.htm index.php;
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
    }
 
    #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;
    }
 
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
    	# 9074上面设置的监听端口,加载php7.4
        fastcgi_pass   127.0.0.1:9074;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

6.检查配置

nginx -t
如果报文件权限问题:sudo chmod -R 777 /var/logs

7.设置php-fpm开机自启

sudo cp /opt/homebrew/opt/php@7.4/homebrew.php@7.4.service /Library/LaunchAgents

8.启动php-fpm

brew services start php@7.4

9.验证是否启动成功

lsof -i :9074

10.终端切换php版本

解除之前版本链接:brew unlink php
增加新版本链接:
brew link --overwrite php@7.4

11.php加入环境变量

echo 'export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc

12.安装composer(切换到哪个版本的php,就在当前环境下执行如下命令,就可以在对应的PHP版本下安装composer,从官网获取到的最新哈希值(官网Composer)

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer74

13.验证composer

composer74 -v

14.mysql加入环境变量

 echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc


For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/mysql@5.7/include"

15.启动数据库

 brew services start mysql@5.7

16.brew安装mysql5.7总是出问题,我的解决办法是,更新homebrew,安装的mysql8.0

17.php项目运行:

(1).nginx执行重新加载:nginx -s reload ;报错:

[error] invalid PID number "" in "/opt/homebrew/var/run/nginx.pid"

解决:

重新加载配置文件 nginx.conf,然后再执行 reload:

nginx -c /opt/homebrew/etc/nginx/nginx.conf
nginx -s reload 

(2). 修改hosts文件,/etc/hosts。添加自定义本地域名

#上边配置的test1.conf和test2.conf文件里自定义的域名
127.0.0.1。www.test1.cn
127.0.0.1。www.test2.cn

(3).在~/www/test1里添加index.php。访问域名www.test1.cn就完成啦

补充:多个PHP版本切换步骤:

Step 1: 查看已安装的 PHP 版本

首先,确认你已经安装了所需的 PHP 版本。

brew list | grep php

你应该会看到类似 php@7.2php@7.4 的输出。

Step 2: 停止当前运行的 PHP 版本

如果你正在使用 PHP-FPM,需要停止当前正在运行的 PHP 版本服务。

brew services stop php@7.4

Step 3: 切换到目标 PHP 版本

要切换到 PHP 7.2,先使用 brew unlink 命令解除当前版本的链接,然后使用 brew link 命令链接目标版本。

brew unlink php@7.4
brew link php@7.2

Step 4: 更新终端配置文件

有时,你需要更新终端的配置文件(如 .zshrc.bash_profile),确保 PATH 环境变量指向正确的 PHP 版本。

在你的终端配置文件中添加以下行(这里重点:一定要把php@7.4的配置删除):

export PATH="/usr/local/opt/php@7.2/bin:$PATH"
export PATH="/usr/local/opt/php@7.2/sbin:$PATH"


重新加载:
source ~/.zshrc

Step 5: 重启 PHP 服务(如果适用)

如果你使用 PHP-FPM 或其他服务,需要重新启动服务:

brew services start php@7.2

  • 9
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在 CentOS 7 上安装 Zabbix 6.0、NginxMySQL 8、PHP 7.4 的步骤: 1. 安装 EPEL 和 Remi 源: ``` yum install -y epel-release rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-7.rpm ``` 2. 安装 Nginx: ``` yum install -y nginx systemctl start nginx systemctl enable nginx ``` 3. 安装 PHP 7.4: ``` yum install -y php74-php-fpm php74-php-mysqlnd php74-php-xmlrpc php74-php-gd php74-php-intl php74-php-mbstring php74-php-soap php74-php-xml php74-php-json php74-php-zip systemctl start php74-php-fpm systemctl enable php74-php-fpm ``` 4. 安装 MySQL 8: ``` rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm yum install -y mysql-community-server systemctl start mysqld systemctl enable mysqld ``` 5. 配置 MySQL: ``` mysql_secure_installation ``` 6. 创建 Zabbix 数据库: ``` mysql -u root -p CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin; CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost'; FLUSH PRIVILEGES; EXIT; ``` 7. 导入 Zabbix 数据库: ``` cd /usr/share/doc/zabbix-server-mysql-6.0.0/ zcat create.sql.gz | mysql -u zabbix -p zabbix ``` 8. 安装 Zabbix Server 和 Agent: ``` yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent ``` 9. 配置 Zabbix: ``` vi /etc/zabbix/zabbix_server.conf DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=password ``` 10. 启动 Zabbix Server 和 Agent: ``` systemctl start zabbix-server zabbix-agent systemctl enable zabbix-server zabbix-agent ``` 11. 配置 Nginx: ``` vi /etc/nginx/conf.d/zabbix.conf server { listen 80; server_name localhost; root /usr/share/zabbix; location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_pass unix:/run/php74-php-fpm/zabbix.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ``` 12. 重启 Nginx: ``` systemctl restart nginx ``` 13. 打开浏览器,输入服务器 IP 地址,进入 Zabbix Web 界面,按照提示进行 Zabbix 配置即可。 注意:以上步骤仅供参考,具体操作根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值