18
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7.1にPHP5.2.17環境を構築する

Last updated at Posted at 2017-04-28

今さら感あるが、どうしても必要になったので構築した。
CentOS7.1ならではの手順は無かった。

事前準備

タイムゾーンを変更する

$ sudo timedatectl 
      Local time: Tue 2017-05-09 04:19:11 UTC
  Universal time: Tue 2017-05-09 04:19:11 UTC
        RTC time: Tue 2017-05-09 04:19:11
       Time zone: UTC (UTC, +0000)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

タイムゾーンを Asia/Tokyo に変更する

$ sudo timedatectl set-timezone Asia/Tokyo

設定確認

$ sudo timedatectl 
      Local time: Tue 2017-05-09 13:19:19 JST
  Universal time: Tue 2017-05-09 04:19:19 UTC
        RTC time: Tue 2017-05-09 04:19:19
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

ミドルウェアインストール

ソースを取得するためのミドルウェアをインストールする

$ sudo yum -y install wget

ソースコンパイルに必要なミドルウェアをインストールする

$ sudo yum -y install gcc make libxml2 libxml2-devel

Apacheをインストールする

$ sudo yum -y httpd httpd-devel

httpd-devel は --with-apxs2=/usr/bin/apxs で 必要な apxs がインストールされる
Apache入れたのにapxsが無い場合は疑うと良い

PHPインストール

PHPのソースを取得する

$ cd /usr/local/src
$ wget https://museum.php.net/php5/php-5.2.17.tar.gz
$ tar zxvf php-5.2.17.tar.gz

Patch

ext/dom/node.c

以下のエラーが発生する。

/usr/local/src/php-5.2.17/ext/dom/node.c: In function 'dom_canonicalization':
/usr/local/src/php-5.2.17/ext/dom/node.c:1953:21: error: dereferencing pointer to incomplete type
    ret = buf->buffer->use;
                     ^
In file included from /usr/local/src/php-5.2.17/main/php.h:38:0,
                 from /usr/local/src/php-5.2.17/ext/dom/node.c:26:
/usr/local/src/php-5.2.17/ext/dom/node.c:1955:40: error: dereferencing pointer to incomplete type
     RETVAL_STRINGL((char *) buf->buffer->content, ret, 1);
                                        ^
/usr/local/src/php-5.2.17/Zend/zend_API.h:472:14: note: in definition of macro 'ZVAL_STRINGL'
   char *__s=(s); int __l=l;  \
              ^
/usr/local/src/php-5.2.17/ext/dom/node.c:1955:5: note: in expansion of macro 'RETVAL_STRINGL'
     RETVAL_STRINGL((char *) buf->buffer->content, ret, 1);
     ^
make: *** [ext/dom/node.lo] Error 1

Patchが公開されているので取得する。

$ wget https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt
$ mv txtbgxGXAvz4N.txt php-5.2.17.patch
--- ext/dom/node.c	2012-08-06 17:49:48.826716692 +0800
+++ ext/dom/node.c	2012-08-06 17:52:47.633484660 +0800
@@ -1895,9 +1895,17 @@ static void dom_canonicalization(INTERNA
         RETVAL_FALSE;
     } else {
 		if (mode == 0) {
+#ifdef LIBXML2_NEW_BUFFER
+            ret = xmlOutputBufferGetSize(buf);
+#else
 			ret = buf->buffer->use;
+#endif
 			if (ret > 0) {
+#ifdef LIBXML2_NEW_BUFFER
+                RETVAL_STRINGL((char *) xmlOutputBufferGetContent(buf), ret, 1);
+#else
 				RETVAL_STRINGL((char *) buf->buffer->content, ret, 1);
+#endif
 			} else {
 				RETVAL_EMPTY_STRING();
 			}
--- ext/dom/documenttype.c	2012-08-06 18:02:16.019640870 +0800
+++ ext/dom/documenttype.c	2012-08-06 18:06:16.612228905 +0800
@@ -205,7 +205,13 @@ int dom_documenttype_internal_subset_rea
 		if (buff != NULL) {
 			xmlNodeDumpOutput (buff, NULL, (xmlNodePtr) intsubset, 0, 0, NULL);
 			xmlOutputBufferFlush(buff);
+
+#ifdef LIBXML2_NEW_BUFFER
+			ZVAL_STRINGL(*retval, xmlOutputBufferGetContent(buff),
+			             xmlOutputBufferGetSize(buff), 1);
+#else
 			ZVAL_STRINGL(*retval, buff->buffer->content, buff->buffer->use, 1);
+#endif
 			(void)xmlOutputBufferClose(buff);
 			return SUCCESS;
 		}
--- ext/simplexml/simplexml.c	2012-08-06 18:10:44.621017026 +0800
+++ ext/simplexml/simplexml.c	2012-08-06 18:12:48.016270419 +0800
@@ -1417,7 +1417,12 @@ SXE_METHOD(asXML)
 
 			xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, ((xmlDocPtr) sxe->document->ptr)->encoding);
 			xmlOutputBufferFlush(outbuf);
+#ifdef LIBXML2_NEW_BUFFER
+			RETVAL_STRINGL((char *)xmlOutputBufferGetContent(outbuf),
+			               xmlOutputBufferGetSize(outbuf), 1);
+#else
 			RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use, 1);
