LoginSignup
1
1

CentOS6.5(vagrant) に PHP8.2 をソースインストールする手順

Last updated at Posted at 2023-11-01

こんなケースなかなか無い気がしますが、やってみたので共有します。
実機では未検証で、vagrant の仮想環境のみで検証しました。
この記事ではインストールまでしか行っておらず、その後の動作確認等はバージョン出力以外は行っていません。
参考にした動画では行っているようですので、必要な場合はそちらをご覧ください。
もっと簡単に、yum など使って出来ればその方がよいと思います。出来るんですかね。

参考動画

CentOS 6 - Install php 8.1.6 ※韓国語です。

PHPのインストール部分時間メモ
・1度目 make 終わり 32:00 前後
・2度目 make 終わり 34:51 前後
・3度目 make 終わり 42:32 前後
・make install 終わり 49:36 前後

ほぼ、この動画の通りに行いました。
seomin さん、ありがとうございます。

検証環境

centOS6.5(vagrant/windows)

vagrant環境準備

こちらを参考にしました。ありがとうございます。
Qiita Vagrant入門から実践まで

手順

作成した vagrant の仮想環境に ssh ログインします。
vagrant up
vagrant ssh

以下を上から順に管理者権限にて実行していきます。
ソースをダウンロードしたのは /usr/local/lib 、インストール先は /usr/local としましたが、必要な場合、適宜ご変更下さい。


管理者権限になる

[vagrant-centos65 ~]# sudo su -

yum がエラーで実行できないので、yumを使用するための修正(URLを有効なものに置き換える)

[vagrant-centos65 ~]# sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\/mirrorlist.centos.org/g" /etc/yum.repos.d/CentOS-Base.repo

[vagrant-centos65 ~]# sed -i -e "s/^#baseurl=http:\/\/mirror.centos.org/baseurl=http:\/\/mirror.nsc.liu.se\/centos-store/g" /etc/yum.repos.d/CentOS-Base.repo

epel を使用するための修正

[vagrant-centos65 ~]# sed -i "s/mirrorlist=https/mirrorlist=http/" /etc/yum.repos.d/epel.repo

yum アップデート※かなり時間がかかる可能性あり

[vagrant-centos65 ~]# yum update

libxml2 2.9ダウンロードとインストール

[vagrant-centos65 ~]# wget https://download.gnome.org/sources/libxml2/2.9/libxml2-2.9.14.tar.xz --no-check-certificate

[vagrant-centos65 ~]# unxz libxml2-2.9.14.tar.xz

[vagrant-centos65 ~]# tar -xvf libxml2-2.9.14.tar

[vagrant-centos65 ~]# cd libxml2-2.9.14

[vagrant-centos65 ~]# ./configure \
--prefix=/usr/local/libxml2-2.9.14 \
--with-history \
--with-python=/usr/bin \
--docdir=/usr/local/libxml2-2.9.14/doc

[vagrant-centos65 ~]# make
[vagrant-centos65 ~]# make install

opensslダウンロードとインストール

[vagrant-centos65 ~]# wget https://www.openssl.org/source/openssl-1.1.1o.tar.gz --no-check-certificate

[vagrant-centos65 ~]# cd openssl-1.1.1o

[vagrant-centos65 ~]# ./Configure \
no-shared \
linux-x86_64 \
no-md2 \
no-mdc2 \
no-rc5 \
no-rc4 \
enable-ssl2 \
enable-ssl3 \
--prefix=/usr/local/openssl-1.1.1o

[vagrant-centos65 ~]# make
[vagrant-centos65 ~]# make install

sqliteダウンロードとインストール

[vagrant-centos65 ~]# wget https://www.sqlite.org/2022/sqlite-autoconf-3380500.tar.gz  --no-check-certificate

[vagrant-centos65 ~]# tar -xzf sqlite-autoconf-3380500.tar.gz
cd sqlite-autoconf-3380500

[vagrant-centos65 ~]# ./configure \
--prefix=/usr/local/sqlite3-3.38.5
[vagrant-centos65 ~]# make
[vagrant-centos65 ~]# make install

cURLダウンロードとインストール

[vagrant-centos65 ~]# wget https://curl.se/download/curl-7.83.0.tar.gz  --no-check-certificate
tar -xzf curl-7.83.0.tar.gz
cd curl-7.83.0

[vagrant-centos65 ~]# ./configure \
--prefix=/usr/local/curl-7.83.0 \
--with-ssl=/usr/local/openssl-1.1.1o
[vagrant-centos65 ~]# make
[vagrant-centos65 ~]# make install

鬼車ダウンロードとインストール

[vagrant-centos65 ~]# wget https://github.com/kkos/oniguruma/releases/download/v6.9.8/onig-6.9.8.tar.gz  --no-check-certificate
[vagrant-centos65 ~]# tar -xzf onig-6.9.8.tar.gz
[vagrant-centos65 ~]# cd onig-6.9.8

[vagrant-centos65 ~]# ./configure \
--prefix=/usr/local/onig-6.9.8
[vagrant-centos65 ~]# make
[vagrant-centos65 ~]# make install

libPNGダウンロードとインストール

