LoginSignup
1
2

More than 1 year has passed since last update.

PHP8.0.xをインストールする(ソースからビルドする)for RockyLinux8.5

Last updated at Posted at 2021-10-24

はじめに

PHPは、様々なライブラリがあり大変便利ですが、コンパイル時にはそのライブラリを含めてビルドする必要があります。
PHP8とよく使うであろうライブラリ含めたコンパイルの一式の作業メモです。
処理部分をまとめていますので、必要に応じてコピペすればほぼ無操作で、PHP8が稼働する環境が作れます。

あらかじめApacheのインストールが必要です

Apacheのインストールに関しては以下を参考にしてあらかじめインストールが必要です。
Apache2.4をインストールする(ソースからコンパイル) for RockeyLinux 8.4 (systemd対応)

以下のライブラリの事前インストールが必要です。

コンパイルオプションを適宜変更していただければ構いませんが、投稿で以下のライブラリが事前にインストールされている前提になっています。
インストール手順はリンクを参考にしてください。
OpenSSL1.0
zlib

今回採用するライブラリ群

プログラム名 バージョン
JPEG v9d
FreeType 2.11.0
libPNG 1.6.37
zlib 1.2.11
m4 1.4.19
libGD 2.3.3
xml 2.9.11
curl curl-7.80
imap(c-client) 2007f
libssh2 1.10.0
SQLite 3360000
Oniguruma 6.9.7.1
libwp 1.2.1
sodium 1.0.18
icu4c 70

※必要に応じてMySQLやPostgreSQLも追加可能です

実践環境

環境 バージョン
PHP 8.0.12
OS RockeyLinux 8.4(CentOS 8.1/7.2/7.3/7.4も確認済み)

OS標準のバイナリをインストールする

xorg-x11-proto-devel-7.7-13.el7.noarch.rpm
libXpm-devel-3.5.11-3.el7.x86_64.rpm
libX11-devel-1.6.3-3.el7.x86_64.rpm
pam-devel-1.1.8-18.el8.x86_64.rpm

dnf install libXpm-devel
dnf install pam-devel
#dnf install gmp-devel

関係ライブラリをダウンロードする

#バイナリダウンロード
mkdir -p /usr/local/src/phpmodule
cd /usr/local/src/phpmodule

#JPEG
cd /usr/local/src/phpmodule
wget http://www.ijg.org/files/jpegsrc.v9d.tar.gz
tar xvzf jpegsrc.v9d.tar.gz

#FreeType
wget https://download.savannah.gnu.org/releases/freetype/freetype-2.11.0.tar.gz
tar xvzf freetype-2.11.0.tar.gz

#libPNG
wget --trust-server-names  https://downloads.sourceforge.net/project/libpng/libpng16/1.6.37/libpng-1.6.37.tar.gz?ts=gAAAAABhdQ7tRCnHqV9l3ru36RQVjY6cXHNZ4kX2tiCpS7gdJFlrLQ5ql9n-os2Q8JUd1ndQgkziQdUwvRJDUvOIbOQrIeHNzg%3D%3D&r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Flibpng%2Ffiles%2Flibpng16%2F1.6.37%2Flibpng-1.6.37.tar.gz%2Fdownload%3Fuse_mirror%3Djaist%26download%3D
tar xvzf libpng-1.6.37.tar.gz

#zlib
wget http://zlib.net/zlib-1.2.11.tar.gz
tar xvzf zlib-1.2.11.tar.gz

#m4
wget http://ftp.gnu.org/gnu/m4/m4-1.4.19.tar.gz
tar xvzf m4-1.4.19.tar.gz

#xml
wget ftp://xmlsoft.org/libxml2/libxml2-2.9.12.tar.gz
tar xvzf libxml2-2.9.12.tar.gz

#libGD
wget -O libgd-2.3.3.tar.gz https://github.com/libgd/libgd/releases/download/gd-2.3.3/libgd-2.3.3.tar.gz
tar xvzf libgd-2.3.3.tar.gz

#imap
#wget ftp://ftp.cac.washington.edu/imap/imap-2007f.tar.gz
#ミラーサイトを利用
wget http://ftp.ntua.gr/pub/net/mail/imap/imap-2007f.tar.gz
tar xvzf imap-2007f.tar.gz

