Quantcast
Channel: PHP7.4タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 113

PHP 7.4 alpha 1 がリリースされたので記念に野良ビルドしてみる

$
0
0

はじめに

待望の PHP 7.4 がリリースされました!ということで記念に野良ビルドします🐘

野良ビルド集

動作環境

  • CentOS 7
$ php -v
PHP 7.4.0alpha1 (cli) (built: Jun 16 2019 02:11:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0-dev, Copyright (c) Zend Technologies
Removing intermediate container dddb573013ea

ビルド

ミニマム

  • configure にオプション何もつけずにやります 何もつけないとすんなりビルドが通ります。
sudo yum install epel-release
sudo yum install -y wget make automake gcc libxml2 libxml2-devel sqlite sqlite-devel
cd /tmp
wget https://downloads.php.net/~derick/php-7.4.0alpha1.tar.gz
tar zxvf php-7.4.0alpha1.tar.gz
cd php-7.4.0alpha1

./configure

make
sudo make install

Dockerfile

FROM centos:7

RUN yum install -y epel-release
RUN yum install -y wget make automake gcc libxml2 libxml2-devel sqlite sqlite-devel

WORKDIR /tmp
RUN wget https://downloads.php.net/~derick/php-7.4.0alpha1.tar.gz && \
    tar zxvf php-7.4.0alpha1.tar.gz

WORKDIR php-7.4.0alpha1
RUN ./configure

RUN make
RUN make install

オプションいっぱいつけてみる

下記のよく使いそうなオプションを付けてみます

  • apxs (Apache用モジュール) (--with-apxs2)
  • mbstring (--enable-mbstring)
  • pdo-mysql (--with-pdo-mysql)
  • gettext (--with-gettext)
  • gd (--with-gd, --enable-gd-jis-conv)
  • openssl (--with-openssl)
  • intl (--enable-intl)

ちなみに、 PHP 7.4 から ./configure で出力されるエラーメッセージがめちゃめちゃ優しくなりました。これで野良ビルド初心者の方でも野良ビルドに励むことができそうですね。
逆に今までのエラーメッセージが雑すぎた説はある :thinking:

エラーメッセージの例
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:

No package 'icu-uc' found
No package 'icu-io' found
No package 'icu-i18n' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ICU_CFLAGS
and ICU_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

下記がコマンドです

cd /tmp
sudo yum install -y epel-release
sudo yum install -y wget \
                   automake gcc \
                   libxml2 libxml2-devel \
                   sqlite sqlite-devel \
                   make \
                   httpd httpd-devel \
                   openssl openssl-devel \
                   libicu libicu-devel \
                   gcc-c++ \
                   oniguruma oniguruma-devel

wget https://downloads.php.net/~derick/php-7.4.0alpha1.tar.gz && \
    tar zxvf php-7.4.0alpha1.tar.gz


cd php-7.4.0alpha1
./configure \
        --with-apxs2 \
        --enable-mbstring \
        --with-pdo-mysql \
        --with-gd \
        --enable-gd-jis-conv \
        --with-openssl \
        --enable-intl

make
sudo make install

php -v

Dockerfile

FROM centos:7

WORKDIR /tmp
RUN wget https://downloads.php.net/~derick/php-7.4.0alpha1.tar.gz && \
    tar zxvf php-7.4.0alpha1.tar.gz

RUN yum install -y epel-release
RUN yum install -y wget \
                   automake gcc \
                   libxml2 libxml2-devel \
                   sqlite sqlite-devel \
                   make \
                   httpd httpd-devel \
                   openssl openssl-devel \
                   libicu libicu-devel \
                   gcc-c++ \
                   oniguruma oniguruma-devel

WORKDIR php-7.4.0alpha1
RUN ./configure \
        --with-apxs2 \
        --enable-mbstring \
        --with-pdo-mysql \
        --with-gd \
        --enable-gd-jis-conv \
        --with-openssl \
        --enable-intl

RUN make
RUN make install

RUN php -v

ミニマムの項目と比較して足りなかったモジュールは下記のとおりです。全部 epel に入っているので、 yum で入れられます。

  • gcc-c++
  • httpd
  • httpd-devel
  • openssl
  • openssl-devel
  • libicu
  • libicu-devel
  • oniguruma
  • oniguruma-devel

今まで登場しなかった、 oniguruma あたりが足りないモジュールだよとエラーメッセージとして登場してました。

zip 拡張について

--enable-zip を有効にしてもなぜか php -m で表示されないので、 pecl からインストールする必要がありそうです。

PHP の UPGRADING には下記のように書かれていました。

Zip:
The bundled libzip library has been removed. 
A system libzip >= 0.11 is now necessary to build the extension.

雑翻訳ですが、

バンドルされた libzip は削除されました。
拡張機能をビルドする際に現在 libzip 0.11 以上が必要となります。

と書かれているので、これからは --enable-zip をしても zip は入らないみたいですね。

libzip 自体は cmake の比較的新しいバージョンのインストールも必要のようなので、事前に準備する必要がありそうです。(yum だと 2.8 がインストール対象だったんですが 3 系が必要のようです)

ちなみに、インストールしようとしたら、下記のエラーが出てしまったので、まだオフィシャルでは PHP 7.4 に未対応なようです。

/php-7.4.0alpha1/~/zip-1.15.4/php73/php_zip.c: In function 'php_zip_pcre':
/php-7.4.0alpha1/~/zip-1.15.4/php73/php_zip.c:660:3: error: too many arguments to function 'pcre_get_compiled_regex'
   re = pcre_get_compiled_regex(regexp, &capture_count, &preg_options);
   ^
In file included from /php-7.4.0alpha1/~/zip-1.15.4/php73/php_zip.c:29:0:
/usr/local/include/php/ext/pcre/php_pcre.h:31:20: note: declared here
 PHPAPI pcre2_code* pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count);
                    ^
make: *** [php73/php_zip.lo] Error 1

で、 pcre_get_compiled_regex の引数の数が変わったので、現時点で PHP 7.4 にインストールするには、該当の箇所を変更する必要があります。

私は面倒くさいので下記で対応しました

sed -ie 's/, &preg_options//' /path/to/php_zip.c && \
sed -ie 's/, &preg_optionscapture_count//' /path/to/php_zip.c

こうすることにより正常にインストールができるようになります。

[PHP Modules]
...
zip

下記が使用した Dockerfile なので、ご参考までに。

FROM centos:7

RUN yum install -y epel-release
RUN yum install -y httpd httpd-devel \
                   openssl openssl-devel \
                   libicu libicu-devel \
                   gcc-c++ \
                   oniguruma oniguruma-devel \
                   automake gcc \
                   libxml2 libxml2-devel \
                   sqlite sqlite-devel \
                   make \
                   wget

RUN cd /tmp
RUN wget https://downloads.php.net/~derick/php-7.4.0alpha1.tar.gz && \
    tar zxvf php-7.4.0alpha1.tar.gz


WORKDIR php-7.4.0alpha1
RUN ./configure \
        --with-apxs2 \
        --enable-mbstring \
        --with-pdo-mysql \
        --with-gd \
        --enable-gd-jis-conv \
        --with-openssl \
        --enable-intl

RUN make
RUN make install

# zip を野良ビルドする
WORKDIR ~
RUN wget https://pecl.php.net/get/zip-1.15.4.tgz
RUN tar zxvf zip-1.15.4.tgz
WORKDIR zip-1.15.4
RUN phpize

# cmake を入れる
RUN wget https://github.com/Kitware/CMake/archive/v3.14.5.tar.gz && \
    tar zxvf v3.14.5.tar.gz
RUN cd CMake-3.14.5 && ./bootstrap && make && make install

# libzip を入れる
RUN mkdir /tmp/libzip && \
        cd /tmp/libzip && \
        curl -sSLO https://libzip.org/download/libzip-1.4.0.tar.gz && \
        tar zxfv libzip-1.4.0.tar.gz && \
        cd /tmp/libzip/libzip-1.4.0/
RUN cd /tmp/libzip/libzip-1.4.0/ && \
    cmake .
RUN cd /tmp/libzip/libzip-1.4.0/ && make && make install

# zip の configure を走らせる
RUN ./configure

# 7.4 より引数が変わったので削除
RUN sed -ie 's/, &preg_options//' /php-7.4.0alpha1/~/zip-1.15.4/php73/php_zip.c
RUN sed -ie 's/, &preg_optionscapture_count//' /php-7.4.0alpha1/~/zip-1.15.4/php73/php_zip.c

# PHP モジュールを入れる
RUN make && make install

# extension に追加する
RUN echo extension=zip.so >> /usr/local/lib/php.ini

追記: GitHub にすでに 7.4 対応版があるので、 sed する必要なさそう?あとで試します

最後に

ようやく Typed Property や FFI 使えるようになるのは夢が広がります💪

皆さんも最高の PHP 野良ビルドライフを送りましょう :tada:


Viewing all articles
Browse latest Browse all 113

Trending Articles