MySQLでGeoHashを試してみた。以前、Webサイトを構築したときは、Google Map APIを利用して、住所から緯度経度を逆引きしてvarcharで作った列に情報を格納していましたが、あの時にgeohashを知っていたら色々とサービスで使えたかもしれない。。と思い、少し確認してみた。

MEMO:
Geohashは、任意の精度の緯度と経度座標をテキスト文字列にエンコード
Geohash値は、”0123456789bcdefghjkmnpqrstuvwxyz”から選択された文字のみを含む文字列

Geohash

桁数の誤差による差異

変換テーブル

Wiki参照: https://en.wikipedia.org/wiki/Geohash

変換例: xn76g = 11101 10100 00111 00110 01111
左から数え始め、経度は偶数ビット(1110001101011)、緯度は奇数ビット(101100101011)として表現される。二進数は1ビットずつ、左のビットから順に評価されるて、緯度については、-90から+90が2つの区間に分割され、経度は-180から+180の区間に分割される。

確認で利用したMySQLのバージョン

root@localhost [GIS]> select @@version;
+--------------+
| @@version    |
+--------------+
| 8.0.4-rc-log |
+--------------+
1 row in set (0.00 sec)

MySQL8.0のgeohash関連関数
ST_から始まるものが、最新のGEO関数です。

ST_GeoHash(経度,緯度,最大長)、ST_GeoHash(point,max_length)
接続文字セットと照合順序でgeohash文字列を返します。

ST_LatFromGeoHash(geohash_str)
geohash文字列値から[-90、90]の範囲の倍精度数として緯度を返します。

ST_LongFromGeoHash(geohash_str)
geohash文字列値から[-180,180]の範囲の倍精度数値として経度を返します。

ST_PointFromGeoHash(geohash_str、srid)
geohash文字列値を指定して、解読されたgeohash値を含むPOINT値を返します。

root@localhost [GIS]> SELECT ST_GeoHash(180,0,10), ST_GeoHash(-180,-90,15);
+----------------------+-------------------------+
| ST_GeoHash(180,0,10) | ST_GeoHash(-180,-90,15) |
+----------------------+-------------------------+
| xbpbpbpbpb           | 000000000000000         |
+----------------------+-------------------------+
1 row in set (0.01 sec)

root@localhost [GIS]>  SELECT ST_LatFromGeoHash(ST_GeoHash(45,-20,10));
+------------------------------------------+
| ST_LatFromGeoHash(ST_GeoHash(45,-20,10)) |
+------------------------------------------+
|                                      -20 |
+------------------------------------------+
1 row in set (0.00 sec)

root@localhost [GIS]> SELECT ST_LongFromGeoHash(ST_GeoHash(45,-20,10));
+-------------------------------------------+
| ST_LongFromGeoHash(ST_GeoHash(45,-20,10)) |
+-------------------------------------------+
|                                        45 |
+-------------------------------------------+
1 row in set (0.00 sec)

root@localhost [GIS]> SET @gh = ST_GeoHash(45,-20,10);
Query OK, 0 rows affected (0.00 sec)

root@localhost [GIS]> SELECT ST_AsText(ST_PointFromGeoHash(@gh,0));
+---------------------------------------+
| ST_AsText(ST_PointFromGeoHash(@gh,0)) |
+---------------------------------------+
| POINT(45 -20)                         |
+---------------------------------------+
1 row in set (0.00 sec)

root@localhost [GIS]> 

実際にGoogle Mapを利用して確認
オラクル青山オフィスのgeohash(5桁:xn76g)を利用してレストランを検索。
データをImport後に、緯度-経度を読み込んで確認してみる。

検証用のデータはこちらからダウンロード可能です。
Download OpenStreetMap data for this region:Japan
http://download.geofabrik.de/asia/japan.html
Download OpenStreetMap data for this region:Asia
http://download.geofabrik.de/asia.html

インポート方法はこちらが参考になります。
MySQL 5.7 and GIS, an Example
https://mysqlserverteam.com/mysql-5-7-and-gis-an-example/

検証データと結果の確認

root@localhost [GIS]> select nodetags.v as 'name',st_latfromgeohash(st_geohash((nodes.geom),8)) as 'lat', st_longfromgeohash(st_geohash((nodes.geom),8)) as 'lng','restaurant' as 'type'  FROM nodes,nodetags WHERE nodes.id = nodetags.id and match(tags)  against ('+restaurant' IN BOOLEAN MODE) and nodetags.k='name' and nodes.GeoHash5 = 'xn76g' limit 10;
+--------------------------------------------+---------+----------+------------+
| name                                       | lat     | lng      | type       |
+--------------------------------------------+---------+----------+------------+
| 雅山 (Gazan)                               | 35.6603 | 139.7397 | restaurant |
| とんかつ まい泉                            |  35.668 | 139.7116 | restaurant |
| 粥 「喜喜」                                | 35.6727 | 139.7126 | restaurant |
| ヘンドリックス・カリー・バー               |  35.675 | 139.7126 | restaurant |
| えさき (Esaki)                             | 35.6717 | 139.7133 | restaurant |
| Cardenas/charcoal grill                    | 35.6478 | 139.7075 | restaurant |
| ROYAL PALACE                               | 35.6475 |  139.707 | restaurant |
| 長崎ちゃんぽんリンガーハット               | 35.6478 |  139.746 | restaurant |
| 増田屋 (Masudaya)                          | 35.6705 | 139.7136 | restaurant |
| Las Chicas                                 | 35.6634 |  139.708 | restaurant |
+--------------------------------------------+---------+----------+------------+
10 rows in set (0.04 sec)

PHPにSQLをコピーしてGoogle Map APIに渡して、地図を確認してみると、問題なく、同じGeohashにあるレストランが表示されているようです。
インデックスを併用すれば、結構レスポンスの良い空間データベースになりそうです。

上記処理を実行した時の、MySQLで実行プランは以下のような感じです

以上で確認は終了ですが、ついでにSRIDを指定してテーブルを作成する事が出来るようになっていたので確認してみた。
緯度-経度の順番でINSERTする場合は、列にSRIDを指定して作成した方が良いようです。
反対に経度-緯度の場合はDefaultの0のままで良い。データINSERT時に緯度と経度の順番のバリデーションが無いのであった方がよさそうです。

root@localhost [GIS]> CREATE TABLE geom (
    ->     p POINT NOT NULL SRID 0,
    ->     g GEOMETRY NOT NULL SRID 4326,
    ->     GeoHash5 varchar(5) GENERATED ALWAYS AS (st_geohash(`g`,5)) VIRTUAL,
    ->     GeoHash8 varchar(8) GENERATED ALWAYS AS (st_geohash(`g`,8)) VIRTUAL
    -> );

root@localhost [GIS]> INSERT INTO geom(p,g) VALUES(ST_GeomFromText('POINT(139.718695 35.671482)'),ST_GeomFromText('POINT(35.671482 139.718695)',4326));
Query OK, 1 row affected (0.00 sec)

root@localhost [GIS]> select * from geom;
+---------------------------+---------------------------+----------+----------+
| p                         | g                         | GeoHash5 | GeoHash8 |
+-------- @$----------------+ @$------------------------+----------+----------+
|           A@        |         A@         | xn76g    | xn76gmu1 |
+---------------------------+---------------------------+----------+----------+
1 row in set (0.00 sec)

root@localhost [GIS]> select st_geohash(p,8),st_geohash(g,8),GeoHash5,GeoHash8 from geom;
+-----------------+-----------------+----------+----------+
| st_geohash(p,8) | st_geohash(g,8) | GeoHash5 | GeoHash8 |
+-----------------+-----------------+----------+----------+
| xn76gmu1        | xn76gmu1        | xn76g    | xn76gmu1 |
+-----------------+-----------------+----------+----------+
1 row in set (0.00 sec)

root@localhost [GIS]> select 'xn76g' as 'geohash',st_latfromgeohash('xn76g') as '緯度',st_longfromgeohash('xn76g') as '経度';
+---------+--------+--------+
| geohash | 緯度   | 経度   |
+---------+--------+--------+
| xn76g   |  35.66 | 139.72 |
+---------+--------+--------+
1 row in set (0.01 sec)


参照:
12.15.10 Spatial Geohash Functions
https://dev.mysql.com/doc/refman/8.0/en/spatial-geohash-functions.html

geohash.org
http://geohash.org/


APACHEとPHPのアップグレード
Apache HTTP Server 2.4.3が出ていたので,Apacheのアップグレード対応しようと思いましたが、
2.2.xxの方が安定してそうだったので2.2.22でアップグレード。
——————–

[root@aws bin]# /usr/local/apache2/bin/httpd -v
Server version: Apache/2.2.22 (Unix)
Server built:   Sep  8 2012 22:42:21
[root@aws bin]# /usr/local/bin/php -v
PHP 5.4.6 (cli) (built: Sep  9 2012 00:34:45)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
[root@aws bin]#

—————————————————————
apacheインストール
Apache HTTP Server 2.2.22 (httpd)
http://httpd.apache.org/download.cgi#apache24
—————————————————————

apacheのダウンロード

[root@aws src]# <code>wget http://ftp.kddilabs.jp/infosystems/apache//httpd/httpd-2.2.22.tar.gz
--2012-09-08 22:33:01--  http://ftp.kddilabs.jp/infosystems/apache//httpd/httpd-2.2.22.tar.gz
Resolving ftp.kddilabs.jp... 192.26.91.193, 2001:200:601:10:206:5bff:fef0:466c
Connecting to ftp.kddilabs.jp|192.26.91.193|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7200529 (6.9M) [application/x-gzip]
Saving to: “httpd-2.2.22.tar.gz”

100%[=========================================================>] 7,200,529   3.59M/s   in 1.9s

2012-09-08 22:33:03 (3.59 MB/s) - “httpd-2.2.22.tar.gz” saved [7200529/7200529]
</code>
[root@aws src]#


[root@aws src]# ls -l
total 377160
-rw-r--r-- 1 root     root       7200529 Jan 30  2012 httpd-2.2.22.tar.gz
-rw-r--r-- 1 root     root       6137268 Aug 20 13:22 httpd-2.4.3.tar.gz
-rw-rw-r-- 1 ec2-user ec2-user 186355822 Jul  6 23:07 mysql-5.5.25a-linux2.6-x86_64.tar.gz
-rw-rw-r-- 1 ec2-user ec2-user 186504948 Aug 26 11:37 mysql-5.5.27-linux2.6-x86_64.tar.gz
[root@aws src]#


<strong>apache tarの展開</strong>
[root@aws src]# tar xzvf httpd-2.2.22.tar.gz
httpd-2.2.22/
httpd-2.2.22/emacs-style
httpd-2.2.22/httpd.dsp
httpd-2.2.22/libhttpd.dsp
httpd-2.2.22/.deps
httpd-2.2.22/Makefile.in
httpd-2.2.22/include/
httpd-2.2.22/include/scoreboard.h
httpd-2.2.22/include/ap_regkey.h
httpd-2.2.22/include/ap_compat.h
httpd-2.2.22/include/http_config.h
httpd-2.2.22/include/util_time.h
httpd-2.2.22/include/ap_mmn.h

[省略]

httpd-2.2.22/libhttpd.dep
httpd-2.2.22/configure.in
httpd-2.2.22/VERSIONING
httpd-2.2.22/README
httpd-2.2.22/LAYOUT
httpd-2.2.22/buildconf
httpd-2.2.22/.gdbinit
[root@aws src]#


[root@aws src]# ls -l
total 377164
drwxr-xr-x 11      500 ec2-user      4096 Jan 25  2012 httpd-2.2.22
-rw-r--r--  1 root     root       7200529 Jan 30  2012 httpd-2.2.22.tar.gz
-rw-r--r--  1 root     root       6137268 Aug 20 13:22 httpd-2.4.3.tar.gz
-rw-rw-r--  1 ec2-user ec2-user 186355822 Jul  6 23:07 mysql-5.5.25a-linux2.6-x86_64.tar.gz
-rw-rw-r--  1 ec2-user ec2-user 186504948 Aug 26 11:37 mysql-5.5.27-linux2.6-x86_64.tar.gz
[root@aws src]#

展開したApacheのconfigureとmake

[root@aws src]# cd httpd-2.2.22
[root@aws httpd-2.2.22]# pwd
/usr/local/src/httpd-2.2.22
[root@aws httpd-2.2.22]#

—————————————————————
■基本コンフィグでconfigureを実行
—————————————————————

<code>
./configure \
--enable-rewrite --enable-expires --enable-so \
--prefix=/usr/local/httpd-2_2_22
</code>

—————————————————————

