Mac安装PHP(Homebrew/php弃用、其余第三方tap也已经弃用或者迁移后的安装配置方案)

1、前言

看网上不少资料,大多数都是php

mac安装php,只须要:html

brew tap homebrew/php

brew install phpXX

安装php扩展只须要:nginx

brew install phpXX-phpExtension

可是执行上面两条命令的时候都会抛出error:git

homebrew/dupes was deprecated. This tap is now empty as all its formulae were migrated.

homebrew/php was deprecated. This tap is now empty as all its formulae were migrated.

Homebrew/php已经弃用了,其余第三方tap也已经弃用或者迁移了,参考:

github

https://github.com/Homebrew/homebrew-phpredis

如今执行一下浏览器

brew search php

出现的是:php7

再也不是以往的一大片各类版本的php以及扩展任君选择了,而扩展方面,以往咱们是这样安装扩展的:php-fpm

brew install php71-redis

如今已经搜不出来:测试


 

2、安装

那么如今怎么安装php及扩展呢,上述github连接已经说的很明白,有兴趣的能够本身去看,我这里简单说一下。

下面举例安装php7.1

首先

brew tap Homebrew/homebrew-core

由于其余第三方tab已经迁移/弃用了,所有合并到这里

如今仍然能够经过

brew install php71

来安装php7.1,可是其实你会看到php71已经改名为php@7.1:

安装过程截图:

安装成功截图:

启动 php-fpm

brew services start php@7.1  

设置开机启动:

cp /usr/local/Cellar/php\@7.1/7.1.29/homebrew.mxcl.php\@7.1.plist  ~/Library/LaunchAgents/

launchctl load -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php\@7.1.plist

 

设置 Nginx 的 PHP-FPM 配置

打开 nginx 默认注释掉的php location设置,修改以下(具体配置参数,例如路径,这里以我本地安装为准):

location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/var/www$fastcgi_script_name;
            include        /usr/local/etc/nginx/fastcgi_params;
        }

测试nginx配置是否正确:

StevendeMacBook-Pro:nginx steven$ nginx -t
nginx: [alert] could not open error log file: open() "/usr/local/var/log/nginx/error.log" failed (13: Permission denied)
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
2019/05/21 16:35:46 [emerg] 96011#0: open() "/usr/local/var/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed

由于我同时打开了日志,根据提示,说明日志文件夹没有权限

sudo chmod -R 777  /usr/local/var/log/nginx/


给他权限

 

再试试:

StevendeMacBook-Pro:log steven$ sudo nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/usr/local/Cellar/nginx/1.15.12/logs/access.log" failed (2: No such file or directory)
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed

哦,这里没有/usr/local/Cellar/nginx/1.15.12/logs   logs文件夹,去建立一个就OK,并赋予权限

mkdir  /usr/local/Cellar/nginx/1.15.12/logs

chmod -R 777 logs/

 

 

再试试:

StevendeMacBook-Pro:1.15.12 steven$ sudo nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

成功了,重载nginx配置

sudo nginx -s reload

由于个人nginx解析的根目录是

/usr/local/var/www

因此,去这个目录下建立一个phpinfo.php文件,写入代码

<?php
    echo phpinfo();

?>

浏览器访问 http://localhost:8080/phpinfo.php


 

 

 附:

说一下要用到的几个位置

php-fpm在/usr/local/Cellar/php@7.1/7.1.22/sbin/php-fpm

php和fpm的相关配置在/usr/local/etc/php/7.1

 

安装php扩展:

直接pecl install phpExtension(如:pecl install redis)

扩展放置的位置开发者已经设置好,在/usr/local/lib/php/pecl/20160303

相关文章
相关标签/搜索