<?xml version="1.0" encoding="UTF-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="ja">
<title>シングスブログ</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/" />
<modified>2012-04-11T09:01:02Z</modified>
<tagline>ビジネス向けウェブサイト構築運営、ウェブサービス・アプリの企画開発</tagline>
<id>tag:blog.thingslabo.com,2012://1</id>
<generator url="http://www.movabletype.org/" version="5.13-ja">Movable Type</generator>
<copyright>Copyright (c) 2012, thingsym</copyright>

<entry>
<title>「#!/usr/bin/perl --」はFTP転送モードの問題? 実はFTPサーバ設定の問題</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000273.html" />
<modified>2012-04-11T09:01:02Z</modified>
<issued>2012-04-11T08:52:17Z</issued>
<id>tag:blog.thingslabo.com,2012://1.273</id>
<created>2012-04-11T08:52:17Z</created>
<summary type="text/plain">Perl のパス 「#!/usr/bin/perl -w」では正常に動くのに、「...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>Perl のパス 「#!/usr/bin/perl -w」では正常に動くのに、「#!/usr/bin/perl」では「Internal Server Error」に。</p>

<p>cgiスクリプトの記述や設定が正しくなかったり、サーバ内部でエラーが発生した場合に返されるのが「Internal Server Error (HTTPステータスコード500)」。エラーがあるのは分かるが、原因がわからない、Webエンジニアにとって頭を悩ます「Internal Server Error」。</p>

<p>その原因も様々。原因が明らかにできなければ対策も解決もできない。Perl パスの問題かと思いきや、FTPの転送モードの問題?、実はFTP サーバ設定の問題というちょっと複雑。そんな問題に直面した備忘メモ。</p>

<h2>現象</h2>

<ol>
	<li>FTP を使ってアスキーモードでファイルをアップロード</li>
	<li>Perl のパス 「#!/usr/bin/perl」 では cgi が 「Internal Server Error (HTTPステータスコード500)」に</li>
	<li>Perl のパス 「#!/usr/bin/perl -w」 または 「#!/usr/bin/perl --」 では正常に動作する
<br>
<ul>
	<li><a href="http://oshiete.goo.ne.jp/qa/767872.html" target="_blank" rel="nofollow">#!/usr/bin/perl --</a></li>
	<li><a href="http://sagittarius.dip.jp/toshi/premature.php" target="_blank" rel="nofollow">Premature end of script headersの解決法-超簡易版</a></li>
	<li><a href="http://okwave.jp/qa/q3715712.html" target="_blank" rel="nofollow">「#!/usr/bin/perl --」でなければ動作しないのはなぜ？</a></li>
</ul>
</li>
	<li>改行コードが問題と思ってファイルの改行コードを「LF」に変換</li>
	<li>再度、FTP を使ってアスキーモードでファイルをアップロードしても同じ現象に</li>
	<li>「あれれ」無限ループにはまる。</li>
</ol>

<h3>さらに突き詰めると、</h3>

<p>シェル上でスクリプトを走らせると、</p>

<pre class="prettyprint">
/usr/bin/perl^M: bad interpreter: No such file or directory
</pre>

<p>とエラーに</p>

<ul>
	<li><a href="http://blog.cgi-bin.jp/article/245382329.html" target="_blank" rel="nofollow">/usr/bin/perl^M: bad interprete</a></li>
</ul>


<h3>さらに突き詰めると、</h3>

<p>FTP サーバに <a href="https://security.appspot.com/vsftpd.html" target="_blank" rel="nofollow">vsftpd</a> を使っている</p>

<h2>原因</h2>

<p>FTP サーバ vsftpd では、ファイルの改行コードが変換されないこと。</p>

<h2>解決</h2>

<p>改行コードを「LF」に変換するだけという、単純なものではありません。</p>

<p>実際は、ファイルをアスキーモードでFTPアップロードしても、改行コード「LF」に変換されません。</p>

<p>それは、FTP サーバ vsftpd ではアスキーモードでのダウンロード・アップロードのデフォルト設定が無効になっているから。</p>

<p>ということで vsftpd の設定をしてみる。</p>

<h3>1. vsftpd の設定をする</h3>
<p>シェル上で vsftpd.conf を編集。</p>

<pre class="prettyprint">
vi /etc/vsftpd/vsftpd.conf
</pre>

<p>設定内容を</p>
<pre class="prettyprint">
ascii_download_enable=NO
ascii_upload_enable=NO
</pre>

<p>から</p>

<pre class="prettyprint">
ascii_download_enable=YES
ascii_upload_enable=YES
</pre>

<p>に変更して有効に</p>

<h3>2. vsftpdを再起動</h3>

<pre class="prettyprint">
service vsftpd restart
</pre>

<h3>3. ファイルを再度アップロードする</h3>

<h3>4. 確認。Perl のパス「#!/usr/bin/perl」でうまく表示できた。</h3>

<p>complete!!</p>

<h2>教訓</h2>

<p>FTPの転送間違えの他、視野を広げてFTP サーバの設定も診てみよう。</p>


<h2>関連サイト</h2>
<ul>
	<li><a href="http://shikabo.ddo.jp/118.html" target="_blank" rel="nofollow">Perl：bad interpreter 対処方法の疑問</a></li>
	<li><a href="http://exposed.egoism.jp/wordpress/?p=306" target="_blank" rel="nofollow">vsftpd　アスキーモードでの転送</a></li>
	<li><a href="http://sakaguch.com/PastBBS/0032/B0016504.html" target="_blank" rel="nofollow">perlスクリプトの先頭行の「#!/usr/bin/perl --」の「--」をなくすには?</a></li>
	<li><a href="https://security.appspot.com/vsftpd/vsftpd_conf.html" target="_blank" rel="nofollow">Manpage of VSFTPD.CONF</a></li>
</ul>
]]>

</content>
</entry>

<entry>
<title>ワンソース・マルチデバイスが実現する WordPress プラグイン「Multi Device Switcher」</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000251.html" />
<modified>2012-03-20T03:31:07Z</modified>
<issued>2012-02-01T07:20:28Z</issued>
<id>tag:blog.thingslabo.com,2012://1.251</id>
<created>2012-02-01T07:20:28Z</created>
<summary type="text/plain">デバイス毎にテーマを切り替える WordPress プラグイン「Multi De...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>デバイス毎にテーマを切り替える WordPress プラグイン「Multi Device Switcher」をリリースしました。</p>

<p>デバイスの多様化が進んでいます。スマートフォンの急激な普及や携帯端末ゲームがインターネットに繋がったり、パソコンに変わりタブレット型端末を手に取ったり、そして近い将来テレビがネットに繋がるスマートテレビが実現と大小さまざまな大きさのモニターでインターネットを使うようになってきました。</p>

<p>その変化に対応してウェブサイトもあらゆるデバイスで見られるように最適化を図る必要に迫られています。</p>

<p>WordPress プラグイン「Multi Device Switcher」は WordPress のコンテンツマネジメントシステムを活かしてワンソース・マルチデバイスが実現するプラグインです。デバイス (現在 スマートフォン、タブレット端末、携帯モバイル、ゲームの 4 つに対応) によって自動的にテーマが切り替わります。</p>

<h2>インストール</h2>

<ol>
<li><a href="http://wordpress.org/extend/plugins/multi-device-switcher/" target="_blank">WordPress のプラグインページ</a>から zip ファイルをダウンロード</li>
<li>zip ファイルを解凍</li>
<li>"multi-device-switcher" をプラグインディレクトリ "/wp-content/plugins/" にアップロード</li>
<li>WordPress メニュー「プラグイン」で「Multi Device Switcher」を有効化</li>
<li>デバイスのテーマをディレクトリ "/wp-content/themes/" にアップロード</li>
<li>WordPress メニュー「外観 > マルチデバイス」へ</li>
<li>設定</li>
<li>完了</li>
</ol>

<p>または、WordPress メニュー「プラグイン > 新規追加」から「Multi Device Switcher」で検索してインストール、有効化。</p>


<h2>設定</h2>

<p>オプションは「テーマ」と「ユーザーエージェント」の2つです。タブで切り替えて設定できます。</p>

<h3>テーマ</h3>
<p>デバイス毎のテーマを選択します。テーマは前もって用意してください。</p>

<img src="http://blog.thingslabo.com/images/multi-device-switcher-screenshot-1.png" width="413" height="349" class="screenshot">

<h3>ユーザーエージェント</h3>
<p>デバイス毎のユーザーエージェントを必要に応じて追加修正できます。新しいユーザーエージェントが出たときに追加してください。</p>

<img src="http://blog.thingslabo.com/images/multi-device-switcher-screenshot-2.png" width="514" height="666"class="screenshot" >

<p>以上でデバイス毎にテーマが切り替わります。</p>

<h2>ちょっとした活用法</h2>

<p>テーマオプションを「None」にするとテーマは切り替わりません。CSS3 の Media Queries (メディアクエリ) を採用してレイアウトがデバイスに最適化 (レスポンシブ・ウェブデザイン) しているテーマはテーマの切り替えが必要ありません。その場合に設定します。他のプラグインと組み合わせた柔軟な運営もできます。スマートフォンの表示にプラグイン「WPtouch」や携帯電話端末の表示にプラグイン「Ktai Style」に任せることができます。</p>


<h2>=== Multi Device Switcher ===</h2>

<p>This WordPress plugin allows you to set a separate theme for device (Smart Phone, Tablet PC, Mobile Phone, Game).</p>

<h3>== Description ==</h3>

<p>This WordPress plugin allows you to set a separate theme for device (Smart Phone, Tablet PC, Mobile Phone, Game).
This plugin detects if your site is being viewed by UserAgent and switches to selected theme.</p>

<h3>== Installation ==</h3>

<ol>
<li>Unzip files.</li>
<li>Upload "multi-device-switcher" to the "/wp-content/plugins/" directory.</li>
<li>Activate the plugin through the 'Plugins' menu in WordPress</li>
<li>Upload a separate theme to the "/wp-content/themes/" directory.</li>
<li>Go to the "Multi Device Switcher" options page through the 'Appearance' menu in WordPress.</li>
<li>Configure settings to your needs. Select Theme by Theme option. Add and fix UserAgent by UserAgent option if necessary.</li>
<li>Have fun!</li>
</ol>

<h3>Download:</h3>

<p><a href="http://wordpress.org/extend/plugins/multi-device-switcher/" target="_blank">WordPress のプラグインページからどうぞ。</a></p>

<h3>Licenses:</h3>

<p>Licensed under GPL version 2.0</p>

<h3>GitHub:</h3>

<p><a href="https://github.com/thingsym/multi-device-switcher" target="_blank">thingsym / multi-device-switcher</a></p>

<h3>Donationware:</h3>

<p>よろしければ、開発とメンテナンスのために寄付していただければうれしいです。</p>

<p>If you like this plugin, please donate to support development and maintenance.</p>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="9L53NELFMHTWW">
<table class="no-border">
<tr><td><input type="hidden" name="on0" value="Donationware">Donationware</td></tr><tr><td><select name="os0">
	<option value="1. Donate">1. Donate $3.00 USD</option>
	<option value="2. Donate">2. Donate $5.00 USD</option>
	<option value="3. Donate">3. Donate $7.00 USD</option>
	<option value="4. Donate" selected="selected">4. Donate $10.00 USD</option>
	<option value="5. Donate">5. Donate $20.00 USD</option>
	<option value="6. Donate">6. Donate $30.00 USD</option>
	<option value="7. Donate">7. Donate $40.00 USD</option>
	<option value="8. Donate">8. Donate $50.00 USD</option>
	<option value="9. Donate">9. Donate $60.00 USD</option>
	<option value="10. Donate">10. Donate $70.00 USD</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/ja_JP/i/scr/pixel.gif" width="1" height="1">
</form>
]]>

</content>
</entry>

<entry>
<title>JavaScriptを圧縮するツール「Minify JavaScript」</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000187.html" />
<modified>2012-05-15T08:19:44Z</modified>
<issued>2011-10-17T06:42:43Z</issued>
<id>tag:blog.thingslabo.com,2011://1.187</id>
<created>2011-10-17T06:42:43Z</created>
<summary type="text/plain">スタイルシートを圧縮するツール「Minify CSS」に続いて、JavaScri...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p><a href="http://blog.thingslabo.com/archives/000186.html">スタイルシートを圧縮するツール「Minify CSS」</a>に続いて、JavaScriptを圧縮するツール「Minify JavaScript」もつくってみた。</p>

<p>ファイルをアップロードするか、ソースを貼り付けるだけで圧縮してくれます。ファイルは複数アップロード可能でソースをまとめて圧縮、出力してくれます。ソースを符号化する Packer には未対応です。</p>]]>
<![CDATA[<div  id="minify2js">
<h1>Minify JavaScript</h1>
<fieldset id="js-minifier">
<h2 class="label">JavaScript</h2>
<form method="post" action="http://api.thingslabo.com/minify/minify2js.cgi" enctype="multipart/form-data" target="uploader">

<div id="accordion-js-minifier">
<h3>ファイル</h3>
<div>
<input type="file" name="file" id="file" multiple>
<button onclick="this.form.file.value='';return false;"/>ファイル削除</button>
<p class="note">ファイルサイズは1MBまで。複数のファイルをアップロードできます。</p>
</div>
<h3>ソース</h3>
<div>
<textarea name="source" rows="10" cols="64"></textarea>
</div>
</div>
<input type="submit" value="Minify">
</form>
</fieldset>

<fieldset id="uploader">
<iframe name="uploader" src="" id="uploader"></iframe>
</fieldset>
</div>

<p>「Minify CSS」「Minify JavaScript」をまとめた「<a href="http://api.thingslabo.com/minify/" target="_blank">Minify</a>」もどうぞ。
</p>]]>
</content>
</entry>