[root@aws httpd-2.2.22]# ./configure \
> --enable-rewrite --enable-expires --enable-so \
> --prefix=/usr/local/httpd-2_2_22
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
Configuring Apache Portable Runtime library ...

checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to "  -pthread"
  setting CPPFLAGS to " -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "

Configuring Apache Portable Runtime Utility library...

checking for APR-util... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no

[省略]

config.status: creating docs/conf/extra/httpd-vhosts.conf
config.status: creating include/ap_config_layout.h
config.status: creating support/apxs
config.status: creating support/apachectl
config.status: creating support/dbmmanage
config.status: creating support/envvars-std
config.status: creating support/log_server_status
config.status: creating support/logresolve.pl
config.status: creating support/phf_abuse_log.cgi
config.status: creating support/split-logfile
config.status: creating build/rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
[root@aws httpd-2.2.22]#

[root@aws httpd-2.2.22]# make
Making all in srclib
make[1]: Entering directory `/usr/local/src/httpd-2.2.22/srclib'
Making all in pcre
make[2]: Entering directory `/usr/local/src/httpd-2.2.22/srclib/pcre'
make[3]: Entering directory `/usr/local/src/httpd-2.2.22/srclib/pcre'

[省略]

make[1]: Leaving directory `/usr/local/src/httpd-2.2.22'
[root@aws httpd-2.2.22]#


[root@aws httpd-2.2.22]# ls -l /usr/local/
total 48
drwxr-xr-x  2 root  root  4096 May 27 09:00 bin
drwxr-xr-x  2 root  root  4096 Jan  6  2012 etc
drwxr-xr-x  2 root  root  4096 Jan  6  2012 games
drwxr-xr-x  3 root  root  4096 May 27 09:00 include
drwxr-xr-x  2 root  root  4096 May 26 23:12 lib
drwxr-xr-x  3 root  root  4096 Mar 24 17:06 lib64
drwxr-xr-x  2 root  root  4096 Jan  6  2012 libexec
lrwxrwxrwx  1 root  root    39 Aug 26 12:09 mysql -> /usr/local/mysql-5.5.27-linux2.6-x86_64
drwxrwxr-x 13 mysql mysql 4096 Jul  7 04:44 mysql-5.5.25a-linux2.6-x86_64
drwxr-xr-x 14 mysql mysql 4096 Aug 26 12:09 mysql-5.5.27-linux2.6-x86_64
drwxr-xr-x  2 root  root  4096 Jan  6  2012 sbin
drwxr-xr-x  6 root  root  4096 Mar 24 17:06 share
drwxr-xr-x  3 root  root  4096 Sep  8 22:35 src
[root@aws httpd-2.2.22]# 


[root@aws httpd-2.2.22]# make install
Making install in srclib
make[1]: Entering directory `/usr/local/src/httpd-2.2.22/srclib'
Making install in pcre
make[2]: Entering directory `/usr/local/src/httpd-2.2.22/srclib/pcre'
make[3]: Entering directory `/usr/local/src/httpd-2.2.22/srclib/pcre'
make[3]: Leaving directory `/usr/local/src/httpd-2.2.22/srclib/pcre'
make[2]: Leaving directory `/usr/local/src/httpd-2.2.22/srclib/pcre'
make[2]: Entering directory `/usr/local/src/httpd-2.2.22/srclib'
make[2]: Leaving directory `/usr/local/src/httpd-2.2.22/srclib'
make[1]: Leaving directory `/usr/local/src/httpd-2.2.22/srclib'

[省略]