#libssh2
wget https://www.libssh2.org/download/libssh2-1.10.0.tar.gz
tar xvzf libssh2-1.10.0.tar.gz

#curl
wget https://curl.se/download/curl-7.80.0.tar.gz
tar xvzf curl-7.80.0.tar.gz

#libtiff
#wget http://download.osgeo.org/libtiff/tiff-4.3.0.tar.gz
#tar xvzf tiff-4.3.0.tar.gz

#tcl
wget https://prdownloads.sourceforge.net/tcl/tcl8.6.12-src.tar.gz
tar xvzf tcl8.6.12-src.tar.gz

#SQLite3
wget https://www.sqlite.org/src/tarball/sqlite.tar.gz
tar xvzf sqlite.tar.gz

#Oniguruma
wget https://github.com/kkos/oniguruma/releases/download/v6.9.7.1/onig-6.9.7.1.tar.gz
tar xvzf onig-6.9.7.1.tar.gz

#libzip
wget https://libzip.org/download/libzip-1.6.1.tar.gz
tar xvzf libzip-1.6.1.tar.gz

#libwebp
wget https://github.com/webmproject/libwebp/archive/master.zip
unzip master.zip

#sodium
wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz
tar xvzf libsodium-1.0.18.tar.gz

#icu4c
#wget https://github.com/unicode-org/icu/releases/download/release-70-1/icu4c-70_1-src.tgz
#tar xvzf icu4c-70_1-src.tgz
#icu4c Ver70は、PHP8.12では競合起きてコンパイル出来ない
#https://bugs.php.net/bug.php?id=81592
wget https://github.com/unicode-org/icu/releases/download/release-69-1/icu4c-69_1-src.tgz
tar xvzf icu4c-69_1-src.tgz


#GMP
wget https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz
tar xvJf gmp-6.2.1.tar.xz

-- OPEN LDAP連係時 --

#libnettel
#※先にGMPをコンパイルすること
cd /usr/local/src/phpmodule
wget https://ftp.gnu.org/gnu/nettle/nettle-3.7.2.tar.gz
tar xvzf nettle-3.7.2.tar.gz
cd nettle-3.7.2
./configure --enable-mini-gmp
make -j 4
make install

#libtasn
cd /usr/local/src/phpmodule
wget https://ftp.gnu.org/gnu/libtasn1/libtasn1-4.17.0.tar.gz
tar xvzf libtasn1-4.17.0.tar.gz
cd libtasn1-4.17.0
./configure
make -j 4
make install 

#libunistring
cd /usr/local/src/phpmodule
wget https://ftp.gnu.org/gnu/libunistring/libunistring-0.9.10.tar.gz
tar xvzf libunistring-0.9.10.tar.gz
cd libunistring-0.9.10
./configure
make -j 4
make install

#libunbound
cd /usr/local/src/phpmodule
wget https://www.nlnetlabs.nl/downloads/unbound/unbound-1.13.2.tar.gz
tar xvzf unbound-1.13.2.tar.gz
cd unbound-1.13.2
./configure
make -j 4
make install

#libffi
cd /usr/local/src/phpmodule
wget https://github.com/libffi/libffi/releases/download/v3.4.2/libffi-3.4.2.tar.gz
tar xvzf libffi-3.4.2.tar.gz
cd libffi-3.4.2
./configure
make -j 4
make install


#p11-kit
cd /usr/local/src/phpmodule
wget https://github.com/p11-glue/p11-kit/releases/download/0.24.0/p11-kit-0.24.0.tar.xz
tar xvJf p11-kit-0.24.0.tar.xz
cd p11-kit-0.24.0
export PKG_CONFIG_PATH=/usr/local/ssl/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
./configure
make -j 4
make install


#GNU TLS ???
cd /usr/local/src/phpmodule
wget https://www.gnupg.org/ftp/gcrypt/gnutls/v3.6/gnutls-3.6.16.tar.xz
tar xvJf gnutls-3.6.16.tar.xz
cd gnutls-3.6.16
export PKG_CONFIG_PATH=/usr/local/ssl/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
./configure
make -j 4
make install


#OpenLDAP
cd /usr/local/src
wget  https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.6.0.tgz
tar xvzf openldap-2.6.0.tgz 
cd openldap-2.6.0/

export PKG_CONFIG_PATH=/usr/local/ssl/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
#export CPPFLAGS="-l/usr/local/ssl/include/openssl"
#export LDFLAGS="-L/iusr/local/ssl/lib:/usr/local/lib:/usr/lib"
#export C_INCLUDE_PATH=/usr/local/ssl/include
#export LD_LIBRARY_PATH=/usr/local/ssl/lib:/usr/local/lib:/usr/local/lib64

./configure \
--enable-ipv6 \
--enable-crypt \
--with-tls
#--with-tls=openssl
make
make install

各モジュールをコンパイルする

#JPEG
cd /usr/local/src/phpmodule
cd jpeg-9d
./configure --enable-shared
make
make install

#libtiff
#cd /usr/local/src/phpmodule
#cd tiff-4.3.0
#./configure
#make
#make install

#FreeType
cd /usr/local/src/phpmodule
cd freetype-2.11.0
./configure --enable-static
make
make install

#phpから参照できるようにシンボリックリンクを作成する
ln -s /usr/local/include/freetype2/freetype /usr/local/include/freetype
ln -s /usr/local/include/freetype2/ft2build.h /usr/local/include/ft2build.h


#libPNG
cd /usr/local/src/phpmodule
cd libpng-1.6.37
cp scripts/makefile.linux Makefile
./configure --prefix=/usr/local LDFLAGS="-L/usr/local/lib -lz"
make -j 4
make install


#zlib
cd /usr/local/src/phpmodule
cd zlib-1.2.11
./configure
make -j 4
make install


#m4
cd /usr/local/src/phpmodule
cd m4-1.4.19
./configure
make -j 4
make install


#libxml
cd /usr/local/src/phpmodule
cd libxml2-2.9.12
./configure --with-python=no
make -j 4
make install
ln -s /usr/local/include/libxml2/libxml /usr/local/include/libxml


#libGD
cd /usr/local/src/phpmodule
cd libgd-2.3.3
#cp scripts/makefile.linux Makefile
./configure \
--with-png=/usr/local \
--with-freetype=/usr/local \
--with-jpeg=/usr/local \
--with-xpm=/usr \
--with-libiconv-prefix=/usr/local \
--disable-werror
make -j 4
make install

##もし、libgdのmakeで「gdft.c:154:22: 致命的エラー: ft2build.h:」こける場合は、
##yum install fontconfig-devel
##を実行後、再度、configureからやり直す

#mcrypt
#cd /usr/local/src/phpmodule
#cd libmcrypt-2.5.8
#./configure
#make
#make install
#cd libltdl
#./configure --enable-ltdl-install
#make
#make install


#imap
#OPENSSLが1.1系の場合は以下のパッチを当てる
cd /usr/local/src/phpmodule
cd imap-2007f
wget https://raw.githubusercontent.com/openwrt/packages/master/libs/uw-imap/patches/010-imap-2007f-openssl-1.1.patch

パッチがない場合はこちらを利用する

010-imap-2007f-openssl-1.1.patch
cat > 010-imap-2007f-openssl-1.1.patch << EOF
From c3f68d987c00284d91ad6599a013b7111662545b Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Date: Fri, 2 Sep 2016 21:33:33 +0000
Subject: [PATCH] uw-imap: compile against openssl 1.1.0

I *think* I replaced access to cert->name with certificate's subject name. I
assume that the re-aranged C-code is doing the same thing. A double check
wouldn't hurt :)

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
 src/osdep/unix/ssl_unix.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/osdep/unix/ssl_unix.c b/src/osdep/unix/ssl_unix.c
index 3bfdff3..836e9fa 100644
--- a/src/osdep/unix/ssl_unix.c
+++ b/src/osdep/unix/ssl_unix.c
@@ -59,7 +59,7 @@ typedef struct ssl_stream {
 static SSLSTREAM *ssl_start(TCPSTREAM *tstream,char *host,unsigned long flags);
 static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags);
 static int ssl_open_verify (int ok,X509_STORE_CTX *ctx);
-static char *ssl_validate_cert (X509 *cert,char *host);
+static char *ssl_validate_cert (X509 *cert,char *host, char *cert_subj);
 static long ssl_compare_hostnames (unsigned char *s,unsigned char *pat);
 static char *ssl_getline_work (SSLSTREAM *stream,unsigned long *size,
                   long *contd);
@@ -210,6 +210,7 @@ static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags)
   BIO *bio;
   X509 *cert;
   unsigned long sl,tl;
+  char cert_subj[250];
   char *s,*t,*err,tmp[MAILTMPLEN];
   sslcertificatequery_t scq =
     (sslcertificatequery_t) mail_parameters (NIL,GET_SSLCERTIFICATEQUERY,NIL);
@@ -266,14 +267,19 @@ static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags)
   if (SSL_write (stream->con,"",0) < 0)
     return ssl_last_error ? ssl_last_error : "SSL negotiation failed";
                /* need to validate host names? */
-  if (!(flags & NET_NOVALIDATECERT) &&
-      (err = ssl_validate_cert (cert = SSL_get_peer_certificate (stream->con),
-               host))) {
-               /* application callback */
-    if (scq) return (*scq) (err,host,cert ? cert->name : "???") ? NIL : "";
+  if (!(flags & NET_NOVALIDATECERT)) {
+
+   cert_subj[0] = '\0';
+   cert = SSL_get_peer_certificate(stream->con);
+   if (cert)
+       X509_NAME_oneline(X509_get_subject_name(cert), cert_subj, sizeof(cert_subj));
+   err = ssl_validate_cert (cert, host, cert_subj);
+   if (err)
+       /* application callback */
+       if (scq) return (*scq) (err,host,cert ? cert_subj : "???") ? NIL : "";
                /* error message to return via mm_log() */
-    sprintf (tmp,"*%.128s: %.255s",err,cert ? cert->name : "???");
-    return ssl_last_error = cpystr (tmp);
+   sprintf (tmp,"*%.128s: %.255s",err,cert ? cert_subj : "???");
+   return ssl_last_error = cpystr (tmp);
   }
   return NIL;
 }
@@ -313,7 +319,7 @@ static int ssl_open_verify (int ok,X509_STORE_CTX *ctx)
  * Returns: NIL if validated, else string of error message
  */

