現役プログラマのWordPressカスタマイズ相談

WordPress(ワードプレス)のお悩み、うまくいかなくてお困りなこと、不具合調査、新規制作依頼まで、ウェブアプリケーションエンジニアがあなたをサポートします。

PhantomJSをインストールする(Amazon Linux)

f:id:jsaz:20171126183112p:plain
[Amazon Linux]PhantomJSインストール手順

Amazon LinuxにPhantomJSをインストールしました。

Amazon Linux AMIのyumリポジトリからPhantomJSをインストールすることはできなかったのでバイナリディストリビューションからインストールします。

こちらを利用します。 bitbucket.org

ubuntuへのインストールはこちらをご覧ください。 soudan.hatenablog.jp

参考にしたサイト

www.codeammo.com

フォント関連パッケージのインストール

$ sudo yum install fontconfig freetype freetype-devel fontconfig-devel libstdc++
読み込んだプラグイン:priorities, update-motd, upgrade-helper
amzn-main/latest                                                                | 2.1 kB     00:00     
amzn-updates/latest                                                             | 2.5 kB     00:00     
パッケージ fontconfig-2.8.0-5.8.amzn1.x86_64 はインストール済みか最新バージョンです
パッケージ freetype-2.3.11-15.14.amzn1.x86_64 はインストール済みか最新バージョンです
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ fontconfig-devel.x86_64 0:2.8.0-5.8.amzn1 を インストール
---> パッケージ freetype-devel.x86_64 0:2.3.11-15.14.amzn1 を インストール
--> 依存性の処理をしています: zlib-devel のパッケージ: freetype-devel-2.3.11-15.14.amzn1.x86_64
---> パッケージ libstdc++48.x86_64 0:4.8.3-9.111.amzn1 を 更新
---> パッケージ libstdc++48.x86_64 0:4.8.5-11.135.amzn1 を アップデート
--> トランザクションの確認を実行しています。
---> パッケージ zlib-devel.x86_64 0:1.2.8-7.18.amzn1 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

=======================================================================================================
 Package                    アーキテクチャー バージョン                      リポジトリー         容量
=======================================================================================================
インストール中:
 fontconfig-devel           x86_64           2.8.0-5.8.amzn1                 amzn-main           210 k
 freetype-devel             x86_64           2.3.11-15.14.amzn1              amzn-main           411 k
更新します:
 libstdc++48                x86_64           4.8.5-11.135.amzn1              amzn-main           403 k
依存性関連でのインストールをします:
 zlib-devel                 x86_64           1.2.8-7.18.amzn1                amzn-main            53 k

トランザクションの要約
=======================================================================================================
インストール  2 パッケージ (+1 個の依存関係のパッケージ)
更新          1 パッケージ

総ダウンロード容量: 1.1 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): fontconfig-devel-2.8.0-5.8.amzn1.x86_64.rpm                              | 210 kB     00:00     
(2/4): freetype-devel-2.3.11-15.14.amzn1.x86_64.rpm                             | 411 kB     00:00     
(3/4): libstdc++48-4.8.5-11.135.amzn1.x86_64.rpm                                | 403 kB     00:00     
(4/4): zlib-devel-1.2.8-7.18.amzn1.x86_64.rpm                                   |  53 kB     00:00     
-------------------------------------------------------------------------------------------------------
合計                                                                   6.0 MB/s | 1.1 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : zlib-devel-1.2.8-7.18.amzn1.x86_64                                     1/5 
  インストール中          : freetype-devel-2.3.11-15.14.amzn1.x86_64                               2/5 
  インストール中          : fontconfig-devel-2.8.0-5.8.amzn1.x86_64                                3/5 
  更新します              : libstdc++48-4.8.5-11.135.amzn1.x86_64                                  4/5 
  整理中                  : libstdc++48-4.8.3-9.111.amzn1.x86_64                                   5/5 
  検証中                  : zlib-devel-1.2.8-7.18.amzn1.x86_64                                     1/5 
  検証中                  : fontconfig-devel-2.8.0-5.8.amzn1.x86_64                                2/5 
  検証中                  : libstdc++48-4.8.5-11.135.amzn1.x86_64                                  3/5 
  検証中                  : freetype-devel-2.3.11-15.14.amzn1.x86_64                               4/5 
  検証中                  : libstdc++48-4.8.3-9.111.amzn1.x86_64                                   5/5 

インストール:
  fontconfig-devel.x86_64 0:2.8.0-5.8.amzn1         freetype-devel.x86_64 0:2.3.11-15.14.amzn1        

依存性関連をインストールしました:
  zlib-devel.x86_64 0:1.2.8-7.18.amzn1                                                                 