<entry>
<title>スタイルシートを圧縮するツール「Minify CSS」</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000186.html" />
<modified>2012-05-15T08:19:56Z</modified>
<issued>2011-10-15T09:07:51Z</issued>
<id>tag:blog.thingslabo.com,2011://1.186</id>
<created>2011-10-15T09:07:51Z</created>
<summary type="text/plain">ウェブサイトやウェブアプリの表示の最適化を求められている昨今。Google の検...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>ウェブサイトやウェブアプリの表示の最適化を求められている昨今。Google の検索エンジンもウェブページの表示の高速化を考慮に入れたり、ウェブサイトのパフォーマンス如何でアクセス数やコンバージョン率、売上に影響を与えつつあり、パフォーマンス向上のため、最適化の必要性が高まっている。</p>

<p>スタイルシートは、HTML5 の普及につれて表現が豊かになりつつあるが、その反面スタイルシートの記述が複雑になり、ファイルサイズも大きくなりつつある。</p>

<p>まず、スタイルシートの最適化に大きく期待できる、2つのポイントを押さえておきたい。</p>

<ul>
<li>複数の外部ファイルをまとめて HTTP リクエスト数を減らす</li>
<li>スタイルシートファイルを圧縮してダウンロードサイズを減らす</li>
</ul>

<p>ということで、スタイルシートを圧縮するツールをつくってみた。ファイルをアップロードするか、ソースを貼り付けるだけでスタイルシートを圧縮してくれます。ファイルは複数アップロード可能。</p>
]]>
<![CDATA[<div  id="minify2css">
<h1>Minify CSS</h1>
<fieldset id="css-minifier">
<h2 class="label">Style Sheet</h2>
<form method="post" action="http://api.thingslabo.com/minify/minify2css.cgi" enctype="multipart/form-data" target="uploader">

<div id="accordion-css-minifier">
<h3>ファイル</h3>
<div>
<input type="file" name="file" id="file" multiple>
<button onclick="this.form.file.value='';return false;"/>ファイル削除</button>
<p class="note">ファイルサイズは1MBまで。複数のファイルをアップロードできます。</p>
</div>
<h3>ソース</h3>
<div>
<textarea name="source" rows="10" cols="64"></textarea>
</div>
</div>
<input type="submit" value="Minify">
</form>
</fieldset>

<fieldset id="uploader">
<iframe name="uploader" src="" id="uploader"></iframe>
</fieldset>
</div>

<h3>関連サイト</h3>
<ul>
<li><a href="http://developer.yahoo.com/yui/compressor/" target="_blank">YUI Compressor</a></li>
<li><a href="http://code.google.com/p/minify/" target="_blank">minify - Combines, minifies, and caches JavaScript and CSS files on demand to speed up page loads. </a></li>
</ul>
]]>
</content>
</entry>

<entry>
<title>MySQLをバージョン5.5.xにアップデート</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000185.html" />
<modified>2012-03-16T01:21:27Z</modified>
<issued>2011-08-30T08:10:48Z</issued>
<id>tag:blog.thingslabo.com,2011://1.185</id>
<created>2011-08-30T08:10:48Z</created>
<summary type="text/plain">yum 経由で MySQL をアップデートした備忘録。 MySQL がバージョン...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>yum 経由で MySQL をアップデートした備忘録。</p>

<p>MySQL がバージョン 5.5.3  なってからコマンドやサーバオプション、変数に大幅な変更や廃止が加えられている。グーグルで検索すると今回の変更のことで MySQL が起動しないことがたくさんヒットする。この機会に古い設定を見直しておきたい。</p>

<p>バージョン5.5.x のインストールは無事に済んだが、データベースに繋がらず。</p>

<pre class="prettyprint">
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
</pre>

<p>再起動しても失敗。ログを見ると、いくつかエラーが見られる。</p>

<pre class="prettyprint">
tail -50 /var/log/mysqld.log

...
110830 12:39:45 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
...
110830 12:39:46 [ERROR] /usr/libexec/mysqld: unknown variable 'default-character-set=utf8'
110830 12:39:46 [ERROR] Aborting
...
110830 12:39:47 [Note] /usr/libexec/mysqld: Shutdown complete
</pre>

<p>一つ一つ解決。</p>

<p>まずは、デフォルトで文字コードを設定しているが、文字コードの設定の方法が変わったみたいだ。それで MySQL が起動せずにシャットダウン。</p>

<p>my.cnf の設定を変更。[mysqld] ディレクティブにある default-char-set を</p>

<pre class="prettyprint">
default-character-set=utf8
</pre>
<p>から</p>
<pre class="prettyprint">
character-set-server=utf8
</pre>

<p>に変更。</p>

<p>再起動ができるようになった。</p>

<p>そしてつぎは、アップグレードの度に実行する mysql_upgrade コマンドでテーブルの互換性をチェック、修正を施す。</p>

<pre class="prettyprint">
mysql_upgrade -u root -p
</pre>

<p>無事アップグレードが済んで、データベースに繋がった。</p>

<h3>関連サイト</h3>
<ul>
<li><a href="http://unix.codenote.net/mysql/default-character-set-で起動が失敗する.html" target="_blank" rel="nofollow">default-character-set で起動が失敗する</a></li>
<li><a href="http://firegoby.theta.ne.jp/archives/2170" target="_blank" rel="nofollow">MySQL5.5.3にアップグレードしたら再起動に失敗した。</a></li>
<li><a href="http://blog.shimabox.net/2011/04/29/mysqlが繋がらなくなってたので対応した/" target="_blank" rel="nofollow">mysqlが繋がらなくなってたので対応した</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_character-set-server" target="_blank" rel="nofollow">5.1.2. Server Command Options</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.5/en/news-5-5-3.html" target="_blank" rel="nofollow">D.1.14. Changes in MySQL 5.5.3 (24 March 2010 Milestone 3)</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.5/en/mysql-nutshell.html" target="_blank" rel="nofollow">1.5. What Is New in MySQL 5.5</a></li>
<li><a href="http://d.hatena.ne.jp/sakaik/20100414/mysql533obsol" target="_blank" rel="nofollow">MySQL 5.5.3-m3 で廃止になった変数やオプションなどを整理しました</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.1/ja/mysql-upgrade.html" target="_blank" rel="nofollow">4.5.4. mysql_upgrade -- MySQL アップグレードのテーブル チェック</a></li>
</ul>
]]>

</content>
</entry>

<entry>
<title>PHPでHTML上にエラー表示/非表示する php.ini 設定</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000184.html" />
<modified>2012-03-19T10:01:28Z</modified>
<issued>2011-07-23T07:27:44Z</issued>
<id>tag:blog.thingslabo.com,2011://1.184</id>
<created>2011-07-23T07:27:44Z</created>
<summary type="text/plain">PHP でのエラー表示は php.ini にある display_errors ...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>PHP でのエラー表示は php.ini にある</p>

<pre class="prettyprint">
display_errors = On
</pre>

<p>で HTML 上にエラーが表示される。</p>

<pre class="prettyprint">
display_errors = Off
</pre>

<p>で HTML 上に表示されなくなる。</p>


<p>さらにエラーレポートレベルによってエラーの種類を設定する必要がある。</p>

<p>PHP 4 と PHP 5 のデフォルトは</p>

<pre class="prettyprint">
error_reporting = E_ALL & ~E_NOTICE
</pre>

<p>他は、全てのエラー出力をオフにする</p>