-static char *ssl_validate_cert (X509 *cert,char *host)
+static char *ssl_validate_cert (X509 *cert,char *host, char *cert_subj)
 {
   int i,n;
   char *s,*t,*ret;
@@ -322,9 +328,9 @@ static char *ssl_validate_cert (X509 *cert,char *host)
                /* make sure have a certificate */
   if (!cert) ret = "No certificate from server";
                /* and that it has a name */
-  else if (!cert->name) ret = "No name in certificate";
+  else if (cert_subj[0] == '\0') ret = "No name in certificate";
                /* locate CN */
-  else if (s = strstr (cert->name,"/CN=")) {
+  else if (s = strstr (cert_subj,"/CN=")) {
     if (t = strchr (s += 4,'/')) *t = '\0';
                /* host name matches pattern? */
     ret = ssl_compare_hostnames (host,s) ? NIL :
-- 
2.9.3

EOF
## 「osdep.c:89:31: 致命的エラー: security/pam_appl.h: そのようなファイルやディレクトリはありません」が出る場合は、
## rpm -ivh pam-devel-1.1.8-18.el7.x86_64.rpm
## もしくは
## dnf install pam-devel
cd /usr/local/src/phpmodule
cd imap-2007f

#OpenSSL1.1.xの場合のみ
patch -p1 < 010-imap-2007f-openssl-1.1.patch
make lnp SSLTYPE=unix EXTRACFLAGS=-fPIC
y

#ソースをコピー
cp -p c-client/*.h /usr/include
cp c-client/c-client.a  /usr/lib/libc-client.a


#libssh2
cd /usr/local/src/phpmodule
cd libssh2-1.10.0
export LDFLAGS="-L/usr/local/ssl/lib"
export CPPFLAGS="-I/usr/local/ssl/include"
export CFLAGS="-I/usr/local/ssl/include"
./configure \
--with-openssl=/usr/local/ssl \
--with-libssl-prefix=/usr/local/ssl/include/openssl
make
make install


#curl
cd /usr/local/src/phpmodule
cd curl-7.80.0

#OpenSSLの場所を明示
CPPFLAGS="-I/usr/local/ssl/include" LDFLAGS="-L/usr/local/ssl/lib"

./configure \
--enable-http \
--enable-ftp \
--enable-file \
--enable-proxy \
--enable-cookies \
--with-zlib=/usr/local \
--with-ssl=/usr/local/ssl \
--with-libssh2=/usr/local

make -j 4
make install

#tcl
cd /usr/local/src/phpmodule
cd tcl8.6.12/unix
./configure
make -j 4
make install

#SQLite3
cd /usr/local/src/phpmodule
cd sqlite
./configure
make -j 4
make install


#Oniguruma
cd /usr/local/src/phpmodule
cd onig-6.9.7
autoreconf -vfi
./configure
make -j 4
make install


#libwebp
cd /usr/local/src/phpmodule
cd libwebp-master
./autogen.sh
./configure
make 
make install



#libzip
cd /usr/local/src/phpmodule
cd libzip-1.6.1
mkdir build
cd build
cmake ..
make
make test
make install


#sodium
cd /usr/local/src/phpmodule
cd libsodium-1.0.18
./configure
make
make install


#icu4c
cd /usr/local/src/phpmodule
cd icu/source
./configure \
--build=x86_64-redhat-linux-gnu \
--enable-release --enable-icu-config \
--enable-shared \
--enable-extras \
--enable-icuio
make
make install


#gmp
cd /usr/local/src/phpmodule
cd gmp-6.2.1
./configure
make -j 6
make install

PHPをインストールする

cd /usr/local/src
wget https://www.php.net/distributions/php-8.0.12.tar.gz --no-check-certificate
tar xvzf php-8.0.12.tar.gz
cd php-8.0.12

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/ssl/lib/pkgconfig

./configure \
--enable-opcache \
--enable-mbstring \
--enable-mbregex \
--with-apxs2=/usr/local/apache2/bin/apxs \
--enable-gd \
--with-freetype=/usr/local/src/phpmodule/freetype-2.10.1 \
--with-jpeg=/usr/local/lib \
--with-zlib=/usr/local/lib64 \
--with-expat=/usr/local \
--enable-gd-jis-conv \
--with-zip=/usr \
--with-curl=/usr/local \
--enable-bcmath \
--enable-sockets \
--enable-ftp \
--with-openssl=/usr/local/ssl \
--with-xpm=/usr \
--with-gettext \
--with-imap=/usr/local/src/phpmodule/imap-2007f \
--with-imap-ssl=/usr/local/ssl \
--with-sodium=/usr/local/lib \
--enable-intl \
--with-gmp=shared \
--with-gmp=/usr/local




#
#PGSQLを入れる場合
#--with-pgsql=/usr/local/pgsql \
#--with-pdo-pgsql=/usr/local/pgsql
#
#MySQL(MariaDB)を入れる場合
#--with-mysqli=mysqlnd \
#--with-pdo-mysql=mysqlnd \
#--with-mysql-sock=/usr/local/mysql/run/mariadb/mysql.sock \
#--enable-mysqlnd 
#
#OpenLDAPを入れる場合
#--with-ldap=/usr/local 


make
make install

DBに対応する場合

PostgreSQLに対応する場合

--with-pgsql=/usr/local/pgsql \
--with-pdo-pgsql=/usr/local/pgsql

MySQL対応する場合

--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql \
--with-mysql-sock=/usr/local/mysql/run/mariadb/mysql.sock \
--enable-mysqlnd 

設定を行う

cp php.ini-production /usr/local/lib/php.ini

httpd.confにphpファイルを実行されるように設定します

vi /usr/local/apache2/conf/httpd.conf

LoadModule php7_module modules/libphp7.so
の下に「AddType application/x-httpd-php .php」を記入する

httpd.copf
LoadModule php8_module        modules/libphp8.so
#↓追加する
AddType application/x-httpd-php .php

を追記して保存終了します。

phpinfoを出す

以下の内容を張り付けて保存終了

phpinfo
cat > /usr/local/apache2/htdocs/phpinfo.php << EOF
<?php
  date_default_timezone_set("Asia/Tokyo");
  phpinfo();
?>

EOF

Apacheを再起動後、phpinfo.phpを開き以下のような画面が出ればOK
image.png

参考文献

http://www.itkb.ro/kb/linux/patch-libiconv-pentru-glibc-216
https://travis-ci.org/libgd/libgd/jobs/151123674/config
https://github.com/libgd/libgd/issues/292

1
2
0

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
1
2