LoginSignup
1
1

More than 1 year has passed since last update.

PHP8.2をインストールする(ソースからビルドする)for RockyLinux9

Posted at

はじめに

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

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

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

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

コンパイルオプションを適宜変更していただければ構いませんが、投稿で以下のライブラリが事前にインストールされている前提になっています。
インストール手順はリンクを参考にしてください。
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.2.4
OS RockeyLinux 9.1(CentOS 8.1/7.2/7.3/7.4も確認済み)

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

dnf install libXpm-devel
dnf install libX11-devel
dnf install pam-devel
dnf install libtiff-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.v9e.tar.gz
tar xvzf jpegsrc.v9e.tar.gz

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

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

#zlib
wget http://zlib.net/zlib-1.2.13.tar.gz
tar xvzf zlib-1.2.13.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.10.tar.gz
wget https://download.gnome.org/sources/libxml2/2.10/libxml2-2.10.3.tar.xz
tar xvJf libxml2-2.10.3.tar.xz

#libGD
wget 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-8.0.1.tar.gz
tar xvzf curl-8.0.1.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 --trust-server-names https://downloads.sourceforge.net/project/tcl/Tcl/8.6.13/tcl8.6.13-src.tar.gz?ts=gAAAAABkLASlgIWRe246MpgZCkadMxi20dNHaI2r4yUoqpWhepr1FV0dQ9dPiwmBzT7WDD6_W1E37c_aEncFJTRvsDXNaP4YsA%3D%3D&r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Ftcl%2Ffiles%2FTcl%2F8.6.13%2Ftcl8.6.13-src.tar.gz%2Fdownload
tar xvzf tcl8.6.13-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.8/onig-6.9.8.tar.gz
tar xvzf onig-6.9.8.tar.gz

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

#libwebp
wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.3.0.tar.gz
tar xvzf libwebp-1.3.0.tar.gz

#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

#PHP8.1はこれだった
#wget https://github.com/unicode-org/icu/releases/download/release-70-1/icu4c-70_1-src.tgz
#tar xvzf icu4c-70_1-src.tgz

#2022.04.10で71.1がリリースされいる
#wget https://github.com/unicode-org/icu/releases/download/release-71-1/icu4c-71_1-src.tgz

#2023.04.04
wget https://github.com/unicode-org/icu/releases/download/release-72-1/icu4c-72_1-src.tgz
tar xvzf icu4c-72_1-src.tgz


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

#giflib
wget https://github.com/mldbai/giflib/archive/refs/tags/v5.1.4.tar.gz
tar xvzf v5.1.4.tar.gz

-- OPEN LDAP連係時 --

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

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

#libunistring
cd /usr/local/src/phpmodule
wget https://ftp.gnu.org/gnu/libunistring/libunistring-1.0.tar.xz
tar xvJf libunistring-1.0.tar.xz
cd libunistring-1.0
./configure
make -j 4
make install

#libunbound
cd /usr/local/src/phpmodule
wget https://www.nlnetlabs.nl/downloads/unbound/unbound-1.16.1.tar.gz
tar xvzf unbound-1.16.1.tar.gz
cd unbound-1.16.1
./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.1/p11-kit-0.24.1.tar.xz
tar xvJf p11-kit-0.24.1.tar.xz
cd p11-kit-0.24.1
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 ???
#先にGMPがビルドされてることを確認する
cd /usr/local/src/phpmodule
wget https://www.gnupg.org/ftp/gcrypt/gnutls/v3.7/gnutls-3.7.6.tar.xz
tar xvJf gnutls-3.7.6.tar.xz
cd gnutls-3.7.6
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.3.tgz
tar xvzf openldap-2.6.3.tgz 
cd openldap-2.6.3/

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-9e
./configure --enable-shared
make -j 4
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.13.0
./configure --enable-static
make -j4 
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.39
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.13
./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.10
./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 or OepnSSL 3.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 -j 8
make install


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

#OpenSSLの場所を明示
CPPFLAGS="-I/usr/local/ssl/include" LDFLAGS="-L/usr/local/ssl/lib"
#OpenSSL3系は以下を参照
CPPFLAGS="-I/usr/local/ssl/include" LDFLAGS="-L/usr/local/ssl/lib64"

./configure \
--enable-http \
--enable-ftp \
--enable-file \
--enable-proxy \
--enable-cookies \
--enable-ipv6 \
--with-zlib=/usr/local \
--with-libssh2=/usr/local \
--disable-openssl-auto-load-config \
--with-openssl=/usr/local/ssl \ #OpenSSL 3系など新しい場合はこちら
#--with-ssl=/usr/local/ssl \   #opensslの古いバージョンはこちらを選択
#openldapが入っている場合、以下を入れるとOpenLDAPを参照しない
#--disable-ldap \
#--disable-ldaps 

make -j 4
make install

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

#SQLite3
cd /usr/local/src/phpmodule
cd sqlite
./configure \
--enable-pdo=shared \
--with-sqlite=shared \
--with-pdo-sqlite=shared \
--with-zlib
make -j 4
make install


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

#libgif
cd /usr/local/src/phpmodule
cd giflib-5.1.4
./configure
make -j 4
make install


#libwebp
cd /usr/local/src/phpmodule
cd libwebp-1.3.0
make -f makefile.unix
./configure
make 
make install



#libzip
cd /usr/local/src/phpmodule
cd libzip-1.9.2
mkdir build
cd build
/usr/local/bin/cmake ..
make
make test
make install
ln -s /usr/local/lib64/libzip.so.5 /usr/local/lib/libzip.so.5


#sodium
cd /usr/local/src/phpmodule
cd libsodium-1.0.18
./configure
make -j 4
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.1.8.tar.gz --no-check-certificate
tar xvzf php-8.1.8.tar.gz
cd php-8.1.8

cd /usr/local/src
wget https://www.php.net/distributions/php-8.2.4.tar.gz
tar xvzf php-8.2.4.tar.gz
cd php-8.2.4

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 php_module modules/libphp.so
の下に「 AddType application/x-httpd-php .php 」を記入する

httpd.copf
LoadModule php_module         modules/libphp.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
1
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
1