+#endif
 			xmlOutputBufferClose(outbuf);
 		}
 	} else {
$ sudo patch -p0 < ../php-5.2.17.patch 
patching file ext/dom/node.c
Hunk #1 succeeded at 1950 (offset 55 lines).
patching file ext/dom/documenttype.c
Hunk #1 succeeded at 215 (offset 10 lines).
patching file ext/simplexml/simplexml.c
Hunk #1 succeeded at 1343 (offset -74 lines).

unixd_config

以下のエラーが発生する。

Apache2.4起動時にlibphp5.soの読み込みに失敗する。

Apr 27 07:55:22 ip-10-0-0-79 httpd: httpd: Syntax error on line 55 of /etc/httpd/conf/httpd.conf: Cannot load /usr/lib64/httpd/modules/libphp5.so into server: /usr/lib64/httpd/modules/libphp5.so: undefined symbol: unixd_config

要因は以下
http://httpd.apache.org/docs/current/developer/new_api_2_4.html

unixd_configをap_unixd_configに変更する。

--- sapi/apache2handler/php_functions.c.2012-09-07 15:15:37.403662055 +0900
+++ sapi/apache2handler/php_functions.c 2012-09-07 14:58:38.755648593 +0900
@@ -383,7 +383,7 @@
        char *p;
        server_rec *serv = ((php_struct *) SG(server_context))->r->server;
 #if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE)
-       AP_DECLARE_DATA extern unixd_config_rec unixd_config;
+       AP_DECLARE_DATA extern unixd_config_rec ap_unixd_config;
 #endif

        for (n = 0; ap_loaded_modules[n]; ++n) {
@@ -414,7 +414,7 @@
        php_info_print_table_row(2, "Hostname:Port", tmp);

 #if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE)
-       snprintf(tmp, sizeof(tmp), "%s(%d)/%d", unixd_config.user_name, unixd_config.user_id, unixd_config.group_id);
+       snprintf(tmp, sizeof(tmp), "%s(%d)/%d", ap_unixd_config.user_name, ap_unixd_config.user_id, ap_unixd_config.group_id);
        php_info_print_table_row(2, "User/Group", tmp);
 #endif

configure

$ ./configure --with-apxs2=/usr/bin/apxs --enable-mbstring --enable-mbregex

他、環境に合わせて変更すれば良い

make

$ sudo make ZEND_EXTRA_LIBS='-liconv'
$ sudo make
$ sudo make install

権限

$ chown -R apache:apache /var/www/mcd/rsync
$ find /var/www/mcd/rsync -type d -exec chmod 770 {} ;
$ find /var/www/mcd/rsync -type f -exec chmod 660 {} ;

おまけ:ビルド条件の確認

configure にて、ビルド条件を確認する。

$ cd php-5.2.17
$ ./configure > hogehoge.log
configure: warning: bison versions supported for regeneration of the Zend/PHP parsers: 1.28 1.35 1.75 1.875 2.0 2.1 2.2 2.3 2.4 2.4.1 (found: none).
configure: warning: flex versions supported for regeneration of the Zend/PHP parsers: 2.5.4  (found: none)
configure: warning: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
configure: warning: lemon versions supported for regeneration of libsqlite parsers: 1.0 (found: none).
configure: warning: bison versions supported for regeneration of the Zend/PHP parsers: 1.28 1.35 1.75 1.875 2.0 2.1 2.2 2.3 2.4 2.4.1 (found: none).

bison

$ sudo wget https://ftp.gnu.org/gnu/bison/bison-2.4.1.tar.gz
$ sudo tar -xzvf bison-2.4.1.tar.gz
$ cd bison-2.4.1/
$ sudo ./configure

configure: error: GNU M4 1.4 is required

M4解決してから再実行

/usr/local/src/bison-2.4.1/build-aux/missing: line 52: help2man: command not found

help2man解決してから再実行

GNU M4

$ sudo wget https://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.gz
$ sudo tar -xzvf m4-1.4.18.tar.gz
$ sudo ./configure
$ sudo make
$ sudo make install

help2man

$ sudo yum -y install help2man
18
15
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?