<pre class="prettyprint">
error_reporting = 0
</pre>

<p>全てのエラーを出力する</p>

<pre class="prettyprint">
error_reporting = E_ALL
</pre>

<p>など<a href="http://www.php.net/manual/ja/errorfunc.constants.php" target="_blank">定義済み定数</a>で細かく設定できる。</p>

<p>php.ini にあるサンプルには</p>

<pre class="prettyprint">
error_reporting
 Default Value: E_ALL & ~E_NOTICE
 Development Value: E_ALL | E_STRICT
 Production Value: E_ALL & ~E_DEPRECATED
</pre>

<p>とある。</p>

<p>開発環境には以下の設定を。</p>

<pre class="prettyprint">
error_reporting = E_ALL | E_STRICT
</pre>

<p>E_ALL には PHP5 から追加された E_STRICT が含まれていないため、E_STRICT で互換性がない推奨されていないコードの警告とスクリプトのチェックをしたい。</p>

<p>Webサービスとして運営する時には、</p>

<pre class="prettyprint">
error_reporting = E_ALL & ~E_DEPRECATED
</pre>

<p>PHP 5.3.0 で新しく加わった E_DEPRECATED で特定の機能が将来のPHPバージョンで推奨されない場合に警告が表示されるので、回避策として。</p>

<p>さらに</p>

<pre class="prettyprint">
display_errors = Off
</pre>

<p>でエラー表示をなくしたい。</p>


<h3>関連サイト</h3>
<ul>
<li><a href="http://www.php.net/manual/ja/function.error-reporting.php" target="_blank">PHP: error_reporting - Manual</a></li>
<li><a href="http://www.php.net/manual/ja/errorfunc.configuration.php#ini.error-reporting" target="_blank">PHP: 実行時設定 - Manual</a></li>
<li><a href="http://www.php.net/manual/ja/errorfunc.constants.php" target="_blank">PHP: 定義済み定数 - Manual</a></li>
<li><a href="http://www.php.net/manual/ja/migration53.deprecated.php" target="_blank">PHP: PHP 5.3.x で推奨されない機能 - Manual</a></li>
</ul>]]>

</content>
</entry>

<entry>
<title>Fatal error: Allowed memory size of ... に対処してPHPの使用メモリを増やす</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000183.html" />
<modified>2011-07-22T07:10:30Z</modified>
<issued>2011-07-22T07:07:14Z</issued>
<id>tag:blog.thingslabo.com,2011://1.183</id>
<created>2011-07-22T07:07:14Z</created>
<summary type="text/plain">WordPress などを使っていると PHP スクリプトがサーバーに割り当てら...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>WordPress などを使っていると PHP スクリプトがサーバーに割り当てられたメモリをオーバーして使用している際に遭遇する。</p>

<pre class="prettyprint">
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 19456 bytes) in ....
</pre>

<p>そこで、メモリーを増やすことに。設定は /etc/php.ini に。</p>

<pre class="prettyprint">
memory_limit = 16M
</pre>

<p>から</p>

<pre class="prettyprint">
memory_limit = 32M
</pre>

<p>に変更して保存。</p>

<p>Apacheを再起動して確認。</p>

<p>あらら、またまた同じエラーが。</p>

<pre class="prettyprint">
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 19456 bytes) in ....
</pre>

<p>phpinfo() で確認すると、memory_limit の項目が Master Value では 32M。Local Value では 16M と php.ini で設定された値とは別に .htaccess や httpd.conf など他のどこかで設定されているようだ。</p>

<p>サーバーに <a href="http://dream.jp/vps/" target="_blank">ServersMan@VPS</a> を使っている場合、いろいろ探してみるとサブドメインの設定 (/etc/httpd/conf.d/subdomains/site1.xxx.conf) に該当箇所があった。削除するか、</p>

<pre class="prettyprint">
php_admin_value memory_limit 16M
</pre>

<p>から</p>

<pre class="prettyprint">
php_admin_value memory_limit 32M
</pre>

<p>に変更保存。</p>

<p>再びサーバ再起動。</p>

<pre class="prettyprint">
/etc/init.d/httpd restart
</pre>

<p>phpinfo() でも Master Value と Local Value が同じ 32M を確認。</p>

<p>きちっとメモリーが割り当てられた。</p>


<h3>関連サイト</h3>
<ul>
<li><a href="http://jp.php.net/manual/ja/ini.core.php#ini.memory-limit" target="_blank">PHP: コア php.ini ディレクティブに関する説明</a></li>
<li><a href="http://webtech-walker.com/archive/2007/03/05152445.html" target="_blank">phpでmemory sizeエラーがでたときの対処法</a></li>
<li><a href="http://blog.stylem.info/denno/?p=294" target="_blank">ServersMan@VPSの導入（５）～WordPress導入編～</a></li>
</ul>]]>

</content>
</entry>

<entry>
<title>スタイルシートを切り替えるjQuery Plugin「CssSwitcher」アップグレード</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000069.html" />
<modified>2012-01-29T13:02:06Z</modified>
<issued>2011-06-27T06:30:59Z</issued>
<id>tag:blog.thingslabo.com,2011://1.69</id>
<created>2011-06-27T06:30:59Z</created>
<summary type="text/plain">スタイルシートを切り替える jQuery Plugin「CssSwitcher」...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>スタイルシートを切り替える jQuery Plugin「CssSwitcher」をアップグレードしました。あわせて JavaScript 版もアップグレード。</p>

<p>改良点は二つ。</p>

<ul>
<li>ソースの全面見直し。初期設定の仕方を変更しました。</li>
<li>ブラウザの戻るボタンで前のページに戻る際に、先のページで変更したスタイルシートが反映されない場合の対処</li>
</ul>

<p>二つ目はブラウザによって挙動が違うのですが、ブラウザで直前まで見ていたページの状態を復元する「Back Forward Cache」が働いているため、スタイルシートが反映されないことが起こっているようです。Firefox ではデフォルトで「Back Forward Cache」がオンの状態。</p>

<h3>参考</h3>
<ul>
<li><a href="https://developer.mozilla.org/ja/Using_Firefox_1.5_caching" target="_blank">Using Firefox 1.5 caching</a></li>
<li><a href="http://nmi.jp/archives/273" target="_blank">戻るボタンが押された際、ページのJavaScriptを途中の状態から実行させない方法</a></li>
</ul>]]>
<![CDATA[<p>ページ遷移は、</p>
<p>前ページ --[リンクをクリック]--> 今見ているページ (ここでスタイルシートを変更) --[ブラウザの戻るボタンで戻る]--> 前のページ (あらら、以前のスタイルシートの設定のまま)</p>

<p>これが、</p>
<p>前ページ --[リンクをクリック]--> 今見ているページ (ここでスタイルシートを変更) --[ブラウザの戻るボタンで戻る]--> 前のページ (スタイルシートを変更反映)</p>

<p>になります。</p>

<h2>デモサンプル</h2>
<ul>
<li><a href="http://demo.thingslabo.com/apps/CssSwitcher-0.0.2/demo/jquery.cssswitcher_mix.html" target="_blank">jQuery Plugin cssswitcher.js * Mix</a></li>
<li><a href="http://demo.thingslabo.com/apps/CssSwitcher-0.0.2/demo/cssswitcher_mix.html" target="_blank">CssSwitcher * Mix</a></li>
</ul>

<p>これでいままで抱えていた課題が解決できました。</p>

<blockquote>
<h3>技術的な課題:</h3>
<ul>
<li>ブラウザのボタン操作でのページ遷移とブラウザキャッシュ<br>
ブラウザの戻るボタンでの前のページに戻る際に、先のページで変更したスタイルシートが反映されない場合がある。</li>
</ul>
<p><a href="http://blog.thingslabo.com/archives/000045.html">スタイルシートを切り替えるjQuery Plugin「CssSwitcher」</a>より</p>
</blockquote>

<h2>初期設定の仕方を変更しました。</h2>

<p>ソースの全面見直しに伴い以下に変更。</p>

<pre class="prettyprint">
 var CssSwitcher = {
  // Settings
  cssPath : "http://domain/path/to/css/", // http://domain/path/to/css/
  idList : [ 'layout', 'font', 'color' ], // List up id attribute of 'stylesheet' rel attribute
  // Cookie Settings
  domain : "",
  path : "/",
  expires : 7, // days or a Date object Wdy, DD-Mon-YYYY HH:MM:SS GMT (ex. Fri, 01-Dec-2010 20:40:03 GMT)
  secure : 0, // 0 or 1
...

</pre>

<p>基本設定</p>
<ul>
<li>「cssPath」スタイルシートファイルのディレクトリパス</li>
<li>「idList」スタイルシートのIDリスト、link要素に追加したid名</li>
</ul>
<p>Cookieの設定を必要に応じて</p>
<ul>
<li>「domain」Webサーバー名</li>
<li>「path」パス名</li>
<li>「expires」有効期限 日数 または Wdy, DD-Mon-YYYY HH:MM:SS GMT形式</li>
<li>「secure」セキュリティ</li>
</ul>

<p>他の設定と使い方は、従来通りです。以下のページを参考ください。</p>

<ul>
<li><a href="http://blog.thingslabo.com/archives/000045.html">jQuery Plugin版「CssSwitcher」</a></li>
<li><a href="http://blog.thingslabo.com/archives/000044.html">JavaScript版「CssSwitcher」</a></li>
</ul>

<h3>Download:</h3>

<p><a href="http://download.thingslabo.com/jquery/CssSwitcher/jquery.cssswitcher-0.0.2.js" target="_blank">jquery.cssswitcher-0.0.2.js</a></p>
<p><a href="http://download.thingslabo.com/javascript/CssSwitcher/cssswitcher-0.0.2.js" target="_blank">cssswitcher-0.0.2.js</a></p>


<h3>Changes:</h3>

<ul>
<li>0.0.2 2011.06.27 Fix browser cache. </li>
<li><a href="http://blog.thingslabo.com/archives/000045.html">0.0.1 2010.09.02 First Release. (jQuery Plugin版)</a></li>
<li><a href="http://blog.thingslabo.com/archives/000044.html">0.0.1 2010.08.13 First Release. (JavaScript版)</a></li>
</ul>

<h3>Licenses:</h3>

<p>Dual licensed under the MIT and GPL licenses.</p>]]>
</content>
</entry>

<entry>
<title>Perl で OAuth / モジュール OAuth::Lite::Consumer インストール</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000063.html" />
<modified>2012-03-18T17:18:08Z</modified>
<issued>2011-05-26T08:15:43Z</issued>
<id>tag:blog.thingslabo.com,2011://1.63</id>
<created>2011-05-26T08:15:43Z</created>
<summary type="text/plain">Twitter や Facebook などウェブサービスの連携には欠かせなくなり...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>Twitter や Facebook などウェブサービスの連携には欠かせなくなりつつある認証システム OAuth (オー オース)。アプリ開発者としてマスターしておきたい認証システムのひとつ。今回モジュール <a href="http://search.cpan.org/~lyokato/OAuth-Lite-1.30/lib/OAuth/Lite/Consumer.pm" target="_blank">OAuth::Lite::Consumer</a> をインストールして、Perlで OAuth 認証できる環境をつくってみた。Twitter で認証してアカウント情報を表示するサンプルプログラムも。</p>


<h2>OAuth::Lite::Consumer インストール</h2>
<p>ふつうに cpanm でインストールできず。パッケージ openssl-devel が必要。</p>

<pre class="prettyprint">
cpanm OAuth::Lite::Consumer
</pre>

<pre class="prettyprint">
...
Checking if you have Crypt::OpenSSL::RSA 0.25 ... No
Checking if you have Crypt::OpenSSL::Random 0.04 ... No
...
</pre>

<p>エラーで止まってしまう。パッケージがないので、perlモジュールの依存関係を解決できず。</p>

<p>まずは、パッケージ openssl-devel をインストール。</p>

<pre class="prettyprint">
yum install openssl-devel
</pre>

<p>インストール後。</p>

<pre class="prettyprint">
cpanm OAuth::Lite::Consumer
</pre>

<p>complete!!</p>


<h2>サンプルプログラム</h2>

<p>Twitter のアカウントでログイン認証。アクセストークンを取得して Twitter のアカウント情報を表示するサンプルプログラム。サンプルを動かすには Twitter にアプリケーションを登録して、ConsumerKey と ConsumerSecret を取得する必要があります。
登録は <a href="https://dev.twitter.com/" target="_blank">dev.twitter.com</a> から。</p>

<h3>流れとメソッド</h3>
<ol>
<li>リクエストトークンを取得する - <a href="http://search.cpan.org/~lyokato/OAuth-Lite-1.30/lib/OAuth/Lite/Consumer.pm#get_request_token(%params)" target="_blank">get_request_token()</a></li>
<li>リクエストトークンを元に認証 - <a href="http://search.cpan.org/~lyokato/OAuth-Lite-1.30/lib/OAuth/Lite/Consumer.pm#url_to_authorize(%params)" target="_blank">url_to_authorize()</a></li>
<li>Twitterログイン画面でアプリ認証</li>
<li>アプリ認証ボタンを押すと callback_url に転送 (リダイレクト)</li>
<li>アクセストークンの取得 - <a href="http://search.cpan.org/~lyokato/OAuth-Lite-1.30/lib/OAuth/Lite/Consumer.pm#get_access_token(%params)" target="_blank">get_access_token()</a></li>
<li>アクセストークンを元に認証が必要なリクエスト (<a href="https://dev.twitter.com/doc/get/account/verify_credentials" target="_blank">GET account/verify_credentials</a>) を発行、今回Twitterアカウント情報を表示 - <a href="http://search.cpan.org/~lyokato/OAuth-Lite-1.30/lib/OAuth/Lite/Consumer.pm#gen_oauth_request(%args)" target="_blank">gen_oauth_request()</a></li>
</ol>

<pre class="prettyprint linenums">
#!/usr/bin/perl

use strict;
use warnings;
use utf8;

use CGI;
use OAuth::Lite::Consumer;
use LWP::UserAgent;
use JSON;

my $ConsumerKey = 'xxxxxxx';
my $ConsumerSecret = 'xxxxxxxx';
my $callback_url = 'xxxxxxxx';

my $consumer = OAuth::Lite::Consumer->new(
    consumer_key    => $ConsumerKey,
    consumer_secret => $ConsumerSecret,
    site => "http://twitter.com/",
    request_token_path => "https://api.twitter.com/oauth/request_token",
    access_token_path => "https://api.twitter.com/oauth/access_token",
    authorize_path => "https://api.twitter.com/oauth/authorize",
    callback_url => $callback_url,
);

my $query = CGI->new;

if ($query->param('oauth_token') && $query->param('oauth_verifier')) {
    my $access_token = $consumer->get_access_token(
        token => $query->param('oauth_token'),
        verifier => $query->param('oauth_verifier'),
    );

    my $req = $consumer->gen_oauth_request(
        method => 'GET',
        url => 'http://api.twitter.com/1/account/verify_credentials.json',
        token => $access_token,
    );

    my $ua = new LWP::UserAgent();
    my $res = $ua->request($req);

    die $res->status_line if ! $res->is_success;

    my $account = decode_json($res->content);

    print "Content-type: text/html;charset=UTF-8\n\n";
    print "&lt;img src='$account-&gt;{profile_image_url}' /&gt;";
    print "&lt;p&gt;ID : $account-&gt;{id}&lt;/p&gt;";
    print "&lt;p&gt;name : $account-&gt;{name}&lt;/p&gt;";
    print "&lt;p&gt;screen_name : $account-&gt;{screen_name}&lt;/p&gt;";
    print "&lt;p&gt;description : $account-&gt;{description}&lt;/p&gt;";
    exit;
}
else {
    my $request_token = $consumer->get_request_token();

    my $uri = $consumer->url_to_authorize(
        token => $request_token,
    );

    print $query->redirect($uri);
}
exit;
</pre>


<h3>関連サイト</h3>
<ul>
<li><a href="http://search.cpan.org/~lyokato/OAuth-Lite-1.30/lib/OAuth/Lite/Consumer.pm" target="_blank">OAuth::Lite::Consumer</a></li>
<li><a href="https://dev.twitter.com/" target="_blank">dev.twitter.com</a></li>
<li><a href="http://oauth.net/code/" target="_blank">OAuth Community Site</a></li>
<li><a href="http://gihyo.jp/dev/feature/01/oauth/0001" target="_blank">ゼロから学ぶOAuth</a></li>
<li><a href="http://developer.yahoo.co.jp/other/oauth/flow.html"> Yahoo!デベロッパーネットワーク - OAuth - フロー</a></li>
<li><a href="http://d.hatena.ne.jp/yuroyoro/20100506/1273137673">OAuthプロトコルの中身をざっくり解説してみるよ</a></li>
<li><a href="http://d.hatena.ne.jp/punitan/20100206/1265417663" target="_blank">PerlでTwitterのOAuthを使うサンプル</a></li>
<li><a href="http://d.hatena.ne.jp/xlc/20110228/1298900300" target="_blank">OAuth::Liteを使って、はてなでOAuth認証</a></li>
</ul>]]>

</content>
</entry>

<entry>
<title>PHPを 5.1.x から 5.3.x にアップデートすると、phpMyAdmin にアクセスできなくなった</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000062.html" />
<modified>2011-04-04T09:05:15Z</modified>
<issued>2011-04-04T08:29:58Z</issued>
<id>tag:blog.thingslabo.com,2011://1.62</id>
<created>2011-04-04T08:29:58Z</created>
<summary type="text/plain">phpMyAdmin のエラー表示には、 エラーが出たためセッションを開始できま...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>phpMyAdmin のエラー表示には、</p>

<blockquote>
<p>エラーが出たためセッションを開始できませんでした。PHP やウェブサーバのログファイルに出ているエラーを確認して、PHP を正しく設定してください。
</blockquote>

<p>と。以降、phpMyAdmin のログイン画面が表示されてもログインできず。</p>


<p> セッションファイルの保存場所 /var/lib/php/session のパーミッションが 770 (drwxrwx---) になっているので、セッションファイルが書き込めない状態になっているようだ。</p>

<pre class="prettyprint">
sudo chmod 777 /usr/lib/php/session
</pre>

<p>で、パーミッションを 777 (drwxrwxrwx) に変更するとログインできた。</p>

<p>PHP をアップデートするときは、確認しておきたい。</p>


<h3>関連する記事をピックアップ</h3>
<ul>
<li><a href="http://network.station.ez-net.jp/server/web/apache/php/error.session.asp" target="_blank">PHP のセッション処理でエラーになる</a></li>
<li><a href="http://phprefa.seesaa.net/article/91236056.html" target="_blank">phpでセッションを利用</a></li>
</ul>]]>

</content>
</entry>

<entry>
<title>Google Appsを使って独自ドメインのメールアドレスで Gmail</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000061.html" />
<modified>2011-04-05T05:24:10Z</modified>
<issued>2011-03-01T13:53:37Z</issued>
<id>tag:blog.thingslabo.com,2011://1.61</id>
<created>2011-03-01T13:53:37Z</created>
<summary type="text/plain">メールサーバを立ち上げて独自ドメインでメールを受け取るといつのまにかスパムメール...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>メールサーバを立ち上げて独自ドメインでメールを受け取るといつのまにかスパムメールが届く。基本はスパムフィルタを導入したりサーバの設定を調整することで対応するが、なかなか根絶は難しい。日々のメール処理でスパムメールに悩まれている方も多いと思う。今回優れたスパムフィルタがあるGmailでメールを受け取ってみることに。</p>

<p>独自ドメインと<a href="http://muumuu-domain.com/" target="_blank">ムームードメイン</a>でDNSがカスタマイズできるムームーDNSを使ってやってみます。</p>


<p>まず<a href="http://www.google.com/apps/intl/ja/group/index.html" target="_blank">Google Apps</a>で申し込み。</p>

<p>Google Appsは、ユーザーアカウント50個まで無料で使える。それ以上は <a href="http://www.google.com/apps/intl/ja/business/index.html" target="_blank">Google Apps for Business</a> で。いろいろな機能を追加で使えたり、Gmailの容量も25GBに。月額6,000円。</p>

<p>すでにドメインを持っている場合は、ドメイン名を入力して申し込もう。あとはフォームに従って入力していく。</p>

<img alt="googleapps1.png" src="http://blog.thingslabo.com/img/googleapps1.png" width="324" height="226" class="mt-image-none" style="" />

<p>次はドメインの所有確認。HTMLファイルをアップロードするか、CNAME レコードの変更の2つの方法。今回はHTMLファイルのアップロードで対応。</p>

<img alt="googleapps2.png" src="http://blog.thingslabo.com/img/googleapps2.png" width="373" height="208" class="mt-image-none" style="" />

<p>googlehostedservice.html にテキストを入力して作成保存。サーバにアップロード。
「確認」ボタンを押す。</p>

<p>上手くいくと設定ガイドに。</p>

<p>まずは、「組織とユーザー」でいままで運営していたメールアカウントを移行する。
「新しいユーザーを作成」ボタンを押してメールアカウントを作っていく。</p>