更新:
  libstdc++48.x86_64 0:4.8.5-11.135.amzn1                                                              

完了しました!

PhantomJSバイナリデータをbitbucketからwgetでダウンロードする

$ wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
--2017-11-23 14:48:03--  https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
bitbucket.org (bitbucket.org) をDNSに問いあわせています... 104.192.143.3, 104.192.143.1, 104.192.143.2, ...
bitbucket.org (bitbucket.org)|104.192.143.3|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 302 Found
場所: https://bbuseruploads.s3.amazonaws.com/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2?Signature=QZebR8GmMV2YfuyeyKN77gnwCeA%3D&Expires=1510811882&AWSAccessKeyId=AKIAIQWXW6WLXMB5QZAQ&versionId=null&response-content-disposition=attachment%3B%20filename%3D%22phantomjs-1.9.8-linux-x86_64.tar.bz2%22 [続く]
--2017-11-23 14:48:04--  https://bbuseruploads.s3.amazonaws.com/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2?Signature=QZebR8GmMV2YfuyeyKN77gnwCeA%3D&Expires=1510811882&AWSAccessKeyId=AKIAIQWXW6WLXMB5QZAQ&versionId=null&response-content-disposition=attachment%3B%20filename%3D%22phantomjs-1.9.8-linux-x86_64.tar.bz2%22
bbuseruploads.s3.amazonaws.com (bbuseruploads.s3.amazonaws.com) をDNSに問いあわせています... 54.231.41.67
bbuseruploads.s3.amazonaws.com (bbuseruploads.s3.amazonaws.com)|54.231.41.67|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 13163325 (13M) [application/x-tar]
`phantomjs-1.9.8-linux-x86_64.tar.bz2' に保存中

phantomjs-1.9.8-linux-x86 100%[====================================>]  12.55M  1.10MB/s    in 16s     

2017-11-23 14:48:20 (804 KB/s) - `phantomjs-1.9.8-linux-x86_64.tar.bz2' へ保存完了 [13163325/13163325]

phantomjsフォルダを作成

$ sudo mkdir -p /opt/phantomjs

bz2ファイルを展開する

$ bzip2 -d phantomjs-1.9.8-linux-x86_64.tar.bz2
$ ls
phantomjs-1.9.8-linux-x86_64.tar

tarファイルを展開する

$ sudo tar -xvf phantomjs-1.9.8-linux-x86_64.tar --directory /opt/phantomjs/ --strip-components 1
phantomjs-1.9.8-linux-x86_64/bin/
phantomjs-1.9.8-linux-x86_64/bin/phantomjs
phantomjs-1.9.8-linux-x86_64/examples/
phantomjs-1.9.8-linux-x86_64/examples/scandir.js
phantomjs-1.9.8-linux-x86_64/examples/technews.coffee
phantomjs-1.9.8-linux-x86_64/examples/tweets.js
phantomjs-1.9.8-linux-x86_64/examples/rasterize.coffee
phantomjs-1.9.8-linux-x86_64/examples/pagecallback.js
phantomjs-1.9.8-linux-x86_64/examples/printheaderfooter.js
phantomjs-1.9.8-linux-x86_64/examples/follow.js
phantomjs-1.9.8-linux-x86_64/examples/run-jasmine.coffee
phantomjs-1.9.8-linux-x86_64/examples/module.js
phantomjs-1.9.8-linux-x86_64/examples/waitfor.coffee
phantomjs-1.9.8-linux-x86_64/examples/stdin-stdout-stderr.coffee
phantomjs-1.9.8-linux-x86_64/examples/pizza.js
phantomjs-1.9.8-linux-x86_64/examples/seasonfood.coffee
phantomjs-1.9.8-linux-x86_64/examples/unrandomize.js
phantomjs-1.9.8-linux-x86_64/examples/modernizr.js
phantomjs-1.9.8-linux-x86_64/examples/waitfor.js
phantomjs-1.9.8-linux-x86_64/examples/direction.js
phantomjs-1.9.8-linux-x86_64/examples/arguments.coffee
phantomjs-1.9.8-linux-x86_64/examples/render_multi_url.js
phantomjs-1.9.8-linux-x86_64/examples/run-qunit.js
phantomjs-1.9.8-linux-x86_64/examples/printheaderfooter.coffee
phantomjs-1.9.8-linux-x86_64/examples/ipgeocode.js
phantomjs-1.9.8-linux-x86_64/examples/ipgeocode.coffee
phantomjs-1.9.8-linux-x86_64/examples/version.js
phantomjs-1.9.8-linux-x86_64/examples/movies.js
phantomjs-1.9.8-linux-x86_64/examples/child_process-examples.js
phantomjs-1.9.8-linux-x86_64/examples/loadurlwithoutcss.coffee
phantomjs-1.9.8-linux-x86_64/examples/version.coffee
phantomjs-1.9.8-linux-x86_64/examples/seasonfood.js
phantomjs-1.9.8-linux-x86_64/examples/server.js
phantomjs-1.9.8-linux-x86_64/examples/countdown.js
phantomjs-1.9.8-linux-x86_64/examples/rasterize.js
phantomjs-1.9.8-linux-x86_64/examples/injectme.js
phantomjs-1.9.8-linux-x86_64/examples/run-jasmine.js
phantomjs-1.9.8-linux-x86_64/examples/post.js
phantomjs-1.9.8-linux-x86_64/examples/imagebin.coffee
phantomjs-1.9.8-linux-x86_64/examples/pizza.coffee
phantomjs-1.9.8-linux-x86_64/examples/hello.coffee
phantomjs-1.9.8-linux-x86_64/examples/features.js
phantomjs-1.9.8-linux-x86_64/examples/movies.coffee
phantomjs-1.9.8-linux-x86_64/examples/tweets.coffee
phantomjs-1.9.8-linux-x86_64/examples/injectme.coffee
phantomjs-1.9.8-linux-x86_64/examples/features.coffee
phantomjs-1.9.8-linux-x86_64/examples/colorwheel.coffee
phantomjs-1.9.8-linux-x86_64/examples/walk_through_frames.js
phantomjs-1.9.8-linux-x86_64/examples/printmargins.coffee
phantomjs-1.9.8-linux-x86_64/examples/printmargins.js
phantomjs-1.9.8-linux-x86_64/examples/scandir.coffee
phantomjs-1.9.8-linux-x86_64/examples/loadspeed.coffee
phantomjs-1.9.8-linux-x86_64/examples/printenv.js
phantomjs-1.9.8-linux-x86_64/examples/serverkeepalive.coffee
phantomjs-1.9.8-linux-x86_64/examples/fibo.coffee
phantomjs-1.9.8-linux-x86_64/examples/echoToFile.coffee
phantomjs-1.9.8-linux-x86_64/examples/netlog.js
phantomjs-1.9.8-linux-x86_64/examples/useragent.coffee
phantomjs-1.9.8-linux-x86_64/examples/child_process-examples.coffee
phantomjs-1.9.8-linux-x86_64/examples/weather.coffee
phantomjs-1.9.8-linux-x86_64/examples/direction.coffee
phantomjs-1.9.8-linux-x86_64/examples/module.coffee
phantomjs-1.9.8-linux-x86_64/examples/printenv.coffee
phantomjs-1.9.8-linux-x86_64/examples/simpleserver.js
phantomjs-1.9.8-linux-x86_64/examples/fibo.js
phantomjs-1.9.8-linux-x86_64/examples/imagebin.js
phantomjs-1.9.8-linux-x86_64/examples/colorwheel.js
phantomjs-1.9.8-linux-x86_64/examples/technews.js
phantomjs-1.9.8-linux-x86_64/examples/hello.js
phantomjs-1.9.8-linux-x86_64/examples/echoToFile.js
phantomjs-1.9.8-linux-x86_64/examples/postserver.coffee
phantomjs-1.9.8-linux-x86_64/examples/page_events.coffee
phantomjs-1.9.8-linux-x86_64/examples/postserver.js
phantomjs-1.9.8-linux-x86_64/examples/weather.js
phantomjs-1.9.8-linux-x86_64/examples/countdown.coffee
phantomjs-1.9.8-linux-x86_64/examples/netsniff.coffee
phantomjs-1.9.8-linux-x86_64/examples/detectsniff.js
phantomjs-1.9.8-linux-x86_64/examples/render_multi_url.coffee
phantomjs-1.9.8-linux-x86_64/examples/useragent.js
phantomjs-1.9.8-linux-x86_64/examples/walk_through_frames.coffee
phantomjs-1.9.8-linux-x86_64/examples/post.coffee
phantomjs-1.9.8-linux-x86_64/examples/arguments.js
phantomjs-1.9.8-linux-x86_64/examples/simpleserver.coffee
phantomjs-1.9.8-linux-x86_64/examples/run-qunit.coffee
phantomjs-1.9.8-linux-x86_64/examples/outputEncoding.coffee
phantomjs-1.9.8-linux-x86_64/examples/phantomwebintro.js
phantomjs-1.9.8-linux-x86_64/examples/follow.coffee
phantomjs-1.9.8-linux-x86_64/examples/loadspeed.js
phantomjs-1.9.8-linux-x86_64/examples/page_events.js
phantomjs-1.9.8-linux-x86_64/examples/loadurlwithoutcss.js
phantomjs-1.9.8-linux-x86_64/examples/sleepsort.js
phantomjs-1.9.8-linux-x86_64/examples/sleepsort.coffee
phantomjs-1.9.8-linux-x86_64/examples/netlog.coffee
phantomjs-1.9.8-linux-x86_64/examples/outputEncoding.js
phantomjs-1.9.8-linux-x86_64/examples/serverkeepalive.js
phantomjs-1.9.8-linux-x86_64/examples/phantomwebintro.coffee
phantomjs-1.9.8-linux-x86_64/examples/server.coffee
phantomjs-1.9.8-linux-x86_64/examples/universe.js
phantomjs-1.9.8-linux-x86_64/examples/pagecallback.coffee
phantomjs-1.9.8-linux-x86_64/examples/stdin-stdout-stderr.js
phantomjs-1.9.8-linux-x86_64/examples/detectsniff.coffee
phantomjs-1.9.8-linux-x86_64/examples/unrandomize.coffee
phantomjs-1.9.8-linux-x86_64/examples/netsniff.js
phantomjs-1.9.8-linux-x86_64/ChangeLog
phantomjs-1.9.8-linux-x86_64/README.md
phantomjs-1.9.8-linux-x86_64/LICENSE.BSD
phantomjs-1.9.8-linux-x86_64/third-party.txt
$ ls
phantomjs-1.9.8-linux-x86_64.tar

