月度归档:2019年04月

PHP MongoDB各版本库和扩展版本对应关系

PHP DriverMongoDB 4.0MongoDB 3.6MongoDB 3.4MongoDB 3.2MongoDB 3.0MongoDB 2.6
PHPLIB 1.4 + mongodb-1.5 
PHPLIB 1.3 + mongodb-1.4 
PHPLIB 1.2 + mongodb-1.3  
PHPLIB 1.1 + mongodb-1.2  
PHPLIB 1.0 + mongodb-1.1   
mongodb-1.0    

laravel实现跨域的中间件

# 创建中间件
php artisan make:middleware EnableCrossRequestMiddleware
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class EnableCrossRequestMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param Request $request
     * @param Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $origin = $request->header('Origin');
        if ($origin) {
            $exps = [
                '/.*\.xxx\.com$/', # 匹配下自己的域名
                '/.*localhost.*/',
                '/.*127.0.0.1.*/',
                '/.*10.*/',
            ];
            foreach ($exps as $exp) {
                $matchCount = preg_match($exp, $origin, $matches);
                if ($matchCount && isset($matches[0])) {
                    if ($request->isMethod('OPTIONS')) {
                        $response = response('');
                        $response->withHeaders([
                            'Access-Control-Allow-Credentials' => 'true',
                            'Access-Control-Allow-Origin' => $origin,
                            'Access-Control-Allow-Methods' => 'GET, POST',
                            'Access-Control-Allow-Headers' => 'Content-Type, Token',
                            'Access-Control-Max-Age' => 3600 * 24,
                        ]);
                        return $response;
                    }
                    $response = $next($request);
                    $response->withHeaders([
                        'Access-Control-Allow-Credentials' => 'true',
                        'Access-Control-Allow-Origin' => $origin,
                    ]);
                    return $response;
                }
            }
        }
        return $next($request);
    }
}

另外需要关闭csrf保护否则会413

docker初探小记


# 启动个nginx
docker run --detach --publish 80:80 --name webserver nginx
# 停止nginx
docker container stop webserver
# 删除容器
docker container rm webserver

–detach等于-d 后后台运行的意思

可参考链接:
http://www.runoob.com/docker/docker-command-manual.html

CentOS 7安装docker:

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io

MySQL 8.0快速配置远程连接

— 创建用户并设置密码(默认密码有复杂度要求,这里使用新的验证方式 caching_sha2_password )

CREATE USER 'root'@'%' IDENTIFIED WITH caching_sha2_password BY 'Aa#111111111';

— 授予root权限

GRANT ALL ON *.* TO 'root'@'%';
UPDATE `mysql`.`user` SET `Grant_priv` = 'y' WHERE (`Host` = '%') and (`User` = 'root');

然后重启下MySQL就好了