<img alt="googleapps3.png" src="http://blog.thingslabo.com/img/googleapps3.png" width="389" height="154" class="mt-image-none" style="" />
<img alt="googleapps4.png" src="http://blog.thingslabo.com/img/googleapps4.png" width="391" height="161" class="mt-image-none" style="" />

<p>作成後、ダッシュボードへ。「Gmailを有効にする」をクリック。</p>

<img alt="googleapps5.png" src="http://blog.thingslabo.com/img/googleapps5.png" width="176" height="73" class="mt-image-none" style="" />

<p>ここからムームードメインの管理画面でDNSをカスタマイズします。ムームーDNSのカスタム設定でMX レコードごとにGoogle Appsの管理画面にある表に従って情報を入力していきます。「セットアップ情報変更」ボタンを押して反映。DNSの反映に時間がかかるので一休み。</p>

<img alt="googleapps6.png" src="http://blog.thingslabo.com/img/googleapps6.png" width="451" height="200" class="mt-image-none" style="" />

<p>そして、Google Appsの管理画面に戻って「指定された手順を完了しました」ボタンを押して完了。</p>

<p>MXレコードの確認。最大48時間程度かかるようだ。</p>

<p>無事反映されると、Gmailから独自ドメインのメールアドレスとパスワードでログイン。</p>

<img alt="googleapps7.png" src="http://blog.thingslabo.com/img/googleapps7.png" width="136" height="107" class="mt-image-none" style="" />
<br>
<img alt="googleapps8.png" src="http://blog.thingslabo.com/img/googleapps8.png" width="406" height="131" class="mt-image-none" style="" />

<p>これで独自ドメインを使ってメールを送ったり受け取ったりできる。日々のメール処理でスパムメールに悩まれている方はどうぞ。</p>]]>

</content>
</entry>

<entry>
<title>専用サーバ運営では必須の不正アクセス対策 SSHのポート番号変更</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000060.html" />
<modified>2011-03-23T02:59:00Z</modified>
<issued>2011-01-17T11:41:31Z</issued>
<id>tag:blog.thingslabo.com,2011://1.60</id>
<created>2011-01-17T11:41:31Z</created>
<summary type="text/plain">サーバを運営していると、SSH経由でユーザ名とパスワートの総当たりで不正な接続を...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>サーバを運営していると、SSH経由でユーザ名とパスワートの総当たりで不正な接続を試みる攻撃 (<a href="http://ja.wikipedia.org/wiki/総当たり攻撃" target="_blank">ブルートフォースアタック</a>) を受けることが多い。<a href="http://blog.thingslabo.com/archives/000054.html">ログ監視ツール Logwatch</a> から毎日送られてくるレポートでも多数確認できる。root には数千件の数で試みられているのが見受けられることも。</p>

<p>対策は、ssh のポート番号を変更すること。デフォルトのポート番号 22 での接続を避ける。</p>

<p>デフォルトのポート番号 22 から別の番号に変更することで断続的な不正アクセスを無くして、サーバの負荷軽減にもなる。</p>

<p>ということで、sshのポート番号を変更。</p>

<p>設定ファイルを編集。</p>

<pre class="prettyprint">
$ vi /etc/ssh/sshd_config
</pre>

<p>デフォルトではコメントアウトでポート番号 22 が使われているので、任意のポート番号 **** に変更。ポート番号は、使用されていない 0～1023  (<a href="http://e-words.jp/w/E382A6E382A7E383ABE3838EE382A6E383B3E3839DE383BCE38388.html" target="_blank">ウェルノウンポート</a>) 以外のポート番号に変更しましょう。</p>

<pre class="prettyprint">
#Port 22
Port ****
</pre>

<p>SSHを再起動。</p>

<pre class="prettyprint">
$ /etc/init.d/sshd restart
</pre>


<h3>接続確認</h3>

<p>まずはポート番号 22 で接続。</p>

<pre class="prettyprint">
$ ssh ユーザID@ホスト名
$ ssh: connect to host **.**.**.** port 22: Connection refused
</pre>

<p>ポート番号 22 では接続が拒否される。</p>

<p>変更したポート番号で接続。</p>

<pre class="prettyprint">
$ ssh -p ポート番号 ユーザID@ホスト名
</pre>

<p>接続できれば完了。</p>



<ul>
<li><a href="http://ja.wikipedia.org/wiki/%E7%B7%8F%E5%BD%93%E3%81%9F%E3%82%8A%E6%94%BB%E6%92%83" target="_blank">総当たり攻撃 - Wikipedia</a></li>
<li><a href="http://e-words.jp/w/E38396E383ABE383BCE38388E38395E382A9E383BCE382B9E694BBE69283.html" target="_blank">ブルートフォース攻撃</a></li>

<li><a href="http://dream.jp/vps/manual/mnl_security.html#a_03" target="_blank">ssh用のポート番号を変更する - ServersMan@VPS仮想専用サーバーサービス</a></li>
<li><a href="http://futuremix.org/2005/09/sshd-port22" target="_blank">SSHの不正接続増加? ポート22は変更しましょう</a></li>
</ul>]]>

</content>
</entry>

<entry>
<title>analogのログフォーマット (turn debugging on or try different LOGFORMAT)</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000059.html" />
<modified>2011-03-23T02:42:42Z</modified>
<issued>2010-12-08T06:11:05Z</issued>
<id>tag:blog.thingslabo.com,2010://1.59</id>
<created>2010-12-08T06:11:05Z</created>
<summary type="text/plain">Cron からアラートメールが返ってくる。 /etc/cron.daily/lo...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>Cron からアラートメールが返ってくる。</p>

<pre class="prettyprint">
/etc/cron.daily/logrotate:

/usr/bin/analog: analog version 5.32/Unix
/usr/bin/analog: Warning L: Large number of corrupt lines in logfile stdin:
 turn debugging on or try different LOGFORMAT
 (For help on all errors and warnings, see docs/errors.html)
   Current logfile format:
     %v %S %j %u [%d/%M/%Y:%h:%n:%j] "%j%w%r%wHTTP%j" %c %b "%f" "%B"\n
     %S %j %u [%d/%M/%Y:%h:%n:%j] "%j%w%r%wHTTP%j" %c %b "%f" "%B"\n
     %S %j %u [%d/%M/%Y:%h:%n:%j] "%j%w%r" %c %b "%f" "%B"\n
     %S %j %u [%d/%M/%Y:%h:%n:%j] "%r" %c %b "%f" "%B"\n
</pre>

<p>analog のログフォーマットが違うみたいだ。Apache のログ形式は combined なので、analogの LOGFORMAT ( /etc/analog.cfg ) を確認。なかったので末尾に以下を追記。</p>

<pre class="prettyprint">
LOGFORMAT COMBINED
</pre>

<p>Apache のログ形式を変更したときには見直すことを忘れずに。</p>]]>

</content>
</entry>

