본문 바로가기
노마드 노트

MeCab 형태소 셋팅 부터 PHP언어까지 해보기

by 이영훈 태천인(이영훈) 2021. 1. 14.
728x90

셋팅환경
AWS L1ightsail (Ubuntu 20.04 LTS) $3.5

램 : 512MB, CPU : 1 vCPU, SSD : 20GB, 트래픽 : 1TB

 

설치하기

 

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install php7.4-dev
  • sudo apt-get install gcc
  • sudo apt-get install g++
  • sudo apt-get install make
  • sudo apt-get install automake
  • sudo apt-get install apache2
  • sudo apt-get install libapache2-mod-php7.4

  • wget https://bitbucket.org/eunjeon/mecab-ko/downloads/mecab-0.996-ko-0.9.2.tar.gz
  • tar xvfz mecab-0.996-ko-0.9.2.tar.gz
  • cd mecab-0.996-ko-0.9.2
  • sudo ./configure
  • sudo make
  • sudo make check
  • sudo make install

  • sudo ldconfig
  • sudo ldconfig -p | grep /usr/local/lib
  • mecab --version
  • cd ..

  • wget https://bitbucket.org/eunjeon/mecab-ko-dic/downloads/mecab-ko-dic-2.0.1-20150920.tar.gz
  • tar xvzf mecab-ko-dic-2.0.1-20150920.tar.gz
  • cd mecab-ko-dic-2.0.1-20150920
  • sudo ./autogen.sh
  • sudo ./configure
  • sudo make
  • sudo make install

  • mecab -d /usr/local/lib/mecab/dic/mecab-ko-dic
    나는 당신을 사랑합니다.

  • cd ..

  • git clone https://github.com/rsky/php-mecab
  • cd php-mecab/
  • cd mecab
  • phpize
  • sudo ./configure
  • sudo make
  • sudo make test
  • sudo make install

PHP 테스트 소스 입니다.

PHPCli 설정

  • cd /etc/php/7.4/mods-available/
  • sudo touch mecab.ini
  • echo "extension=mecab.so" | sudo tee -a mecab.ini
  • sudo phpenmod -v 7.4 mecab
  • php -m   

 

 

웹에서 셋팅 하는 방법 

  • cd /etc/php/7.4/apache2/conf.d
  • sudo touch mecab.ini
  • echo "extension=mecab.so" | sudo tee -a mecab.ini
  • sudo service apache2 reload

웹에서 실행 결과

 

728x90

댓글0