0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PHP8.5をソースからビルドする for RockyLinux 10.x

0
Last updated at Posted at 2026-10-10

はじめに

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

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

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

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

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

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

プログラム名 バージョン
JPEG v9f
FreeType 2.13.3
libPNG 1.6.46
zlib 1.3.1
m4 1.4.19
libGD 2.3.3
xml 2.13.5
imap(c-client) 2007f
libssh2 1.11.0
curl 8.11.1
tcl 9.0.1
SQLite 3.45.3
Oniguruma 6.9.10
libzip 1.11.3
libwp 1.5.0
sodium 1.0.20
icu4c 76.1
gmp 6.3.1
giflib 5.1.4

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

実践環境

環境 バージョン
PHP 8.4.2
OS RockeyLinux 9.5

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

dnf install -y libXpm-devel libX11-devel pam-devel libtiff-devel 
#dnf install gmp-devel
古いOSの場合
#Rocky Linux 8などコンパイラが古いとビルドできないので新しいコンパイラを用意
dnf install -y gcc-toolset-12
dnf install -y texinfo
source /opt/rh/gcc-toolset-12/enable

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

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

#JPEG
cd /usr/local/src/phpmodule
curl -LO http://www.ijg.org/files/jpegsrc.v10.tar.gz
tar xvzf jpegsrc.v10.tar.gz

#FreeType
curl -LO https://download.savannah.gnu.org/releases/freetype/freetype-2.14.3.tar.gz
tar xvzf freetype-2.14.3.tar.gz

#libPNG
curl -LO https://downloads.sourceforge.net/project/libpng/libpng16/1.6.44/libpng-1.6.44.tar.gz?ts=gAAAAABqydl6w9bSWbUKT2WrJ5AaFf9XohoyPpWCly0nK1HdDCjKu194ZPJqQYNMaDflN3OWDzPnDf9WVsc2qH_q0pSiV8nQPw%3D%3D&r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Flibpng%2Ffiles%2Flibpng16%2F1.6.44%2Flibpng-1.6.44.tar.gz%2Fdownload
tar xvzf libpng-1.6.44.tar.gz

#zlib
curl -LO https://zlib.net/zlib-1.3.2.tar.gz
tar xvzf zlib-1.3.2.tar.gz

#m4
curl -LO http://ftp.gnu.org/gnu/m4/m4-1.4.21.tar.gz
tar xvzf m4-1.4.21.tar.gz

#xml
curl -LO https://download.gnome.org/sources/libxml2/2.15/libxml2-2.15.4.tar.xz
tar xvJf libxml2-2.15.4.tar.xz

#libGD
curl -LO 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
#Patch入りミラーに変更
curl -LO https://github.com/uw-imap/imap/archive/refs/tags/patches-FD29-RPM.tar.gz
tar xvzf patches-FD29-RPM.tar.gz

#libssh2
curl -LO https://libssh2.org/download/libssh2-1.11.1.tar.gz
tar xvzf libssh2-1.11.1.tar.gz

#nghttp2
curl -LO https://github.com/nghttp2/nghttp2/releases/download/v1.70.0/nghttp2-1.70.0.tar.gz
tar xvzf nghttp2-1.70.0.tar.gz

#libpsl
cd /usr/local/src/phpmodule
curl -LO https://github.com/rockdaboot/libpsl/releases/download/0.23.3/libpsl-0.23.3.tar.gz
tar xvzf libpsl-0.23.3.tar.gz


#curl
curl -LO https://curl.se/download/curl-8.22.0.tar.gz
tar xvzf curl-8.22.0.tar.gz

#tcl
curl -LO https://downloads.sourceforge.net/project/tcl/Tcl/9.1.0/tcl9.1.0-src.tar.gz?ts=gAAAAABqyduXE4M15oeIG8X7FGtcpWIT6qkaWsYnVXd2sj1KUL58u-yYUGG9JsFCDnT6QDDuIA1mdb9CQRDXSD1lQLeKdiywbg%3D%3D&r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Ftcl%2Ffiles%2FTcl%2F9.1.0%2Ftcl9.1.0-src.tar.gz%2Fdownload
tar xvzf tcl9.1.0-src.tar.gz

#SQLite3
curl -LO https://www.sqlite.org/src/tarball/sqlite.tar.gz
tar xvzf sqlite.tar.gz

#Oniguruma
curl -LO https://github.com/kkos/oniguruma/archive/refs/tags/v6.9.10.tar.gz
tar xvzf v6.9.10.tar.gz

#libbzip2
cd /usr/local/src/phpmodule
curl -LO https://github.com/winlibs/libbzip2/archive/refs/tags/libbzip2-1.0.8-1.tar.gz
tar xvzf libbzip2-1.0.8-1.tar.gz