<entry>
<title>画像をBase64に変換するツール (data URI scheme) </title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000058.html" />
<modified>2012-05-15T08:35:59Z</modified>
<issued>2010-11-25T07:50:38Z</issued>
<id>tag:blog.thingslabo.com,2010://1.58</id>
<created>2010-11-25T07:50:38Z</created>
<summary type="text/plain">Google のウェブ検索結果でウェブページのスクリーンショットに使われている ...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>Google のウェブ検索結果でウェブページのスクリーンショットに使われている data URI scheme。</p>

<p>data:[&lt;mediatype&gt;][;base64],&lt;data&gt; 形式のデータ (data URI scheme) を生成してウェブページに埋め込むことで HTTP リクエストを減らせるメリットがある。ただ、バイナリデータより3割ほどデータサイズが増える。</p>

<p>ファイルサイズが小さいアイコンを直接埋め込んだり、ブラウザが PC より対応しているスマートフォンでも使われ出している。ということで、画像のバイナリデータを Base64 にエンコードするツールをつくった。出力形式も HTML の img、CSS、JavaScript、生データに対応。</p>]]>
<![CDATA[<div id="base64image">
<h1>data URI scheme 変換ツール</h1>
<fieldset>
<form method="post" action="http://api.thingslabo.com/base64image/base64image.cgi" enctype="multipart/form-data" target="uploader">
<input type="file" name="image" value=""><br>
<p>gif, jpeg, pngに対応。ファイルサイズは1MBまで。</p>
出力形式 
<label class="inline cursor"><input type="radio" name="output" value="html" checked="checked"> HTML</label>
<label class="inline cursor"><input type="radio" name="output" value="css"> CSS</label>
<label class="inline cursor"><input type="radio" name="output" value="js"> JavaScript</label>
<label class="inline cursor"><input type="radio" name="output" value="row"> 生データ</label>
<br>
<input type="submit" value="base64変換">
</form>
</fieldset>
<fieldset id="uploader">
<iframe name="uploader" src=""></iframe>
</fieldset>
</div>

<p><a href="http://api.thingslabo.com/base64image/" target="_blank">別ウインドウで開く</a></p>


<p>data URI scheme がサポートしている HTML タグは</p>
<ul>
<li>object (images only)</li>
<li>img</li>
<li>input type=image</li>
<li>link</li>
</ul>

<p>CSSでは</p>
<ul>
<li>background-image</li>
<li>background</li>
<li>list-style-type</li>
<li>list-style</li>
</ul>
<p>とURLが設定できるところ。</p>

<p>&lt;data&gt; はサイズに制限があって基本 1,024 bytes まで。実装するブラウザでまちまち。</p>

<p>対応ブラウザは</p>
<ul>
<li>Firefox 2+ (100KB)</li>
<li>Opera 7.2+ (4,100 characters)</li>
<li>Chrome</li>
<li>Safari</li>
<li>IE 8+ (32 KB)</li>
</ul>

<p>一枚の画像にアイコンやボタンを配置してCSSのポジション指定で表示させる CSS Sprite がありますが、画像の HTTP リクエストを減らすもう一つの選択肢として使える。メンテナンス性も CSS Sprite より高そうだ。</p>

<h3>関連サイト</h3>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Data_URI_scheme" target="_blank">Data URI scheme - wikipedia</a></li>
<li><a href="http://tools.ietf.org/html/rfc2397" target="_blank">The "data" URL scheme</a></li>
<li><a href="http://www.darts.jp/reference/rfc/rfc2397-jp.txt" target="_blank">The "data" URL scheme 日本語訳</a></li>
<li><a href="http://www.websiteoptimization.com/speed/tweak/inline-images/" target="_blank">Inline Images with Data URLs</a></li>
</ul>]]>
</content>
</entry>

<entry>
<title>サーバ管理ツール Plesk アップデートエラー対処法</title>
<link rel="alternate" type="text/html" href="http://blog.thingslabo.com/archives/000055.html" />
<modified>2010-10-25T10:20:55Z</modified>
<issued>2010-10-25T06:30:48Z</issued>
<id>tag:blog.thingslabo.com,2010://1.55</id>
<created>2010-10-25T06:30:48Z</created>
<summary type="text/plain">サーバ管理ツールである Parallels Plesk Panel をバージョン...</summary>
<author>
<name></name>

<email>thingsym@gmail.com</email>
</author>
<dc:subject></dc:subject>
<content type="text/html" mode="escaped" xml:lang="ja" xml:base="http://blog.thingslabo.com/">
<![CDATA[<p>サーバ管理ツールである <a href="http://www.parallels.com/products/plesk/">Parallels Plesk Panel</a> をバージョン 8.6.0 から 9.x.x にアップデートすると、管理画面にアクセスできなくなった。届いてるメールは「Plesk autoupdate success report」だけど。</p>

<p>メールの内容をみると、Plesk の起動に失敗している。</p>

<pre class="prettyprint">
Trying to start Plesk... 
Stopping Plesk... done
Starting xinetd service... done
Starting named service... done
Starting mysqld service... done
Starting postgresql service... done
Starting psa-spamassassin service... done
Plesk: Starting Mail Server... already started
Starting Plesk... failed
Starting drwebd service... failed
</pre>

<p>再びサービスを開始しても同じに。</p>

<pre class="prettyprint">
$ /etc/rc.d/init.d/psa start
</pre>

<p>ログをみると、どうやら SSL でエラーになっているようだ。</p>

<ul>
<li><a href="https://atomicorp.com/forums/viewtopic.php?f=3&t=4027" target="_blank">Updated now Plesk won't start.</a></li>
</ul>

<pre class="prettyprint">
$ tail /var/log/sw-cp-server/error_log

2010-10-24 18:44:44: (log.c.75) server started 
2010-10-24 18:50:27: (log.c.135) server stopped 
2010-10-24 18:50:34: (log.c.75) server started 
2010-10-24 18:50:34: (network.c.336) SSL: error:00000000:lib(0):func(0):reason(0) 
2010-10-24 18:50:34: (log.c.75) server started 
2010-10-24 18:50:34: (network.c.336) SSL: error:00000000:lib(0):func(0):reason(0) 
</pre>

<p>対処方法は、<a href="http://kb.parallels.com/8338" target="_blank">Latest update of openssl breaks Parallels Panel</a> を参考にパッケージをインストール。</p>

<pre class="prettyprint">
$ wget -c http://kb.parallels.com/Attachments/12669/Attachments/sw-cp-server-1.0-6.201004011105.centos5.i386.rpm
$ rpm -Uhv sw-cp-server-1.0-6.201004011105.centos5.i386.rpm
$ /etc/rc.d/init.d/psa start

startStarting xinetd service... done
Starting named service... done
Starting mysqld service... done
Starting postgresql service... done
Starting psa-spamassassin service... done
Plesk: Starting Mail Server... already started
Starting Plesk... done
Starting drwebd service... done
</pre>

<p>と無事に Plesk が起動して管理画面にアクセスできるようになった。</p>


<h3>関連サイト</h3>
<ul>
<li><a href="http://www.parallels.com/products/plesk/" target="_blank">Parallels Plesk Panel</a></li>
<li><a href="http://www.parallels.com/products/plesk/demo/" target="_blank">Plesk デモ</a></li>
</ul>]]>

</content>
</entry>

</feed>