[vagrant-centos65 ~]# wget https://download.sourceforge.net/libpng/libpng-1.6.37.tar.gz  --no-check-certificate

[vagrant-centos65 ~]# tar -xzf libpng-1.6.37.tar.gz

[vagrant-centos65 ~]# cd libpng-1.6.37

[vagrant-centos65 ~]# ./configure \
--prefix=/usr/local/libpng-1.6.37
--with-zlib-dir \
--with-zlib \
ZLIB_CFLAGS=-I/usr/local/zlib-1.2.13/include \
ZLIB_LIBS=-L/usr/local/zlib-1.2.13/lib
[vagrant-centos65 ~]# make
[vagrant-centos65 ~]# make install

zlib が無い場合、ダウンロードとインストール

[vagrant-centos65 ~]# yum install zlib zlib-devel

libgdダウンロードとインストール

[vagrant-centos65 ~]# wget https://github.com/libgd/libgd/releases/download/gd-2.3.3/libgd-2.3.3.tar.gz
tar -xzf libgd-2.3.3.tar.gz
cd libgd-2.3.3

[vagrant-centos65 ~]# ./configure \
--prefix=/usr/local/libgd-2.3.3 \
--with-png=/usr/local/libpng-1.6.37

cmakeダウンロードとインストール

[vagrant-centos65 ~]# wget https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-linux-x86_64.tar.gz  --no-check-certificate
[vagrant-centos65 ~]# tar -xzf cmake-3.23.1-linux-x86_64.tar.gz
mv cmake-3.23.1-linux-x86_64 /usr/local/cmake-3.23.1-linux-x86_64

libzip ダウンロードとインストール
※wget でインストールエラーとなったので、
https://libzip.org/download/libzip-1.8.0.tar.xz
からダウンロードし、vagrant の仮想環境に転送
転送方法はこちらの記事を参考にしました。
https://stmtk358.hatenablog.com/entry/2021/11/07/094239

[vagrant-centos65 ~]# unxz libzip-1.8.0.tar.xz
[vagrant-centos65 ~]# tar -xvf libzip-1.8.0.tar
[vagrant-centos65 ~]# cd libzip-1.8.0
/usr/local/cmake-3.23.1-linux-x86_64/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/libzip-1.8.0
[vagrant-centos65 ~]# make
[vagrant-centos65 ~]# make install

PHP8.2 ダウンロードとインストール
※ vagrantではメモリ不足でエラー発生したため、configure に --disable-fileinfo を追加しています。

[vagrant-centos65 ~]# wget https://www.php.net/distributions/php-8.2.11.tar.gz --no-check-certificate
[vagrant-centos65 ~]# tar -xzf php-8.2.11.tar.gz
[vagrant-centos65 ~]# cd php-8.2.11

[vagrant-centos65 ~]# ./configure \
--prefix=/usr/local/php-8.2.11 \
--with-config-file-path=/etc/php8 \
--with-config-file-scan-dir=/etc/php8/php.d \
--with-zlib-dir \
--enable-mbstring \
--with-curl \
--with-zlib \
--disable-rpath \
--disable-fileinfo \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--with-mhash \
--with-pdo-mysql \
--with-mysqli \
--with-openssl \
--with-fpm-user=apache \
--with-fpm-group=apache \
--enable-fpm \
--with-pdo-mysql \
--enable-ftp \
--enable-gd \
LIBXML_CFLAGS=-I/usr/local/libxml2-2.9.14/include/libxml2 \
LIBXML_LIBS=-L/usr/local/libxml2-2.9.14/lib \
OPENSSL_CFLAGS=-I/usr/local/openssl-1.1.1o/include \
OPENSSL_LIBS=-L/usr/local/openssl-1.1.1o/lib \
SQLITE_CFLAGS=-I/usr/local/sqlite3-3.38.5/include \
SQLITE_LIBS=-L/usr/local/sqlite3-3.38.5/lib \
CURL_CFLAGS=-I/usr/local/curl-7.83.0/include \
CURL_LIBS=-L/usr/local/curl-7.83.0/lib \
ONIG_CFLAGS=-I/usr/local/onig-6.9.8/include \
ONIG_LIBS=-L/usr/local/onig-6.9.8/lib \
GD_CFLAGS=-I/usr/local/libgd-2.3.3/include \
GD_LIBS=-L/usr/local/libgd-2.3.3/lib \
PNG_CFLAGS=-I/usr/local/libpng-1.6.37/include \
PNG_LIBS=-L/usr/local/libpng-1.6.37/lib \
LIBZIP_CFLAGS=-I/usr/local/libzip-1.8.0/include \
LIBZIP_LIBS=-L/usr/local/libzip-1.8.0/lib64

configure 後に生成される Makefile 内、EXTRA_LIBS の項目に以下を追記

-lxml2 -lcrypto -lssl -lsqlite3 -lcurl -lonig -lpng

バージョンを出してみる。

[root@vagrant-centos65 ~]# /usr/local/php-8.1.6/bin/php --version
PHP 8.1.6 (cli) (built: Oct 27 2023 06:50:53) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies

インストールできました。

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