mkdir /usr/local/httpd-2_2_22/build
Installing man pages and online manual
mkdir /usr/local/httpd-2_2_22/man
mkdir /usr/local/httpd-2_2_22/man/man1
mkdir /usr/local/httpd-2_2_22/man/man8
mkdir /usr/local/httpd-2_2_22/manual
make[1]: Leaving directory `/usr/local/src/httpd-2.2.22'
[root@aws httpd-2.2.22]# 



[root@aws httpd-2.2.22]# ls -l /usr/local/
total 52
drwxr-xr-x  2 root  root  4096 May 27 09:00 bin
drwxr-xr-x  2 root  root  4096 Jan  6  2012 etc
drwxr-xr-x  2 root  root  4096 Jan  6  2012 games
drwxr-xr-x 14 root  root  4096 Sep  8 22:44 httpd-2_2_22
drwxr-xr-x  3 root  root  4096 May 27 09:00 include
drwxr-xr-x  2 root  root  4096 May 26 23:12 lib
drwxr-xr-x  3 root  root  4096 Mar 24 17:06 lib64
drwxr-xr-x  2 root  root  4096 Jan  6  2012 libexec
lrwxrwxrwx  1 root  root    39 Aug 26 12:09 mysql -> /usr/local/mysql-5.5.27-linux2.6-x86_64
drwxrwxr-x 13 mysql mysql 4096 Jul  7 04:44 mysql-5.5.25a-linux2.6-x86_64
drwxr-xr-x 14 mysql mysql 4096 Aug 26 12:09 mysql-5.5.27-linux2.6-x86_64
drwxr-xr-x  2 root  root  4096 Jan  6  2012 sbin
drwxr-xr-x  6 root  root  4096 Mar 24 17:06 share
drwxr-xr-x  3 root  root  4096 Sep  8 22:35 src
[root@aws httpd-2.2.22]#

インストール後にシンボリックリンク作成
後でバージョンアップや切戻しを楽にするた為。

[root@aws local]# ln -s /usr/local/httpd-2_2_22 /usr/local/apache2
[root@aws local]# ls -l
total 52
lrwxrwxrwx  1 root  root    23 Sep  8 22:47 apache2 -> /usr/local/httpd-2_2_22
drwxr-xr-x  2 root  root  4096 May 27 09:00 bin
drwxr-xr-x  2 root  root  4096 Jan  6  2012 etc
drwxr-xr-x  2 root  root  4096 Jan  6  2012 games
drwxr-xr-x 14 root  root  4096 Sep  8 22:44 httpd-2_2_22
drwxr-xr-x  3 root  root  4096 May 27 09:00 include
drwxr-xr-x  2 root  root  4096 May 26 23:12 lib
drwxr-xr-x  3 root  root  4096 Mar 24 17:06 lib64
drwxr-xr-x  2 root  root  4096 Jan  6  2012 libexec
lrwxrwxrwx  1 root  root    39 Aug 26 12:09 mysql -> /usr/local/mysql-5.5.27-linux2.6-x86_64
drwxrwxr-x 13 mysql mysql 4096 Jul  7 04:44 mysql-5.5.25a-linux2.6-x86_64
drwxr-xr-x 14 mysql mysql 4096 Aug 26 12:09 mysql-5.5.27-linux2.6-x86_64
drwxr-xr-x  2 root  root  4096 Jan  6  2012 sbin
drwxr-xr-x  6 root  root  4096 Mar 24 17:06 share
drwxr-xr-x  3 root  root  4096 Sep  8 22:35 src
[root@aws local]#

symbolic

アカウントは既に作成済み

[root@aws local]# cat /etc/passwd | grep apache2
apache:x:558:558:Apache:/usr/local/apache2:/sbin/nologin
[root@aws local]#

※フォルダー権限等も既に設定済み。

init.dの変更・作成

----------------------------------------------------------------------------------------
[root@aws local]# vi /etc/init.d/httpd2
[root@aws local]# chmod 755 /etc/init.d/httpd2
----------------------------------------------------------------------------------------
[BASH]
#!/bin/bash
#
# Startup script for Apache Web Server
#
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server. It is used to serve \
#     HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/usr/bin:/bin
CMDPATH=/usr/local/apache2/bin/
CMD=apachectl

test -f $CMDPATH$CMD || exit 0

start()
{
    echo -n "Starting httpd ... "
    $CMDPATH$CMD start
    echo "done."
}

stop()
{
    echo -n "Stopping httpd ... "
    $CMDPATH$CMD stop
    echo "done."
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|force-reload)
        stop
        sleep 2
        start
        ;;
    *)
        echo "Usage: /etc/rc.d/init.d/rc.httpd2 {start|stop|restart}"
        exit 1
        ;;
esac

exit 0
[/BASH]
----------------------------------------------------------------------------------------

[root@aws local]# ls -l /etc/init.d/httpd2
-rwxr-xr-x 1 root root 870 Sep  8 23:00 /etc/init.d/httpd2
[root@aws local]#

<strong>OS起動時の自動起動設定</strong>
[root@aws local]# /sbin/chkconfig httpd2 on
[root@aws local]# /sbin/chkconfig --list httpd2
httpd2          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@aws local]#

PHPインストール・バージョンアップ
—————————————————————————————-
■PHPインストール php-5.4.6.tar.gz 13,964,954 bytes
http://jp.php.net/get/php-5.4.6.tar.gz/from/a/mirror
—————————————————————————————-

 <code>./configure \
--prefix=/usr/local/php-5.4.6 --with-config-file-path=/etc \
--with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql \
--enable-sockets</code>

—————————————————————————————-

[root@aws php-5.4.6]#  ./configure \
> --prefix=/usr/local/php-5.4.6 --with-config-file-path=/etc \
> --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql \
> --enable-sockets
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for cc... cc

[省略]

Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating main/php_config.h
config.status: executing default commands
[root@aws php-5.4.6]#

メモ:PHPインストール時にエラーが出たので依存関係解決
—————————————————————————————-
[root@aws php-5.4.6]# yum install libxml2
[root@aws php-5.4.6]# yum install libxml2-devel
—————————————————————————————-

[root@aws php-5.4.6]# make install
Installing PHP SAPI module:       apache2handler
/usr/local/httpd-2_2_22/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp5.la /usr/local/httpd-2_2_22/modules
/usr/lib64/apr-1/build/libtool --mode=install cp libphp5.la /usr/local/httpd-2_2_22/modules/
libtool: install: cp .libs/libphp5.so /usr/local/httpd-2_2_22/modules/libphp5.so
libtool: install: cp .libs/libphp5.lai /usr/local/httpd-2_2_22/modules/libphp5.la
libtool: install: warning: remember to run `libtool --finish /usr/local/src/php-5.4.6/libs'
chmod 755 /usr/local/httpd-2_2_22/modules/libphp5.so
[activating module `php5' in /usr/local/httpd-2_2_22/conf/httpd.conf]
Installing PHP CLI binary:        /usr/local/php-5.4.6/bin/
Installing PHP CLI man page:      /usr/local/php-5.4.6/php/man/man1/
Installing PHP CGI binary:        /usr/local/php-5.4.6/bin/
Installing build environment:     /usr/local/php-5.4.6/lib/php/build/
Installing header files:          /usr/local/php-5.4.6/include/php/
Installing helper programs:       /usr/local/php-5.4.6/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php-5.4.6/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php-5.4.6/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.7
[PEAR] Console_Getopt - installed: 1.3.0
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util       - installed: 1.2.1
[PEAR] PEAR           - installed: 1.9.4

/usr/local/src/php-5.4.6/build/shtool install -c ext/phar/phar.phar /usr/local/php-5.4.6/bin
ln -s -f /usr/local/php-5.4.6/bin/phar.phar /usr/local/php-5.4.6/bin/phar
Installing PDO headers:          /usr/local/php-5.4.6/include/php/ext/pdo/
[root@aws php-5.4.6]#

[root@aws local]# <code>ln -sfn /usr/local/php-5.4.6/bin/php /usr/local/bin/php</code>
[root@aws local]# <code>ln -sfn /usr/local/php-5.4.6/bin/php-config /usr/local/bin/php-config</code>
[root@aws local]# <code>ln -sfn /usr/local/php-5.4.6/bin/phpize /usr/local/bin/phpize</code>
[root@aws local]# <code>ln -sfn /usr/local/php-5.4.6/lib/php /usr/local/lib/php</code>

<a href="http://variable.jp/wp-content/uploads/2012/09/php-symbolic.jpg"><img src="http://variable.jp/wp-content/uploads/2012/09/php-symbolic.jpg" alt="PHP" title="php-symbolic" width="633" height="256" /></a>


<strong>php.iniの設定変更(セキュリティ・MYSQL Socket調整)</strong>
[root@aws local]# cp -rp /usr/local/src/php-5.4.6/php.ini-production /etc/php.ini
[root@aws local]# vi /etc/php.ini
[root@aws local]# cat /etc/php.ini | egrep -i "expose_php|mysql.default_socket"
; expose_php = On
expose_php = Off
pdo_mysql.default_socket=
;mysql.default_socket =
mysql.default_socket = /usr/local/mysql/data/mysql.sock
[root@aws local]#

—————————————————————————————-
PHP設定メモ:
—————————————————————————————-
register_globals
http://php.net/manual/ja/ini.core.php
この機能は PHP 5.3.0 で 非推奨となり、 PHP 5.4.0 で削除されました。
register_globals は、 variables_order ディレクティブの影響を受けます。
—————————————————————————————-

—————————————————————————————-
LoadModules,Rewriteを利用する為にFollowSymLinksとAllowOverrideを設定
—————————————————————————————-

[root@aws conf]# cat httpd.conf | egrep -i "php|Options"
LoadModule php5_module modules/libphp5.so
    # Options Indexes FollowSymLinks
    Options FollowSymLinks
    DirectoryIndex index.php
    AddType application/x-httpd-php .php
[root@aws conf]#


[root@aws local]# /etc/init.d/httpd2 restart
Stopping httpd ... done.
Starting httpd ... done.
[root@aws local]#

コンパイルしたファイルをCacheして、phpの動作を速くする
APC(Alternative PHP Cache)。
IISでコンパイル済みASP、ASPX等をCacheするのと同じような設定という認識。

http://php.net/manual/ja/book.apc.php

[root@ip-xxxxxxxxx ec2-user]# yum install php-pear php-devel http-devel
Loaded plugins: fastestmirror, priorities, security, update-motd
Loading mirror speeds from cached hostfile
* amzn-main: packages.ap-northeast-1.amazonaws.com
* amzn-updates: packages.ap-northeast-1.amazonaws.com
Setting up Install Process
No package http-devel available.
Resolving Dependencies
–> Running transaction check
—> Package php-devel.x86_64 0:5.3.10-1.18.amzn1 will be installed
–> Processing Dependency: autoconf for package: php-devel-5.3.10-1.18.amzn1.x86_64
–> Processing Dependency: automake for package: php-devel-5.3.10-1.18.amzn1.x86_64
—> Package php-pear.noarch 1:1.9.4-4.8.amzn1 will be installed
–> Running transaction check
—> Package autoconf.noarch 0:2.63-5.1.7.amzn1 will be installed
—> Package automake.noarch 0:1.11.1-2.9.amzn1 will be installed
–> Finished Dependency Resolution

その他、gcc,make,PHP dev,apache dev,pcre,apxs関係など
不足していたパッケージインストール。

[root@ip-xxxxxxxxx ec2-user]# pecl install APC
downloading APC-3.1.9.tgz …
Starting to download APC-3.1.9.tgz (155,540 bytes)
……………………………done: 155,540 bytes
54 source files, building
running: phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
config.m4:180: warning: AC_CACHE_VAL(PHP_APC_GCC_ATOMICS, …): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from…
../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from…
config.m4:180: the top level
config.m4:180: warning: AC_CACHE_VAL(PHP_APC_GCC_ATOMICS, …): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from…
../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from…
config.m4:180: the top level
Enable internal debugging in APC [no] :
Enable per request file info about files used from the APC cache [no] :
Enable spin locks (EXPERIMENTAL) [no] :
Enable memory protection (EXPERIMENTAL) [no] :
Enable pthread mutexes (default) [yes] :
Enable pthread read/write locks (EXPERIMENTAL) [no] :
building in /var/tmp/pear-build-rootBND1Ww/APC-3.1.9

…… 省略

Build process completed successfully
Installing ‘/usr/lib64/php/modules/apc.so’
Installing ‘/usr/include/php/ext/apc/apc_serializer.h’
install ok: channel://pecl.php.net/APC-3.1.9
configuration option “php_ini” is not set to php.ini location
You should add “extension=apc.so” to php.ini

[root@ip-xxxxxxxxx ec2-user]# echo “extension=apc.so” > /etc/php.d/apc.ini
[root@ip-xxxxxxxxx ec2-user]# pecl list
Installed packages, channel pecl.php.net:
=========================================
Package Version State
APC 3.1.9 stable
[root@ip-xxxxxxxxx ec2-user]#

[root@ip-xxxxxxxxx ec2-user]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@ip-xxxxxxxxx ec2-user]#

APCの状況確認用ページ 「httpでアクセス出来るところにコピー」
[root@ip-xxxxxxxxx ec2-user]# ls -l /usr/share/pear/apc.php
-rw-r–r– 1 root root 46148 Apr 7 09:17 /usr/share/pear/apc.php
[root@ip-xxxxxxxxx ec2-user]#

APC

APC

[ec2-user@ip-xxxxxxxxx ec2-user]$ php -i | grep apc
Additional .ini files parsed => /etc/php.d/apc.ini,
apc
apc.cache_by_default => On => On
apc.canonicalize => On => On
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
apc.enabled => On => On
apc.file_md5 => Off => Off
apc.file_update_protection => 2 => 2
apc.filters => no value => no value
apc.gc_ttl => 3600 => 3600
apc.include_once_override => Off => Off
apc.lazy_classes => Off => Off
apc.lazy_functions => Off => Off
apc.max_file_size => 1M => 1M
apc.mmap_file_mask => no value => no value
apc.num_files_hint => 1000 => 1000
apc.preload_path => no value => no value
apc.report_autofilter => Off => Off
apc.rfc1867 => Off => Off
apc.rfc1867_freq => 0 => 0
apc.rfc1867_name => APC_UPLOAD_PROGRESS => APC_UPLOAD_PROGRESS
apc.rfc1867_prefix => upload_ => upload_
apc.rfc1867_ttl => 3600 => 3600
apc.serializer => default => default
apc.shm_segments => 1 => 1
apc.shm_size => 32M => 32M
apc.slam_defense => On => On
apc.stat => On => On
apc.stat_ctime => Off => Off
apc.ttl => 0 => 0
apc.use_request_time => On => On
apc.user_entries_hint => 4096 => 4096
apc.user_ttl => 0 => 0
apc.write_lock => On => On
[ec2-user@ip-xxxxxxxxx ec2-user]$


PHPでフレームワークのsymfonyを利用する事になったので,とりあえず家で予習です。

とりあえず,インストールしてみました。

[root@localhost bin]# ls
pear  peardev  pecl  php  php-config  phpize

[root@localhost bin]# ./pear channel-discover pear.symfony-project.com
Adding Channel “pear.symfony-project.com” succeeded
Discovery of channel “pear.symfony-project.com” succeeded

[root@localhost bin]# ./pear install symfony/symfony
downloading symfony-1.0.8.tgz …
Starting to download symfony-1.0.8.tgz (1,908,095 bytes)
……………………..done: 1,908,095 bytes
install ok: channel://pear.symfony-project.com/symfony-1.0.8
[root@localhost bin]#

[root@localhost bin]# ls
pear  peardev  pecl  php  php-config  phpize  symfony
[root@localhost bin]#

[root@localhost bin]# ./symfony -V
symfony version 1.0.8
[root@localhost bin]#

symfony.jpg


画像やEXIFを利用したサイトを利用したいので,PHPのインストールオプションを以下のように設定

してインストールしてみた。モジュールが足りないやオプションを間違えている等の部分はあったが

結果的にはインストール出来たので忘れないように,備忘録に記入。

 

=================画像系のライブラリーを扱う為の事前準備==================

[root@localhost ~]# yum -y install flex libxml2-devel
Loading “installonlyn” plugin
Setting up Install Process
Setting up repositories
base                      100% |=========================| 1.1 kB    00:00
updates                   100% |=========================|  951 B    00:00
addons                    100% |=========================|  951 B    00:00
extras                    100% |=========================| 1.1 kB    00:00
Reading repository metadata in from local files
primary.xml.gz            100% |=========================| 315 kB    00:00
updates   : ################################################## 723/723
Added 4 new packages, deleted 0 old in 3.93 seconds
Parsing package install arguments
Nothing to do
[root@localhost ~]# yum -y install zlib-devel libpng-devel
Loading “installonlyn” plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
–> Populating transaction set with selected packages. Please wait.
—> Downloading header for libpng-devel to pack into transaction set.
libpng-devel-1.2.10-7.0.2 100% |=========================|  11 kB    00:00
—> Package libpng-devel.i386 2:1.2.10-7.0.2 set to be updated
–> Running transaction check
–> Processing Dependency: libpng = 2:1.2.10-7.0.2 for package: libpng-devel
–> Restarting Dependency Resolution with new changes.
–> Populating transaction set with selected packages. Please wait.
—> Downloading header for libpng to pack into transaction set.
libpng-1.2.10-7.0.2.i386. 100% |=========================|  11 kB    00:00
—> Package libpng.i386 2:1.2.10-7.0.2 set to be updated
–> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 libpng-devel            i386       2:1.2.10-7.0.2   updates           182 k
Updating for dependencies:
 libpng                  i386       2:1.2.10-7.0.2   updates           241 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       1 Package(s)
Remove       0 Package(s)

Total download size: 423 k
Downloading Packages:
(1/2): libpng-devel-1.2.1 100% |=========================| 182 kB    00:00
(2/2): libpng-1.2.10-7.0. 100% |=========================| 241 kB    00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating  : libpng                       ######################### [1/3]
  Installing: libpng-devel                 ######################### [2/3]
  Cleanup   : libpng                       ######################### [3/3]

Installed: libpng-devel.i386 2:1.2.10-7.0.2
Dependency Updated: libpng.i386 2:1.2.10-7.0.2
Complete!
[root@localhost ~]# yum -y install libjpeg-devel
Loading “installonlyn” plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
–> Populating transaction set with selected packages. Please wait.
—> Downloading header for libjpeg-devel to pack into transaction set.
libjpeg-devel-6b-37.i386. 100% |=========================| 6.3 kB    00:00
—> Package libjpeg-devel.i386 0:6b-37 set to be updated
–> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 libjpeg-devel           i386       6b-37            base              105 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 105 k
Downloading Packages:
(1/1): libjpeg-devel-6b-3 100% |=========================| 105 kB    00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: libjpeg-devel                ######################### [1/1]

Installed: libjpeg-devel.i386 0:6b-37
Complete!
[root@localhost ~]#

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ls
[root@localhost src]# wget http://jp.php.net/get/php-5.2.4.tar.gz/from/this/mirror
–01:00:34–  http://jp.php.net/get/php-5.2.4.tar.gz/from/this/mirror
jp.php.net をDNSに問いあわせています… 61.195.146.164
jp.php.net|61.195.146.164|:80 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています… 302 Found
場所: http://jp.php.net/distributions/php-5.2.4.tar.gz [続く]
–01:00:34–  http://jp.php.net/distributions/php-5.2.4.tar.gz
jp.php.net|61.195.146.164|:80 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています… 200 OK
長さ: 9705468 (9.3M) [application/x-gzip]
Saving to: `php-5.2.4.tar.gz’

100%[============================================================================>] 9,705,468   4.47M/s   in 2.1s

01:00:37 (4.47 MB/s) – `php-5.2.4.tar.gz’ を保存しました [9705468/9705468]

[root@localhost src]#

[root@localhost src]# tar -xzvf php-5.2.4.tar.gz

 

[root@localhost php-5.2.4]# ./configure \
>  –prefix=/usr/local/php-5.2.4 \
>  –with-apxs2=/usr/local/apache2/bin/apxs \
>  –with-config-file-path=/usr/local/php-5.2.4/lib/ \
>  –with-gd \
>  –with-jpeg-dir=/usr/local \
>  –with-png-dir=/usr/local \
>  –with-gd \
>  –with-zlib \
>  –with-zlib-dir=/usr/local \
>  –with-xml \
>  –with-openssl \
>  –with-config-file-path=/etc \
>  –with-libmbfl \
>  –with-mcrypt \
>  –with-mime-magic \
>  –with-mysql \
>  –enable-pcntl \
>  –enable-trans-sid \
>  –enable-zend-multibyte \
>  –enable-mbstr-enc-trans \
>  –enable-mbstring \
>  –enable-mbregex \
>  –enable-gd-native-ttf \
>  –enable-gd-jis-conv \
>  –enable-exif
creating cache ./config.cache
checking for Cygwin environment… no
checking for mingw32 environment… no
checking for egrep… grep -E
checking for a sed that does not truncate output… /bin/sed
checking host system type…

 

===================その他オプションメモ書き===================

–enable-module=all
モジュールをすべて有効に
–enable-shared=max
DSO(Dynamic Shared Object)のサポート。PHPをインストールする際に必要
–with-apxs=/usr/local/apache/bin/apxs
DSOを利用するために、apxsコマンドのパスを指定
–with-mysql
PHPからMySQLを操作するための指定。MySQLを/usr/localや/usrなどではない場所に
インストールしている場合は、パスの指定が必要(例:–with-mysql=/home/mysql)

=========================================================

configure: error: mcrypt.h not found. Please reinstall libmcrypt. <——- libmcryptが無い!!
[root@localhost php-5.2.4]#
[root@localhost php-5.2.4]# yum install libmcrypt
Loading “installonlyn” plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
–> Populating transaction set with selected packages. Please wait.
—> Downloading header for libmcrypt to pack into transaction set.
libmcrypt-2.5.7-5.el5.cen 100% |=========================| 3.8 kB    00:00
—> Package libmcrypt.i386 0:2.5.7-5.el5.centos set to be updated
–> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 libmcrypt               i386       2.5.7-5.el5.centos  extras            123 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 123 k
Is this ok [y/N]: y
Downloading Packages:
(1/1): libmcrypt-2.5.7-5. 100% |=========================| 123 kB    00:15
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: libmcrypt                    ######################### [1/1]

Installed: libmcrypt.i386 0:2.5.7-5.el5.centos
Complete!
[root@localhost php-5.2.4]#

 

checking for mcrypt support… yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.  <—-まだ無いと言われる。
[root@localhost php-5.2.4]# yum install libmcrypt-devel
Loading “installonlyn” plugin
Setting up Install Process
Setting up repositories
base                      100% |=========================| 1.1 kB    00:00
updates                   100% |=========================|  951 B    00:00
addons                    100% |=========================|  951 B    00:00
extras                    100% |=========================| 1.1 kB    00:00
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
–> Populating transaction set with selected packages. Please wait.
—> Downloading header for libmcrypt-devel to pack into transaction set.
libmcrypt-devel-2.5.7-5.e 100% |=========================| 3.2 kB    00:00
—> Package libmcrypt-devel.i386 0:2.5.7-5.el5.centos set to be updated
–> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 libmcrypt-devel         i386       2.5.7-5.el5.centos  extras            103 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 103 k
Is this ok [y/N]: y
Downloading Packages:
(1/1): libmcrypt-devel-2. 100% |=========================| 103 kB    00:02
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: libmcrypt-devel              ######################### [1/1]

Installed: libmcrypt-devel.i386 0:2.5.7-5.el5.centos
Complete!
[root@localhost php-5.2.4]#

 

configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!

                ↑

MYSQL5.0.45をSourceから入れたので開発ライブラリーが無い。

[root@localhost src]# wget ftp://ftp.pbone.net/mirror/dev.mysql.com/pub/Downloads/MySQL-5.0/MySQL-devel-5.0.45-0.glibc23.i386.rpm

 

[root@localhost src]# rpm -ivh MySQL-devel-5.0.45-0.glibc23.i386.rpm
準備中…                ########################################### [100%]
   1:MySQL-devel            ########################################### [100%]
[root@localhost src]# ./configure \
 –prefix=/usr/local/php-5.2.4 \
 –with-apxs2=/usr/local/apache2/bin/apxs \
 –with-config-file-path=/usr/local/php-5.2.4/lib/ \
 –with-gd \
 –with-jpeg-dir=/usr/local \
 –with-png-dir=/usr/local \
 –with-gd \
 –with-zlib \
 –with-zlib-dir=/usr/local \
 –with-xml \
 –with-openssl \
 –with-config-file-path=/etc \
 –with-libmbfl \
 –with-mcrypt \
 –with-mime-magic \
 –with-mysql \
 –enable-pcntl \
 –enable-trans-sid \
 –enable-zend-multibyte \
 –enable-mbstr-enc-trans \
 –enable-mbstring \
 –enable-mbregex \
 –enable-gd-native-ttf \
 –enable-gd-jis-conv \
 –enable-exif

—–省略——-

Generating files
updating cache ./config.cache
creating ./config.status
creating php5.spec
creating main/build-defs.h
creating scripts/phpize
creating scripts/man1/phpize.1
creating scripts/php-config
creating scripts/man1/php-config.1
creating sapi/cli/php.1
creating main/php_config.h
creating main/internal_functions.c
creating main/internal_functions_cli.c
+——————————————————————–+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+——————————————————————–+

Thank you for using PHP.

Notice: Following unknown configure options were used:

–with-xml
(ここに答えがありました:http://www.thinkit.co.jp/free/marugoto/1/5/3/1.html)
–enable-trans-sid
(–enable-trans-idの間違え)
–enable-mbstr-enc-trans
(PHP 4.3.0 以降、このオプション –enable-mbstr-enc-trans は廃止で実行時の設定 mbstring.encoding_translationにに変更)

Check ‘./configure –help’ for available options

[root@localhost php-5.2.4]#

 

とりあえず,オプションのミスはあったもののconfigureは成功3つ程オプションが無視されたが,緊急で必要では

ないので,次回ちゃんとオプションを直して再度,make cleanしてconfigureする事とする。

 

[root@localhost php-5.2.4]# make

gcc: /usr/lib/mysql/libmysqlclient.so: No such file or directory
make: *** [libphp5.la] エラー 1

 

[root@localhost src]# wget ftp://ftp.pbone.net/mirror/dev.mysql.com/pub/Downloads/MySQL-5.0/MySQL-client-community-5.0.45-0.sles10.i586.rpm
–02:37:26–  ftp://ftp.pbone.net/mirror/dev.mysql.com/pub/Downloads/MySQL-5.0/MySQL-client-community-5.0.45-0.sles10                                        .i586.rpm
           => `MySQL-client-community-5.0.45-0.sles10.i586.rpm’
ftp.pbone.net をDNSに問いあわせています… 85.14.85.4
ftp.pbone.net|85.14.85.4|:21 に接続しています… 接続しました。
anonymous としてログインしています… ログインしました!
==> SYST … 完了しました。    ==> PWD … 完了しました。
==> TYPE I … 完了しました。  ==> CWD /mirror/dev.mysql.com/pub/Downloads/MySQL-5.0 … 完了しました。
==> SIZE MySQL-client-community-5.0.45-0.sles10.i586.rpm … 12538161
==> PASV … 完了しました。    ==> RETR MySQL-client-community-5.0.45-0.sles10.i586.rpm … 完了しました。
長さ: 12538161 (12M)

100%[====================================================================================================================>] 12,538,161   221K/s   in 57s

02:38:28 (215 KB/s) – `MySQL-client-community-5.0.45-0.sles10.i586.rpm’ を保存しました [12538161]

[root@localhost src]#

[root@localhost src]# rpm -ivh MySQL-client-community-5.0.45-0.sles10.i586.rpm
準備中…                ########################################### [100%]
   1:MySQL-client-community ########################################### [100%]
[root@localhost src]#

 

[root@localhost php-5.2.4]# make

gcc: /usr/lib/mysql/libmysqlclient.so: No such file or directory
make: *** [libphp5.la] エラー 1
[root@localhost php-5.2.4]# ls /usr/
X11R6/    bin/      etc/      games/    include/  kerberos/ lib/      libexec/  local/    sbin/     share/    src/      tmp/
[root@localhost php-5.2.4]# ls /usr/lib/mysql/lib
libdbug.a            libmyisam.a          libmysqlclient.la    libmystrings.a       libndbclient.la      libz.la
libheap.a            libmyisammrg.a       libmysqlclient_r.a   libmysys.a           libvio.a
libmygcc.a           libmysqlclient.a     libmysqlclient_r.la  libndbclient.a       libz.a
[root@localhost php-5.2.4]# find / -name “libmysqlclient.so”
/home/admin/postsource/mysql-5.0.45/libmysql/.libs/libmysqlclient.so

[root@localhost php-5.2.4]#
[root@localhost php-5.2.4]# cp /home/admin/postsource/mysql-5.0.45/libmysql/.libs/libmysqlclient.so /usr/lib/mysql/libmysqlclient.so
[root@localhost php-5.2.4]# ldconfig
[root@localhost php-5.2.4]#

何回か失敗したので,せっかくなのでConfigureし直す事にした。(一応make clean)

./configure \
 –prefix=/usr/local/php-5.2.4 \
 –with-apxs2=/usr/local/apache2/bin/apxs \
 –with-config-file-path=/usr/local/php-5.2.4/lib/ \
 –with-gd \
 –with-jpeg-dir=/usr/local \
 –with-png-dir=/usr/local \
 –with-gd \
 –with-zlib \
 –with-zlib-dir=/usr/local \
 –with-xml \
 –with-openssl \
 –with-config-file-path=/etc \
 –with-libmbfl \
 –with-mcrypt \
 –with-mime-magic \
 –with-mysql \
 –enable-pcntl \
 –enable-trans-id \
 –enable-zend-multibyte \
 –enable-mbstring \
 –enable-mbregex \
 –enable-gd-native-ttf \
 –enable-gd-jis-conv \
 –enable-exif

 

[root@localhost php-5.2.4]# make

api/cli/getopt.lo main/internal_functions_cli.lo -lcrypt -lcrypt -lrt -lmysqlclient -lmcrypt -lpng -lz -ljpeg -lz -lresolv -lm -ldl -lnsl -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt  -o sapi/cli/php

Build complete.
Don’t forget to run ‘make test’.

 

[root@localhost php-5.2.4]# make test
/usr/local/src/php-5.2.4/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory
/usr/local/src/php-5.2.4/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory
make: [test] エラー 127 (無視されました)
[root@localhost php-5.2.4]#

[root@localhost php-5.2.4]# cp /home/admin/postsource/mysql-5.0.45/libmysql/.libs/libmysqlclient.so.15 /usr/lib/mysql/
[root@localhost php-5.2.4]# ldconfig

 

[root@localhost php-5.2.4]# make test

=====================================================================
TEST RESULT SUMMARY
———————————————————————
Exts skipped    :   48
Exts tested     :   31
———————————————————————

Number of tests : 3973              2632
Tests skipped   : 1341 ( 33.8%) ——–
Tests warned    :    1 (  0.0%) (  0.0%)
Tests failed    :    5 (  0.1%) (  0.2%)
Tests passed    : 2626 ( 66.1%) ( 99.8%)
———————————————————————
Time taken      :  494 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
———————————————————————
libgd #106 (imagerectangle 1×1 draws 1×3) [ext/gd/tests/libgd00106.phpt]
Bug #16069 (ICONV transliteration failure) [ext/iconv/tests/bug16069.phpt]
iconv stream filter [ext/iconv/tests/iconv_stream_filter.phpt]
htmlentities() test 2 (setlocale / fr_FR.ISO-8859-15) [ext/standard/tests/strings/htmlentities02.phpt] (warn: possibly braindead libc)
htmlentities() test 4 (setlocale / ja_JP.EUC-JP) [ext/standard/tests/strings/htmlentities04.phpt]
htmlentities() test 15 (setlocale / KOI8-R) [ext/standard/tests/strings/htmlentities15.phpt]
=====================================================================

※幾つかエラーが出てしまった。とりあえず,それ程問題になりそうではないので今回は無視。

 

[root@localhost php-5.2.4]# make install
Installing PHP SAPI module:       apache2handler
/usr/local/apache2/build/instdso.sh SH_LIBTOOL=’/usr/local/apache2/build/libtool’ libphp5.la /usr/local/apache2/modules
/usr/local/apache2/build/libtool –mode=install cp libphp5.la /usr/local/apache2/modules/
cp .libs/libphp5.so /usr/local/apache2/modules/libphp5.so
cp .libs/libphp5.lai /usr/local/apache2/modules/libphp5.la
libtool: install: warning: remember to run `libtool –finish /usr/local/src/php-5.2.4/libs’
chmod 755 /usr/local/apache2/modules/libphp5.so
[activating module `php5′ in /usr/local/apache2/conf/httpd.conf]
Installing PHP CLI binary:        /usr/local/php-5.2.4/bin/
Installing PHP CLI man page:      /usr/local/php-5.2.4/man/man1/
Installing build environment:     /usr/local/php-5.2.4/lib/php/build/
Installing header files:          /usr/local/php-5.2.4/include/php/
Installing helper programs:       /usr/local/php-5.2.4/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php-5.2.4/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php-5.2.4/lib/php/
[PEAR] Console_Getopt – installed: 1.2.3
[PEAR] Archive_Tar    – installed: 1.3.2
[PEAR] Structures_Graph- installed: 1.0.2
pear/PEAR can optionally use package “pear/XML_RPC” (version >= 1.4.0)
[PEAR] PEAR           – installed: 1.6.1
Wrote PEAR system config file at: /usr/local/php-5.2.4/etc/pear.conf
You may want to add: /usr/local/php-5.2.4/lib/php to your php.ini include_path
Installing PDO headers:          /usr/local/php-5.2.4/include/php/ext/pdo/
[root@localhost php-5.2.4]#

今後のバージョン変更の為にシンボリックリンクを貼って終了。

[root@localhost php-5.2.4]# ln -sfn /usr/local/php-5.2.4 /usr/local/php
[root@localhost php-5.2.4]# ls -l /usr/local/php
lrwxrwxrwx 1 root root 20 10月 13 03:44 /usr/local/php -> /usr/local/php-5.2.4
[root@localhost php-5.2.4]#