Mac下使用homebrew安装php环境

本文详细介绍了在Mac操作系统中如何使用homebrew来安装和配置php环境,包括安装apache和nginx,添加php扩展库,配置apache和nginx,以及homebrew的相关操作,如替换国内源、切换不同版本的php、启动和停止服务等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 安装apache

brew install httpd

2. 安装nginx

brew install nginx

3. 添加php拓展库

brew tap homebrew/homebrew-php

4. 安装php

brew install homebrew/php/php56 --with-httpd --with-fpm

–with-httpd:编译libphp5.so给httpd
–with-fpm:nginx需要php-fpm

5. 配置apche

# httpd.conf 添加这三行
LoadModule php5_module        /usr/local/Cellar/php56/5.6.32_8/libexec/apache2/libphp5.so
AddType application/x-httpd-php .php
DirectoryIndex index.php index.htm index.html

6. 配置nginx

# nginx.conf 添加以下内容

server {
    listen       80;
    server_name  www.xxx.cn;

    root /Users/Icecream/Web/xxx;

    # 文件不存在则重定向到/index.php/xxx(/login.html => /index.php/login.html)
    if (!-f $request_filename) {
         rewrite ^(.*)$ /index.php$1 break;
    }  


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

    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(.*)$  {
        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;
    }
}

7. 其他

7.1. homebrew 替换国内源

参见: https://lug.ustc.edu.cn/wiki/mirrors/help/brew.git

当前php为php56,切换至php70

终端执行:

step 1. brew unlink php56

step 2. brew link php70

7.3. 查看homebrew安装的程序

homebrew list

7.4. 查看homebrew安装的服务

brew services list

7.5. 启动homebrew安装的服务

brew services start|stop|restart xxx

例如:
brew start nginx

brew stop nginx

brew restart nginx

P.s. nginx如使用80端口,则需管理员权限,使用sudo运行命令
sudo brew start nginx

7.6. homebrew卸载程序

brew uninstall xxx
例如:
brew uninstall nginx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值