brew update灾难来了!

我以前用brew 安装了多个php的版本,早上执行了brew update后php就用不了了

# openssl版本不对了
➔ /usr/local/opt/php@5.6/bin/php -v
dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
  Referenced from: /usr/local/opt/php@5.6/bin/php
  Reason: image not found
[1]    16051 abort      /usr/local/opt/php@5.6/bin/php -v
# 把我的xdebug.so删掉了
➔ /usr/local/opt/php@7.2/bin/php -v
Failed loading /usr/local/opt/php@7.2/lib/php/20170718/xdebug.so:  dlopen(/usr/local/opt/php@7.2/lib/php/20170718/xdebug.so, 9): image not found
PHP 7.2.32 (cli) (built: Jul 10 2020 00:06:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.32, Copyright (c) 1999-2018, by Zend Technologies
# 又不知道缺了啥
➔ /usr/local/opt/php@7.4/bin/php -v
dyld: Library not loaded: /usr/local/opt/libffi/lib/libffi.6.dylib
  Referenced from: /usr/local/opt/php@7.4/bin/php
  Reason: image not found
[1]    16126 abort      /usr/local/opt/php@7.4/bin/php -v

我真的是太难了!!!

php5.6解决办法

其实可能我的电脑里已经有openssl@1.0,只是软链接指向变了,你也可以先直接修改软链接试试。

# 安装openssl@1.0
brew install rbenv/tap/openssl@1.0

# 修改symlink
ln -sf /usr/local/opt/openssl@1.0 /usr/local/opt/openssl

继续尝试:

➔ /usr/local/opt/php@5.6/bin/php -v
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
  Referenced from: /usr/local/opt/php@5.6/bin/php
  Reason: image not found
[1]    52151 abort      /usr/local/opt/php@5.6/bin/php -v

看看是否icu4c的老版本在不在吧:

➔ ll /usr/local/opt/icu4c
lrwxr-xr-x  1 jake  admin    20B Jul 22 11:36 /usr/local/opt/icu4c -> ../Cellar/icu4c/67.1

ll /usr/local/Cellar/icu4c/
total 0
drwxr-xr-x  12 jake  staff   384B Jun 28  2019 64.2
drwxr-xr-x  12 jake  staff   384B Jul 22 11:36 67.1

可能是64.2,试试:

ln -sf /usr/local/Cellar/icu4c/64.2 /usr/local/opt/icu4c

这一次php5.6就复活了!

➔ /usr/local/opt/php@5.6/bin/php -v                                                     
PHP 5.6.40 (cli) (built: Apr 23 2019 11:14:34) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

php7.2那还能怎么办,选择原谅她啦

去这里:https://xdebug.org/wizard 把phpinfo的信息粘进去,重新build一个吧。

但是其实更严重的问题来了,php7.2依赖/usr/local/Cellar/icu4c/67.1,而php5.6依赖/usr/local/Cellar/icu4c/64.2,(php7.4却可以正常,神奇!)那只好把/usr/local/Cellar/icu4c/67.1的内容复制到/usr/local/Cellar/icu4c/64.2去吧:

# 复制以下两种文件似乎就可以了
➔ cp /usr/local/Cellar/icu4c/67.1/lib/*.67.1.dylib /usr/local/Cellar/icu4c/64.2/lib/
➔ cp /usr/local/Cellar/icu4c/67.1/lib/*.67.dylib /usr/local/Cellar/icu4c/64.2/lib/

➔ /usr/local/opt/php@7.2/bin/php -v
Failed loading /usr/local/opt/php@7.2/lib/php/20170718/xdebug.so:  dlopen(/usr/local/opt/php@7.2/lib/php/20170718/xdebug.so, 9): image not found
PHP 7.2.32 (cli) (built: Jul 10 2020 00:06:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.32, Copyright (c) 1999-2018, by Zend Technologies

可以了,稍后去把xdebug.so build出来。

php7.4如法炮制

➔ rm /usr/local/opt/libffi
➔ ln -s /usr/local/Cellar/libffi/3.2.1 /usr/local/opt/libffi

➔ /usr/local/opt/php@7.4/bin/php -v
PHP 7.4.4 (cli) (built: Mar 19 2020 20:12:27) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.4, Copyright (c), by Zend Technologies
    with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans

git只add修改的和删除的文件

有时候我本地会写些tests测试用例文件,但是这些文件并不需要被提交,但是它们却有混杂在其他被修改的文件中,那该怎么办呢?

  1. 好的做法是修改.gitignore把这些文件排除开来
  2. 也可以通过git add -u app/ 这样,app目录下除了新增的文件没有被add,其他修改的和删除的都add进去了

另外如果你把一个不想提交的文件add了,可以使用git reset HEAD filename取消add。

Mac带窗口阴影截图

macbook有两个截图快捷键,一个是command+shift+3,用来截整个屏幕图,还有一个command+shift+4自由截图,自由截图时,可以按以下空格键变成窗口截图,窗口截图出来的图片就带有阴影了,默认截图都保存在桌面上(如果你只想截图到粘贴板中,而不是在桌面生成文件,可以尝试:control+cmd+shift+4)。
示例:

cmd+shift+5 区域截图,即默认出来一个区域,自己去调节。

截屏2020-07-17 上午10.58.26

service container的一个好处

service container最明显的一个特点是,它产生实例不需要显性的new一个类,因此甚至也不需要传入构造函数的参数(如果参数也是可以通过容器生成),看一个类的定义:

class FooHandler
{
  public __construct(Bar $bar = null)
  {
    // ...
    $bar->doSomething();
  }
}

如果你直接通过new FooHandler($bar),生成你需要的对象时,必须先得到Bar的实例$bar,这在有时候是没必要的,在Laravel中,可以直接通过:

$fooHandler = app()->make(FooHandler::class);

得到,唯一不足的一点是$fooHandler不能被IDE智能识别。

Apache2静态文件报“Access denied”小记

apache2提示“Access denied”,状态码404,第一反应是apache2的用户www-data对文件没有权限,但是奇怪的是,对于接口访问(php)确是OK的,所有的资源文件都访问不了,查了以下,是有读权限的,查了站点下的error.log:

[Thu Apr 09 14:33:55.072565 2020] [proxy_fcgi:error] [pid 23:tid 140714637768448] [client 172.18.0.1:49334] AH01071: Got error 'Access to the script '/var/www/xxx/public/logo.png' has been denied (see security.limit_extensions)\n'

注意关键点:proxy_fcgi:error`,我想,访问资源文件跟fcgi有什么关系呢?那我是不是有可能把所有的请求都转发给php了呢?

继续检查apache配置文件,终于发现:

    <FilesMatch .*$>
        SetHandler "proxy:fcgi://php72:9000"
    </FilesMatch>

有问题!

果然所有的请求都会转发到php去了!遂按照示例配置改成如下:

    <FilesMatch \.(cgi|shtml|phtml|php)$>
        SetHandler "proxy:fcgi://php72:9000"
    </FilesMatch>

重启 apache:docker-compose restart apache2,问题解决!