#libzip
curl -LO https://libzip.org/download/libzip-1.12.tar.gz
tar xvzf libzip-1.12.tar.gz

#libwebp
#https://developers.google.com/speed/webp/download?hl=ja
#https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html
curl -LO https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.6.0.tar.gz
tar xvzf libwebp-1.6.0.tar.gz

#sodium
curl -LO https://download.libsodium.org/libsodium/releases/libsodium-1.0.22.tar.gz
tar xvzf libsodium-1.0.22.tar.gz

#icu4c
cd /usr/local/src/phpmodule
curl -LO https://github.com/unicode-org/icu/archive/refs/tags/release-78.3.tar.gz
tar xvzf release-78.3.tar.gz

#GMP
curl -LO https://gmplib.org/download/gmp/gmp-6.3.0.tar.gz
tar xvzf gmp-6.3.0.tar.gz

#giflib
curl -L 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
curl -LO https://ftp.gnu.org/gnu/nettle/nettle-4.0.tar.gz
tar xvzf nettle-4.0.tar.gz
cd nettle-4.0
./configure --enable-mini-gmp
make -j 4
make install

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

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

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

#libffi
cd /usr/local/src/phpmodule
curl -LO https://github.com/libffi/libffi/archive/refs/tags/v3.8.0.tar.gz
tar xvzf v3.8.0.tar.gz
cd libffi-3.8.0
./autogen
./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
curl -LO https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.7.1.tgz
tar xvzf openldap-2.7.1.tgz 
cd openldap-2.7.1/

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

export LIBS="-ldl"
./configure \
--enable-ipv6 \
--enable-crypt \
--with-tls=openssl
#--with-tls=openssl
make depend
make -j 8
make install

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

#JPEG
cd /usr/local/src/phpmodule
cd jpeg-9f
./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.14.3
./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.44
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.3.2
./configure
make -j 4
make install


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


#libxml
cd /usr/local/src/phpmodule
cd libxml2-2.15.4
./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
cd imap-patches-FD29-RPM

#OpenSSL1.1.x or OepnSSL 3.x の場合のみ(3.4まで対応可能なことを確認済み)
#OpenSSLライブラリをみえるようにする
export LDFLAGS="-L/usr/local/ssl/lib"
export CPPFLAGS="-I/usr/local/ssl/include"
export CFLAGS="-I/usr/local/ssl/include"

#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.11.1
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

#libpsl / OpneLDAP時のみ必要
cd /usr/local/src/phpmodule
cd libpsl-0.23.3
./configure
make -j 4
make install

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

#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"
LD_LIBRARY_PATH=/usr/local/ssl/lib64:/usr/lib64:/lib64:/lib:/usr/local/lib:/usr/local/lib64
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/ssl/lib/pkgconfig

./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-ssl=/usr/local/ssl \
--with-nghttp2=/usr/local \
--with-test-httpd=/usr/local/apache2
#--with-openssl=/usr/local/ssl \ #このオプションは廃止
#openldapが入っている場合、以下を入れるとOpenLDAPを参照しない
#--disable-ldap \
#--disable-ldaps 

make -j 4
make install

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

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


#Oniguruma
cd /usr/local/src/phpmodule
cd onig-6.9.10
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.6.0
make -f makefile.unix
./configure
make 
make install

#libbzip2
cd /usr/local/src/phpmodule
cd libbzip2-libbzip2-1.0.8-1
make -f Makefile-libbz2_so
make install

#libzip
cd /usr/local/src/phpmodule
cd libzip-1.12
mkdir build
cd build
/usr/local/bin/cmake .. \
  -DOPENSSL_ROOT_DIR=/usr/local/ssl \
  -DCMAKE_INSTALL_PREFIX=/usr/local \
  -DCMAKE_INSTALL_RPATH="/usr/local/ssl/lib:/usr/local/ssl/lib64"
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.22
./configure
make -j 4
make install


#icu4c
cd /usr/local/src/phpmodule
cd icu-release-78.3/icu4c/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.3.0
./configure
make -j 6
make install

PHPをインストールする

cd /usr/local/src
curl -LO https://www.php.net/distributions/php-8.5.11.tar.gz
tar xvzf php-8.5.11.tar.gz
cd php-8.5.11

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


./configure \
--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-sodium=/usr/local/lib \
--enable-intl \
--with-gmp=shared \
--with-gmp=/usr/local \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-shmop \
#imapは、PHP8.4から除外されている
#--enable-opcache \
#--with-imap=/usr/local/src/phpmodule/imap-2007f \
#--with-imap-ssl=/usr/local/ssl \


 

#
#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 -j 8 
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

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?