シンボリックリンクを作成する

$ sudo ln -s /opt/phantomjs/bin/phantomjs /usr/bin/phantomjs

インストール確認

$ phantomjs /opt/phantomjs/examples/hello.js
Hello, world!
  • PhantomJSが正常にインストールされました。

日本語フォントインストール

PhantomJS実行時に日本語部分が文字化け(すべて日本語が四角で表示される/豆腐というらしい)を解決するために日本語フォントをインストールする必要があります。

  • 明朝フォント
$ sudo yum install ipa-mincho-fonts.noarch
読み込んだプラグイン:priorities, update-motd, upgrade-helper
amzn-main/latest                                                                | 2.1 kB     00:00     
amzn-updates/latest                                                             | 2.5 kB     00:00     
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ ipa-mincho-fonts.noarch 0:003.02-3.1.2.amzn1 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

=======================================================================================================
 Package                    アーキテクチャー バージョン                      リポジトリー         容量
=======================================================================================================
インストール中:
 ipa-mincho-fonts           noarch           003.02-3.1.2.amzn1              amzn-main           5.5 M

トランザクションの要約
=======================================================================================================
インストール  1 パッケージ

総ダウンロード容量: 5.5 M
インストール容量: 7.7 M
Is this ok [y/d/N]: y
Downloading packages:
ipa-mincho-fonts-003.02-3.1.2.amzn1.noarch.rpm                                  | 5.5 MB     00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : ipa-mincho-fonts-003.02-3.1.2.amzn1.noarch                             1/1 
  検証中                  : ipa-mincho-fonts-003.02-3.1.2.amzn1.noarch                             1/1 

インストール:
  ipa-mincho-fonts.noarch 0:003.02-3.1.2.amzn1                                                         

完了しました!
  • ゴシックフォント
$ sudo yum install ipa-gothic-fonts.noarch
読み込んだプラグイン:priorities, update-motd, upgrade-helper
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ ipa-gothic-fonts.noarch 0:003.02-4.2.2.amzn1 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

=========================================================================================
 Package                 アーキテクチャー
                                       バージョン                 リポジトリー      容量
=========================================================================================
インストール中:
 ipa-gothic-fonts        noarch        003.02-4.2.2.amzn1         amzn-main        4.1 M

トランザクションの要約
=========================================================================================
インストール  1 パッケージ

総ダウンロード容量: 4.1 M
インストール容量: 6.0 M
Is this ok [y/d/N]: y
Downloading packages:
ipa-gothic-fonts-003.02-4.2.2.amzn1.noarch.rpm                    | 4.1 MB     00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : ipa-gothic-fonts-003.02-4.2.2.amzn1.noarch               1/1 
  検証中                  : ipa-gothic-fonts-003.02-4.2.2.amzn1.noarch               1/1 

インストール:
  ipa-gothic-fonts.noarch 0:003.02[f:id:jsaz:20171126183112p:plain]-4.2.2.amzn1                                           

完了しました!

不要なダウンロードファイルを削除

$ rm phantomjs-1.9.8-linux-x86_64.tar.bz2 

手順通りにインストールすることができました。
CentOSyumで入れることができるっぽいですがAMIはこの手順でないとPhantomJSをインストールすることができないようです。