phpの最近のブログ記事

yumのphp53でPHP5.3がインストールできる。拡張もyumにphp53-XXXXがあるが、php53-pearとphp53-mcryptはない。

mcryptのインストール

CentOS5.7のyumでphp53がインストールされた環境に、PHPのソースからmcrypt拡張をインストールした。


まず必要なmcrypt拡張のビルドに必要なパッケージをインストールしておく。

$ sudo yum install php53-devel libmcrypt-devel


yumでインストールしたphpと同じバージョンのソースを http://jp2.php.net/releases/ などPHPのダウンロードサイトからダウンロード、展開してmcrypt拡張をビルド、インストール。

$ wget http://museum.php.net/php5/php-5.3.3.tar.gz
$ tar xzvf php-5.3.3.tar.gz
$ cd php-5.3.3/ext/mcrypt/
$ phpize
$ aclocal
$ ./configure
$ make
$ sudo make install


php.iniを編集

extension=mcrypt.so

CentOS 5.6 に PHP 5.3 の mcrypt 拡張をインストールする (phpMyAdmin) | MyNotebook

pearのインストールとアップグレード

pearは以下の手順でインストール、アップグレード。

$ sudo yum install php-pear
$ sudo pear upgrade --force Archive_Tar
$ sudo pear upgrade --force Console_Getopt
$ sudo pear upgrade PEAR

カテゴリー:

カテゴリー:

$ sudo port install php5-mysql
Password:
--->  Computing dependencies for php5-mysql
--->  Fetching php5-mysql
--->  Verifying checksum(s) for php5-mysql
--->  Extracting php5-mysql
--->  Configuring php5-mysql
--->  Building php5-mysql
--->  Staging php5-mysql into destroot
--->  Installing php5-mysql @5.3.0_0+mysqlnd
To use mysqlnd with a local MySQL server, edit /opt/local/etc/php5/php.ini and set
mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket
to /opt/local/var/run/mysql5/mysqld.sock
--->  Activating php5-mysql @5.3.0_0+mysqlnd
--->  Cleaning php5-mysql

 表示されているメッセージにあるように、php.iniにdefault_socketを設定するのを忘れないこと。

To use mysqlnd with a local MySQL server, edit /opt/local/etc/php5/php.ini and set
mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket
to /opt/local/var/run/mysql5/mysqld.sock

カテゴリー:

カテゴリー:

peclでAPCをインストールしようとしたら、以下のエラーが発生した。

# pecl install APC
downloading APC-3.0.19.tgz ...
Starting to download APC-3.0.19.tgz (115,735 bytes)
.........done: 115,735 bytes

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 7680 bytes) in /usr/share/pear/PEAR/PackageFile/v2.php on line 1917

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 76 bytes) in /usr/share/pear/pearcmd.php on line 402

[php-maint] Bug#375070: php-pear: pecl memory limit too low

pecl実行時のmemory_limitが小さすぎるのが原因らしい。
上記サイトを参考にして、peclを変更( -d memory_limit=24Mを追加)したら解決。

また、peclでのAPCのインストールには、phpize、apxsが必要なので、php-devel、httpd-develをyumでインストール。

# yum install php-devel
# yum install httpd-devel

APCをインストール

# pecl install APC
インストール後、php.iniに、
extension=apc.so
を追加する。

カテゴリー:

macportsでphp5をアップグレードした。

php5 @5.2.9_2+apache2+macosx+mysql5+pear+postgresql82+sqlite
 ↓
php5 @5.2.10_0+apache2+macosx+mysql5+pear+postgresql82+sqlite

すると、以下のエラー。

(追記: 後日、php5 @5.2.10_1が出たのでアップグレードしたら何の問題もなかった。)

$ sudo port upgrade php5
--->  Fetching php5
--->  Verifying checksum(s) for php5
--->  Extracting php5
--->  Applying patches to php5
--->  Configuring php5
--->  Building php5
--->  Staging php5 into destroot
Warning: php5 requests to install files outside the common directory structure!
--->  Deactivating php5 @5.2.9_2+apache2+macosx+mysql5+pear+postgresql82+sqlite
--->  Installing php5 @5.2.10_0+apache2+macosx+mysql5+pear+postgresql82+sqlite
--->  Activating php5 @5.2.10_0+apache2+macosx+mysql5+pear+postgresql82+sqlite
Error: Target org.macports.activate returned: Image error: /opt/local/lib/php/.registry/xml_util.reg already exists and does not belong to a registered port.  Unable to activate port php5.

最後のフェーズのactivateで失敗している。(ファイルのコピーでエラー)
-f オプションを付けて、強制的にactivateした。

$ sudo port -f activate php5 @5.2.10_0+apache2+macosx+mysql5+pear+postgresql82+sqlite
Password:
--->  Activating php5 @5.2.10_0+apache2+macosx+mysql5+pear+postgresql82+sqlite
Warning: File /opt/local/lib/php/.registry/xml_util.reg already exists.  Moving to: /opt/local/lib/php/.registry/xml_util.reg.mp_1246068080.
Warning: File /opt/local/lib/php/doc/XML_Util/examples/example.php already exists.  Moving to: /opt/local/lib/php/doc/XML_Util/examples/example.php.mp_1246068080.
Warning: File /opt/local/lib/php/doc/XML_Util/examples/example2.php already exists.  Moving to: /opt/local/lib/php/doc/XML_Util/examples/example2.php.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/AllTests.php already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/AllTests.php.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_apiVersion.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_apiVersion.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_attributesToString.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_attributesToString.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_collapseEmptyTags.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_collapseEmptyTags.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_createCDataSection.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_createCDataSection.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_createComment.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_createComment.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_createEndElement.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_createEndElement.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_createStartElement.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_createStartElement.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_createTag.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_createTag.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_createTagFromArray.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_createTagFromArray.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_getDocTypeDeclaration.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_getDocTypeDeclaration.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_getXmlDeclaration.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_getXmlDeclaration.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_isValidName.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_isValidName.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_raiseError.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_raiseError.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_replaceEntities.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_replaceEntities.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_reverseEntities.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_reverseEntities.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBasic_splitQualifiedName.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBasic_splitQualifiedName.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBug_4950.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBug_4950.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/test/XML_Util/tests/testBug_5392.phpt already exists.  Moving to: /opt/local/lib/php/test/XML_Util/tests/testBug_5392.phpt.mp_1246068080.
Warning: File /opt/local/lib/php/XML/Util.php already exists.  Moving to: /opt/local/lib/php/XML/Util.php.mp_1246068080.

カテゴリー:

カテゴリー:

PHP: hash_hmac - Manual

string hash_hmac(string $algo, string $data, string $key[, bool $raw_output= false])

カテゴリー:

$ sudo port install php5-xdebug
Password:
--->  Fetching php5-xdebug
--->  Attempting to fetch xdebug-2.0.3.tgz from http://www.xdebug.org/files/
--->  Verifying checksum(s) for php5-xdebug
--->  Extracting php5-xdebug
--->  Configuring php5-xdebug
--->  Building php5-xdebug with target all
--->  Staging php5-xdebug into destroot
--->  Installing php5-xdebug 2.0.3_0

    ***************************************************************************
    * To enable the xdebug extension in php, add or edit the following
    * lines in /opt/local/etc/php.ini:
    *
    * zend_extension="/opt/local/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"
    *
    * Once the extension is installed, you can get a list of the available
    * configuration settings with the following command:
    *
    * % php --ri xdebug
    *
    * For more information and details about configuration settings, see
    * http://www.xdebug.org/docs/
    ***************************************************************************
--->  Activating php5-xdebug 2.0.3_0
--->  Cleaning php5-xdebug

php.iniに以下を追加。

zend_extension="/opt/local/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"

カテゴリー:

$ sudo port install php5 +postgresql +apache2 +pear
--->  Fetching curl
--->  Attempting to fetch curl-7.18.2.tar.bz2 from http://curl.haxx.se/download/
--->  Verifying checksum(s) for curl
--->  Extracting curl
--->  Configuring curl
--->  Building curl with target all
--->  Staging curl into destroot
--->  Installing curl 7.18.2_0
--->  Activating curl 7.18.2_0
--->  Cleaning curl
--->  Fetching gd2
--->  Attempting to fetch gd-2.0.35.tar.bz2 from http://www.libgd.org/releases/
--->  Verifying checksum(s) for gd2
--->  Extracting gd2
--->  Applying patches to gd2
--->  Configuring gd2
--->  Building gd2 with target all
--->  Staging gd2 into destroot
--->  Installing gd2 2.0.35_1
--->  Activating gd2 2.0.35_1
--->  Cleaning gd2
--->  Fetching libmcrypt
--->  Attempting to fetch libmcrypt-2.5.8.tar.bz2 from http://downloads.sourceforge.net/mcrypt
--->  Verifying checksum(s) for libmcrypt
--->  Extracting libmcrypt
--->  Configuring libmcrypt
--->  Building libmcrypt with target all
--->  Staging libmcrypt into destroot
--->  Installing libmcrypt 2.5.8_0
--->  Activating libmcrypt 2.5.8_0
--->  Cleaning libmcrypt
--->  Fetching mhash
--->  Attempting to fetch mhash-0.9.9.tar.bz2 from http://downloads.sourceforge.net/mhash
--->  Verifying checksum(s) for mhash
--->  Extracting mhash
--->  Configuring mhash
--->  Building mhash with target all
--->  Staging mhash into destroot
--->  Installing mhash 0.9.9_0
--->  Activating mhash 0.9.9_0
--->  Cleaning mhash
--->  Fetching php5
--->  Attempting to fetch php-5.2.6.tar.bz2 from http://www.php.net/distributions/
--->  Verifying checksum(s) for php5
--->  Extracting php5
--->  Configuring php5
--->  Building php5 with target all
--->  Staging php5 into destroot
Warning: php5 requests to install files outside the common directory structure!
--->  Installing php5 5.2.6_1+apache2+macosx+pear

If this is your first install, you might want
cd /opt/local/apache2/modules
/opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so

* copy  /opt/local/etc/php.ini-dist to  /opt/local/etc/php.ini
--->  Activating php5 5.2.6_1+apache2+macosx+pear
--->  Cleaning php5

variantsの+postgresqlが間違ってた。
variantsを確認。

$ port variants php5
php5 has the variants:
	universal
	darwin_6
	darwin_7
	macosx
	apache: for Apple Apache
	apache2: for current Apache
	fastcgi: add fastcgi binary
	gmp: Add GNU MP functions
	dbase: Add dBase file format support
	imap: enable operation with IMAP protocol
	pspell: Add pspell spell-checking functions
	tidy: add Tidy support
	mssql: add support for MS-SQL server
	snmp: use Apple snmp
	macports_snmp: use MacPorts snmp
	mysql3: build MySQL 3 support
	mysql4: build MySQL 4 support
	mysql5: build MySQL 5 support
	oracle: Add Oracle oci8 database functions with the Oracle Instant Client
	postgresql82: provide postgresql82 support
	postgresql83: provide postgresql83 support
	sqlite: build sqlite support
	ipc: build IPC support
	pcntl: provide process control
	pear: add pear stuff
	readline: Add GNU readline functions
	sockets: Add socket communication functions
	t1lib: Add PostScript Type 1 font support with t1lib

正しくは、+postgresql83。
改めてインストール。ついでにmysql5とsqliteを追加。(MySQL5を先にインストールしておく。MySQL5のインストールについては、関連エントリー参照)

$ sudo port install php5 +postgresql83 +mysql5 +sqlite +apache2 +pear
--->  Fetching mysql5
--->  Attempting to fetch mysql-5.0.67.tar.gz from http://distfiles.macports.org/mysql5
--->  Verifying checksum(s) for mysql5
--->  Extracting mysql5
--->  Configuring mysql5
--->  Building mysql5 with target all
--->  Staging mysql5 into destroot
--->  Installing mysql5 5.0.67_0
--->  Activating mysql5 5.0.67_0
--->  Cleaning mysql5
--->  Fetching php5
--->  Verifying checksum(s) for php5
--->  Extracting php5
--->  Configuring php5
--->  Building php5 with target all
--->  Staging php5 into destroot
Warning: php5 requests to install files outside the common directory structure!
--->  Installing php5 5.2.6_1+apache2+macosx+mysql5+pear+postgresql83+sqlite

If this is your first install, you might want
cd /opt/local/apache2/modules
/opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so

* copy  /opt/local/etc/php.ini-dist to  /opt/local/etc/php.ini
--->  Activating php5 5.2.6_1+apache2+macosx+mysql5+pear+postgresql83+sqlite
Error: Target org.macports.activate returned: Image error: Another version of this port (php5 @5.2.6_1+apache2+macosx+pear) is already active.
Error: Status 1 encountered during processing.

最初のインストールが残っていたので、activateできなかったみたい。
いったんアンインストールしてインストールしなおす。

$ sudo port uninstall php5
--->  The following versions of php5 are currently installed:
--->  	php5 @5.2.6_1+apache2+macosx+mysql5+pear+postgresql83+sqlite
--->  	php5 @5.2.6_1+apache2+macosx+pear (active)
Error: port uninstall failed: Registry error: Please specify the full version as recorded in the port registry.

php5が複数あるからフルで指定しないとアンインストールできないらしい。

$ sudo port uninstall php5 @5.2.6_1+apache2+macosx+pear
--->  Deactivating php5 5.2.6_1+apache2+macosx+pear
--->  Uninstalling php5 5.2.6_1+apache2+macosx+pear

アンインストールできたので、インストールしなおす。

$ sudo port install php5 +postgresql83 +mysql5 +sqlite +apache2 +pear
--->  Activating php5 5.2.6_1+apache2+macosx+mysql5+pear+postgresql83+sqlite
--->  Cleaning php5

インストールは終わっていたようで、activateだけされた。

インストール時のメッセージにある通り、apxsでapacheにphp5モジュールを追加する。

$ cd /opt/local/apache2/modules/
$ sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
Password:
[activating module `php5' in /opt/local/apache2/conf/httpd.conf]

添付されているサンプルからphp.iniをコピー。

$ sudo cp /opt/local/etc/php.ini-dist /opt/local/etc/php.ini

/opt/local/apache2/conf/httpd.confに以下を追加。

Include conf/extras-conf/mod_php.conf

カテゴリー: