Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

[PhantomJS] Ubuntu 16.04에서 QXcbConnection: Could not connect to display 오류 해결

2017-05-30 by 편리

우분투 16.04 LTS 서버에서 PhantomJS를 아래 명령어로 설치하고 실행 때 오류가 발생할 수 있다.

# apt install phantomjs

오류 메시지는 아래와 같다.

QXcbConnection: Could not connect to display
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
Aborted (core dumped)

위와 같은 오류가 발생하면 xvfb 패키지를 설치하고 아래와 같이 PhantomJS를 실행하면 된다.

# xvfb-run phantomjs -v

위 명령을 매번 입력하는 게 귀찮다면 Alias 를 이용해 처리한다.

# nano /etc/profile.d/aliases.sh

aliases.sh 파일의 내용은 아래와 같다.

#!/bin/bash
alias phantomjs="xvfb-run phantomjs"

파일을 저장한 후 아래 명령어를 통해 갱신해준다.

# source /etc/profile

 

아래의 코드로 PHP 에서 phantomjs 명령어를 실행할 경우 위의 내용을 적용했음에도 제대로 실행이 되지 않는 경우가 있음을 알았다.

<?php
exec('phantomjs /home/user/html/hello.js', $output, $e);

print_r($output);

PHP에서는 아래와 같은 코드로 phantomjs 명령을 실행하면 된다.

<?php
exec('xvfb-run /usr/bin/phantomjs /home/user/html/hello.js', $output, $e);

print_r($output);

 

PHP cli 모드에서 위 스크립트를 실행해보면 xvfb-run: error: Xvfb failed to start 라는 오류가 화면에 표시되는 걸 확인할 수 있다. 이 때는 아래와 같이 -a 옵션을 추가해준다.

<?php
exec('xvfb-run -a /usr/bin/phantomjs /home/user/html/hello.js', $output, $e);

print_r($output);

Post navigation

Previous Post:

[Python] rake-nltk 모듈을 이용한 키워드 추출

Next Post:

[PhantomJS] 팬텀JS evaluate 에서 ajax 실행

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • SK 세븐모바일 유심 셀프교체
  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes