memo.xight.org

日々のメモ

Debian Stretch に PHP5.6 と PHP7.0 を共存させる

Summary

Debian StretchのオフィシャルリポジトリにはPHP5.6が含まれていない。
packages.sury.org のPHP5.6のパッケージを利用して、PHP5.6, PHP7.0 の環境を共存させたい。

sury.orgのgpgキーを追加

$ sudo apt-get install apt-transport-https
$ curl https://packages.sury.org/php/apt.gpg | sudo apt-key add -

- /etc/apt/sources.list.d/deb.sury.org.list
[src]
deb https://packages.sury.org/php/ stretch main


php5.6, php7.0のインストール

$ sudo apt-get update
$ sudo apt-get install php5.6-cli php5.6-fpm php7.0-cli php7.0-fpm


/etc/nginx/site-available/site-with-php7.0

server {
	listen 8870 default_server;
	listen [::]:8870 default_server;
	server_name _;
	root /var/www/site-with-php7.0;
	index index.php;
	location / {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock; # adjust for the listen setting discussed above
	}
}

/etc/nginx/site-available/site-with-php5.6

server {
	listen 8856 default_server;
	listen [::]:8856 default_server;
	server_name _;
	root /var/www/site-with-php5.6;
	index index.php;
	location / {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php5.6-fpm.sock; # adjust for the listen setting discussed above
	}
}

シンボリックリンクの作成, nginxの再起動

$ ln -s ../sites-available/site-with-php5.6 /etc/nginx/sites-enabled
$ ln -s ../sites-available/site-with-php7.0 /etc/nginx/sites-enabled
$ systemctl reload nginx.service


via

pehapkari.cz - 2017-03-27 - Multiple PHP versions, the easy way
https://pehapkari.cz/blog/2017/03/27/multiple-php-versions-the-easy-way/

/dev/log がなくなった場合の対応

Summary

/dev/log が見つからないエラーが発生…。

logger: socket /dev/log: No such file or directory

/run/systemd/journal/dev-log から /dev/log にシンボリックリンクを作成

sudo ln -s /run/systemd/journal/dev-log /dev/log


Reference

askubuntu - 2016-11-18 - Ubuntu Lost /dev/log symlink?
https://askubuntu.com/questions/850848/ubuntu-lost-dev-log-symlink

Mechanize でパースできないHTMLを強引に処理する

Summary

Mechanizeは、HTML (Content-Type: text/html) をパースする際にMechanize::Pageを利用する。
しかし、パースするHTMLがwell-formedではない場合、パースに失敗する。

Mechanize::Page で処理

require 'mechanize'

agent = Mechanize.new
agent.pluggable_parser['text/html'] = PlainFile
page = agent.get("http://example.com/")
p page


#<Mechanize::Page
 {url #<URI::HTTP http://ill-formed.com/>}
 {meta_refresh}
 {title "ill-formed.com"}
 {iframes}
 {frames}
 {links}
 {forms}>

Plain Textで処理

require 'mechanize'

class PlainFile < Mechanize::File; end

agent = Mechanize.new
agent.pluggable_parser['text/html'] = PlainFile
page = agent.get("http://example.com/")
p page


#<PlainFile:0x00007fb8d2077910
 @body=
  "<!doctype html>\n" +
  "<html>\n" +
  "<head>\n" +
  "    <title>ill-formed.com</title>\n" +
  "\n" +
  "    <meta charset=\"utf-8\" />\n" +
  "    <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n" +
  "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n" +
  "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"main.css\" />\n" +
  "</head>\n" +
  "\n" +
  "<body>\n" +
  "<div>\n" +
  "    <h1>ill-formed.com</h1>\n" +
  "\t<p>This domain is established to be used for ill-formed HTML test. <!-- </p> -->\n" +
  "<!-- </div> -->\n" +
  "<!-- </body> -->\n" +
  "<!-- </html> -->\n",
 @code="200",
 @filename="index.html",
 @full_path=false,
 @response=
  {"server"=>"GitHub.com",
   "date"=>"Thu, 05 Oct 2017 14:55:52 GMT",
   "content-type"=>"text/html; charset=utf-8",
   "transfer-encoding"=>"chunked",
   "last-modified"=>"Thu, 05 Oct 2017 14:55:35 GMT",
   "access-control-allow-origin"=>"*",
   "expires"=>"Thu, 05 Oct 2017 15:05:52 GMT",
   "cache-control"=>"max-age=600",
   "content-encoding"=>"gzip",
   "x-github-request-id"=>"F5F8:1F5B:54E8B4B:7C0A75B:59D647F8"},
 @uri=#<URI::HTTP http://ill-formed.com/>>