// input
var date = 20200602
var period = 7;

//temp 미리 만들어놨음 - 나중에 ttl index
var temp_cnt = db.temp.count();
var array = new Array();

for(var i=0; i<period; i++){
var stage = db.test_logs.aggregate([
	{$match: {rday:20200602+i}},
    {$lookup:{
    	from: "temp",
        localField: "userid",
        foreignField: "userid",
        as: "test"
    }}
]);

var stage_cnt = stage._batch.length
array.push(stage_cnt/temp_cnt*100);
}
print(array)
static function lookUpByStage($date, $i){

        return LoginLog::on('mongodbGomLogs')->raw(function($collection) use ($date, $i){
           return $collection->aggregate([
               ['$match'=>['rday'=> $date+$i]],
               ['$lookup'=>[
                    'from'=>'temp',
                    'localField'=>'userid',
                    'foreignField'=>'userid',
                    'as'=>'test'
                ]],
               ['$count'=>'userid']
           ]);
        });

    }

 

1. yum -y install gcc php-pear php-devel

2. pecl install mongo ---> 이렇게 해서 설치했는데 실제로 모듈은 확인 안되고, 새로 설치하면 이미 설치 됐다는 에러만 떴다.. -> pecl install -f mongo 로 바꿔서 됨

3. php.ini 에다가 extension=mongodb.so 추가

**mongo.so: 구버전/ mongodb.so: 신버전

**몽고 잘 깔렸는지 확인 -> php -m 모듈에서 확인 가능 -> phpinfo 에도 잘 떠야한다

추가 4. PHP MongoDB "No suitable servers found" ERROR

selinux 보안과 관련된 문제인거 같다

setsebool -P httpd_can_network_connect on

 

yum -y install gcc php-pear php-deveyum -y install gcc php-pear php-deveㅛㅕㅡ yum -y install gcc php-pear php-develyum -y install gcc php-pear php-devel

0. 새로 ec2 인스터스를 팠으면 yum -y update 해주자

1. Install EPEL Repository

To install the latest PHP 7.3.3 on CentOS 7.6, you need to first install EPEL repositories.

yum install epel-release

 

2. Install Remi Repository

Remi is a third party repository that provides the latest versions of PHP.

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

 

3. Disable Remi PHP 5.4 repository

yum install -y yum-utils

yum-config-manager --disable remi-php54

 

4. Enable Remi PHP 7.3 repository

yum-config-manager --enable remi-php73

 

5.

Installing PHP 7.3.3 on CentOS 7.6

yum install php

 

6. php-fpm 설치

yum install php-fpm php-common

7. 설정파일

/etc/php-fpm.d/www.conf 파일

########### file /etc/php-fpm.d/www.conf user = nginx group = nginx ;listen은 nginx 설정과 맞춰줘야 한다. ;listen = 127.0.0.1:9000 listen = /var/run/php-fpm/php-fpm.sock; listen.owner = nginx listen.group = nginx

출처: https://forteleaf.tistory.com/entry/nginx-php71-phpfpm-설치하기 [부들잎의 이것저것]

 

nginx + php71 + php-fpm 설치하기

version 정보 nginx : 1.14.0 php : 7.1.18 yum install nginx 를 통해서 설치하였으며, # yum install nginx [root@centos html]# nginx -v nginx version: nginx/1.14.0 php71 은 remi repo를 추가해서 아래와..

forteleaf.tistory.com

/etc/nginx/conf.d/default.conf 파일 : 여기 있는 루트 파일에서 html 불러온다

출처: https://forteleaf.tistory.com/entry/nginx-php71-phpfpm-설치하기 [부들잎의 이것저것]

server { listen 80; server_name your_server_ip; # note that these lines are originally from the "location /" block # root 설정이 없으면 404 에러가 날수 있다. root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; #fastcgi_pass 는 아래 두개 중 아무거나 사용해도 좋으나 php-fpm.d/www.conf 설정과 맞춰줘야 한다. #fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; #/scripts 이름으로 인해서 오류가 생길 수 있다. #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }

출처: https://forteleaf.tistory.com/entry/nginx-php71-phpfpm-설치하기 [부들잎의 이것저것]

8. 테스트하려면 

service nginx restart

service php-fpm restart

하고 나서 해당 ip 주소(기본 80포트)로 들어가서 지정해줬던 루트의 index.html이 보이는지 확인

<HTML의 data 속성>

가장 먼저 떠오른 data 속성.

배열을 따로 전달해 주는거 같진 않아서 json 형식의 string으로 전달 후, 자바스크립트에서 decode 해서 사용하기로 함.

JSON.parse($$$) : json to js object

JSON.stringify : json to string

<문제상황>

["Mar 1","Mar 2","Mar 3","Mar 4","Mar 5","Mar 6","Mar 7","Mar 8","Mar 9","Mar 10","Mar 11","Mar 12","Mar 13"]

이렇게 보여야 하는 배열이 json.parse를 하자 uncaught jsonUnexpected end of JSON input 에러가 나옴.

<해결책>

json 키나 밸류에는 공백을 넣어줘서는 안된다

'웹개발 > PHP' 카테고리의 다른 글

mongo retention 계산($lookup) - js/php  (0) 2020.06.10
centos에 php-mongodb driver 설치  (0) 2020.05.27
CentOS 7.8에서 php7.3 +nginx+php-fpm 설치  (0) 2020.05.26

+ Recent posts