きっかけはWordPressプラグインにしたいわけではなく、はたまた独自ドメインで短縮URLサービスを開きたいわけでもなく、「サイボウズ Office」...これのURLがやたら長くて、メールで送りたいときにOutlookの最大135文字を超える→アクセスできないって言われる→HTMLメールで送ればいいけど...→でもHTMLメールってなんか嫌。
社内に短縮URLシステムあったら便利じゃない?って思って探したのが「YOURLS」です。
OSの準備 とか
VMWare ESXiにCentOS 5.7デフォルト環境にインストールしています。
※インストールディスクはCentOS 5.5。yumで5.7にしています。
Apacheインストール
[root@s ~]# yum install httpd -y
入ったのは「2.2.3-53.el5.centos.3」。
Apacheコンフィグ変更
Rewriteが有効でないといけないので、そこだけ修正。
[root@s html]# vim /etc/httpd/conf/httpd.conf327 #AllowOverride None328 AllowOverride All
PHPインストール
[root@s ~]# yum install php -y
入ったのは「5.1.6-27.el5_7.5」。
MySQLインストール
[root@s ~]# yum install mysql-server mysql -y
クライアントも一緒にインストール。入ったのは「5.0.95-1.el5_7.1」。
php-mysqlインストール
[root@s ~]# yum install php-mysql
入ったのは「5.1.6-27.el5_7.5」。
MySQLコンフィグ修正
UTF-8に対応させる(よくある設定)。
UTF-8に対応させる(よくある設定)。
[root@s ~]# vim /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Default to using old password format for compatibility with mysql 3.x# clients (those using the mysqlclient10 compatibility package).old_passwords=1default-character-set=utf8 //追加character_set_server=utf8 //追加skip-character-set-client-handshake //追加[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid[mysql] //追加default-character-set=utf8 //追加
Apacheを起動
[root@s ~]# /etc/init.d/httpd starthttpd を起動中: [ OK ]
MySQL Serverを起動
[root@s ~]# /etc/init.d/mysqld startMySQL データベースを初期化中: Installing MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr/bin/mysqladmin -u root password 'new-password'/usr/bin/mysqladmin -u root -h s.i2ts.local password 'new-password'Alternatively you can run:/usr/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /usr ; /usr/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/bin/mysqlbug script!The latest information about MySQL is available on the web athttp://www.mysql.comSupport MySQL by buying support/licenses at http://shop.mysql.com[ OK ]MySQL を起動中: [ OK ]
YOURLS用のデータベースを作成
MySQLのパスワード設定してないとか、とりあえず気にしない。
[root@s ~]# mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.0.95 Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> create database yourls;Query OK, 1 row affected (0.00 sec)mysql> \qBye
YOURLSダウンロード
[root@s ~]# wget http://yourls.googlecode.com/files/yourls-1.5.zip
ダウンロードしたファイルの解凍
実はunzipコマンドをはじめてつかっているので、なんか手順が変だけれどあまり気にしない。
[root@s ~]# mkdir yourls[root@s ~]# mv yourls-1.5.zip ./yourls[root@s ~]# cd yourls/[root@s yourls]# unzip yourls-1.5.zip
解凍したディレクトリを、Apacheのディレクトリへ移動。
[root@s yourls]# mv ~/yourls/* /var/www/html/
ファイル所有者をApacheに変更。
[root@s html]# chown -R apache /var/www/html
サンプルをコピーして、config.phpにリネームしてコンフィグファイルを作成。
[root@s html]# cd ./includes/[root@s includes]# cp -p config-sample.php config.php
コンフィグを編集します。
[root@s includes]# vim config.php<?php/* This is a sample config file.* Edit this file with your own settings and save it as "config.php"* You can leave it in the "includes" directory, or, better, move it to* the "user" directory. This way, when a new version of YOURLS is available,* simply delete everything but "/user", and upload the new version.*//*** MySQL settings - You can get this info from your web host*//** MySQL database username */define( 'YOURLS_DB_USER', 'root' ); ←MySQLサーバのログインユーザ/** MySQL database password */define( 'YOURLS_DB_PASS', '' ); ←MySQLサーバのログインパスワード/** The name of the database for YOURLS */define( 'YOURLS_DB_NAME', 'yourls' ); ←先ほど作ったデータベース名/** MySQL hostname */define( 'YOURLS_DB_HOST', 'localhost' ); ←データベースサーバ名。今回はローカルなので「localhost」/** MySQL tables prefix */define( 'YOURLS_DB_PREFIX', 'yourls_' ); ←データベースを共有したりするときに、区別するための頭文字。とりあえずデフォルトのままで。/*** Site options*//** YOURLS installation URL, no trailing slash */define( 'YOURLS_SITE', 'http://s.url.local' ); ←サイトのURL。ここを正しく設定しないと動作しない。/** Timezone GMT offset */define( 'YOURLS_HOURS_OFFSET', 0 );/** Allow multiple short URLs for a same long URL** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */define( 'YOURLS_UNIQUE_URLS', true );/** Private means protected with login/pass as defined below. Set to false for public usage. */define( 'YOURLS_PRIVATE', true ); ←管理画面にパスワードを付けないなら「false」に変更。/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookie **/define( 'YOURLS_COOKIEKEY', 'qQ4KhL_pu|s@Zm7n#%:b^{A[vhm' );/** Username(s) and password(s) allowed to access the site */$yourls_user_passwords = array( ←ここでユーザ名とパスワードを設定する。今回はデフォルトで。'username' => 'password','username2' => 'password2' // You can have one or more 'login'=>'password' lines);/*** URL Shortening settings*//** URL shortening method: 36 or 62 */define( 'YOURLS_URL_CONVERT', 36 );/** 36: generates case insentitive lowercase keywords (ie: 13jkm)* 62: generate case sensitive keywords (ie: 13jKm or 13JKm)* Stick to one setting, don't change after you've created links as it will change all your short URLs!* Base 36 should be picked. Use 62 only if you understand what it implies.*//*** Reserved keywords (so that generated URLs won't match them)* Define here negative, unwanted or potentially misleading keywords.*/$yourls_reserved_URL = array('porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick', 'gay',);/*** Personal settings would go after here.*/
サンプルをコピーして、トップページを作成します。
[root@s html]# cp -p sample-public-front-page.php.txt index.php
YOURLSインストールスクリプト実行
http://s.url.local/ にアクセスすると、自動的に http://s.url.local/admin/install.php にリダイレクトされます。
install YOURLSをクリックします。
.htaccessとMySQLのテーブルが作成されます。
管理画面へログイン
インストール完了画面の[YOURLS Administration Page]をクリックすると、管理画面にいきます。
Username/Passwordはコンフィグで設定したもの。変更していなければは「username/password」です。
ログインすると、すでにちょこっと入ってる。
さっそく使ってみよう!!!
http://s.url.local/ にアクセス
「URL:」に適当なURLを入れて、[Shorten]をクリック(Googleの検索結果などが長くてオススメ)。
その結果、「http://s.url.local/1」というURLが生成されます
これをクリックすると、自動的にリダイレクトされます
プラグイン
Twitterとかで使ってるみたいに、ドメインのあとは数字じゃなくて「hJudjK」みたいな感じじゃないと、なんだかカッコよくない。
なので、PluginRandomKeywordsというプラグインを入れます。
ディレクトリを作成
[root@s plugins]# mkdir /var/www/html/user/plugins/random-keyword
ディレクトリに移動
[root@s plugins]# cd /var/www/html/user/plugins/random-keyword
「plugin.php」というファイルを作成
[root@s random-keyword]# vim plugin.php
下記を貼り付け
<?php/*Plugin Name: Random KeywordsPlugin URI: http://yourls.org/Description: Assign random keywords to shorturls, like bitly (sho.rt/hJudjK)Version: 1.1Author: OzhAuthor URI: http://ozh.org/*//* Release History:** 1.0 Initial release* 1.1 Added: don't increment sequential keyword counter & save one SQL query* Fixed: plugin now complies to character set defined in config.php*/global $ozh_random_keyword;/** CONFIG: EDIT THIS*//* Length of random keyword */$ozh_random_keyword['length'] = 5;/** DO NOT EDIT FARTHER*/// Generate a random keywordyourls_add_filter( 'random_keyword', 'ozh_random_keyword' );function ozh_random_keyword() {global $ozh_random_keyword;return yourls_rnd_string( $ozh_random_keyword['length'] );}// Don't increment sequential keyword trackeryourls_add_filter( 'get_next_decimal', 'ozh_random_keyword_next_decimal' );function ozh_random_keyword_next_decimal( $next ) {return ( $next - 1 );}
YOURS管理画面に戻り、[Plugins]ページに行き、Random Keywordsの[Active]ボタンをクリックします
Activeになります
再度 http://s.url.local/ からURLを入力して、[Shoten]をクリックします
Twitterなどで良く見る感じのアドレスになりました。
オマケ
Apache, MySQLの自動起動
継続して使うなら、自動起動設定に。
[root@s ~]# chkconfig httpd on[root@s ~]# chkconfig mysqld on
Quick Shareの文字化け
Quick Shareと、管理ページの「Stats」を開いたときに、titleが文字化けします。
リンク先ページがUTF-8以外の場合に発生するようです。
ちょこっとソース見てみようとも思いましたが、YOURLS Blogにバグと書いてありますので、今のところどうしようもないと思われますので、あきらめました。
But it still sucks :(All things are not perfect yet and there will be a few bugs to axe. In particular, you may experience a few kinks when YOURLS will be fetching the title of a remote page with funky characters.
YOURLS 1.5 Released (YOURLS Blog)
しかし「funky characters」って...。
DBのスキーマ
シンプル。テーブル3つしかない。
mysql> show tables;++| Tables_in_yourls |++| yourls_log || yourls_options || yourls_url |++3 rows in set (0.00 sec)
各テーブルのカラムも少ない。
mysql> describe yourls_log;+-----+-----+------+-----++-------+| Field | Type | Null | Key | Default | Extra |+-----+-----+------+-----++-------+| click_id | int(11) | NO | PRI | NULL | auto_increment || click_time | datetime | NO | | NULL | || shorturl | varchar(200) | NO | MUL | NULL | || referrer | varchar(200) | NO | | NULL | || user_agent | varchar(255) | NO | | NULL | || ip_address | varchar(41) | NO | | NULL | || country_code | char(2) | NO | | NULL | |+-----+-----+------+-----++-------+7 rows in set (0.00 sec)
mysql> describe yourls_options;+-----+---+------+-----++-------+| Field | Type | Null | Key | Default | Extra |+-----+---+------+-----++-------+| option_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment || option_name | varchar(64) | NO | PRI | | || option_value | longtext | NO | | NULL | |+-----+---+------+-----++-------+3 rows in set (0.00 sec)
mysql> describe yourls_url;+--++------+-----+-+-------+| Field | Type | Null | Key | Default | Extra |+--++------+-----+-+-------+| keyword | varchar(200) | NO | PRI | NULL | || url | text | NO | | NULL | || title | text | YES | | NULL | || timestamp | timestamp | NO | MUL | CURRENT_TIMESTAMP | || ip | varchar(41) | NO | MUL | NULL | || clicks | int(10) unsigned | NO | | NULL | |+--++------+-----+-+-------+6 rows in set (0.00 sec)
でも、仕様を考えるとこんなもんか...。
参考
- YOURLS: Yours Own URL Shortner (Official)
- WordPressプラグインにもなる、短縮URLシステム「YOURLS」(MOONGIFT)
Comment
the corporate-intelligence interests that have insinuated themselves into the school
business and effectively hijacked the future of the American people.
“If you were to talk to anyone who knows me, I think that they would describe first and foremost
my lack of patience and how self-critical I am when I can’t
achieve what we need to achieve,” Griffin said. Step one would be
to take the proper observations using the proper sampling regime or not bother at all.
Sinclair says he called Parisi about the allegations, but Parisi failed to respond.
The child should have the same nap, meals, bath, and
bedtime schedules at both homes.
という事実のため 2007、ルイヴィトンが 大きい その プレゼンス、uWebsite.
Danke.
彼ら 最高 に応えるために、金融 うつ病。チョコレート
プレゼント することができます 生産 で ペア 独特 路。 あなたが得ることができる、組み合わせ バルクの コーチ ハンドバッグ オンライン またとして 近所 アウトレット。
あなた 心の状態 ! 最も背の高いシープスキン ブーツできますのフォールド ダウンされる、追加 リラックスした 見える。 その結果、彼らは 紛れもなく 値
人の時間をする 発見 これら。 アクセス に 3
色: 黒/製品、チョコレート/製品 と海軍/クリーム。
マークジェイコブス 選択. マルク Marc jacobs 上流階級サッチェルです洗練されたデザイナー ハンドバッグ は、任意の服を補完します。 最後 の理論的根拠になります リンク 振る。
ファン お待ちしております、将来 マークジェイコブス 選択。 決して のうち スポット ホーボーと バッグ。 重要な する 意識
の web サイト が 興味をそそら に 閲覧 に。http:
//www.makujieikobusujp.com/
迅速にスポット 通常、 実際の不規則性 として、 だけでなく、渡す 先。 地域に注意してください
完全に は、支払い 制御されていないが表示されます。 シンボルを提供することができます 含む フェイク から、 製品場合 それではない 正しく置きます。
つだけ可能性がありますマーク ・ ジェイコブスと変形する一致タイトル。。現在巻き髪を切ることである制約は詳細は信じられないほど面倒職業。
のエリート現代社会。私は間違いなく ないとなった意識 の悪夢である私は経験豊富な されてジャグリングします。
of the TTF’s budget; New Jersey legislature is considering
a bill to fund these costs. So there you’re kind of isolated that way and you have to go with your gut belief.
Wyman secured help and they proceeded to the Purrinton home, where Capt.
To them, all animal ownership IS animal abuse, and
they have been working overtime to pass ‘animal protection’ laws which allow them to seize and kill healthy, well cared for animals.
Deegan shares driving duties with Todd LeDuc, who was also
on hand for the flag presentation.
suppose you were to write a killer headline? I ain't suggesting your content is not good., however suppose you added something that makes people want more? I mean 短縮URLシステム「YOURLS」インストールメモ - キオクノート is a little plain. You ought to peek at Yahoo's front page and watch
how they create post headlines to grab viewers to click.
You might add a related video or a pic or two to grab readers excited about
everything've got to say. In my opinion, it could bring your website a little bit more interesting.
fresh to the blogosphere. Simple but very accurate information…
Thanks for sharing this one. A must read article!
、web ポータルが非常にユーザーフレンドリー。注意のダイヤモンド、マイルストン、サンドペーパー、花こう岩の表面、コンクリート壁等
コメントする