さて、UbuntuServerの20.04.4(LTS)に公式リポジトリ経由でOpenLiteSpeedの1.7.15とPHP8.1.2をインストールして動作成功したと記事を投稿しました。

その後にAchiLinuxで稼働させている本ブログWEBサーバのOpenLiteSpeed1.7.15についても、
PHP8.1.3を稼働させることができましたので、その方法について紹介します。

今回の方法は、OpenLiteSpeedの管理画面を使わずに行いました。
これまでOpenLiteSpeedの管理画面のツール経由で実施していましたが、
PHP8.1系になってからそのツールではエラーが出てしまい、一度もコンパイルに成功せず。

このままPHP8.1系が試せないのも、新しいモノ好きな筆者としては、そんな状況は許せません笑。
そこで、検証も兼ねて試しに手動でコンパイルしたところ・・・・。
なんと、ビルドできました笑

ちっ、OpenLiteSpeedのビルドツール側の問題か・・・・。

ArchLinuxだけでなく、Ubuntuでも検証実施してどちらもビルドできました。

そんなわけで、PHP8.1.3を手動でコンパイル、インストールする手順について紹介します。


PHPのダウンロード

PHP8.1.3をダウンロード

まずはPHPのソースコードをダウンロードします。

$ wget https://www.php.net/distributions/php-8.1.3.tar.gz

以下コマンドで解凍します。

$ tar xvzf php-8.1.3.tar.gz  

次に解凍後のディレクトリに入ります。

$ cd php-8.1.3

コンフィグの作成

以下コマンドでコンフィグを作成します。

$ ./configure -prefix=/usr/local/lsws/lsphp81 '--with-mysqli' '--with-zlib' '--enable-gd' '--enable-gd-jis-conv' '--enable-shmop' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-mbstring' '--with-iconv' '--with-pdo-mysql' '--enable-ftp' '--with-curl' '--enable-soap' '--enable-xml' '--with-openssl' '--enable-bcmath' '--enable-exif' '--with-jpeg' '--with-freetype' '--with-gettext' '--with-bz2' '--enable-litespeed' '--enable-opcache' '--with-zip' '--with-xpm'

コンフィグ作成が正常に完了すると以下のメッセージになります。

Generating files
configure: patching main/php_config.h.in
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

php-8.1.3のビルド

では次にビルドしていきます。

$ make

ここで30分程度待ちます。(※PCスペックにより時間は前後します。)

Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
clicommand.inc
invertedregexiterator.inc
pharcommand.inc
directorygraphiterator.inc
directorytreeiterator.inc
phar.inc

Build complete.
Don't forget to run 'make test'.

インストール

上記メッセージが出ればビルドは完了です。

いざ以下コマンドでインストールしていきましょう。

$ sudo make -k install

Installing shared extensions:     /usr/local/lsws/lsphp81/lib/php/extensions/no-debug-non-zts-20210902/
Installing PHP CLI binary:        /usr/local/lsws/lsphp81/bin/
Installing PHP CLI man page:      /usr/local/lsws/lsphp81/php/man/man1/
Installing PHP LiteSpeed binary:  /usr/local/lsws/lsphp81/bin/
Installing phpdbg binary:         /usr/local/lsws/lsphp81/bin/
Installing phpdbg man page:       /usr/local/lsws/lsphp81/php/man/man1/
Installing PHP CGI binary:        /usr/local/lsws/lsphp81/bin/
Installing PHP CGI man page:      /usr/local/lsws/lsphp81/php/man/man1/
Installing build environment:     /usr/local/lsws/lsphp81/lib/php/build/
Installing header files:          /usr/local/lsws/lsphp81/include/php/
Installing helper programs:       /usr/local/lsws/lsphp81/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/lsws/lsphp81/php/man/man1/
  page: phpize.1
  page: php-config.1
/home/osmaniax/php/php-8.1.3/build/shtool install -c ext/phar/phar.phar /usr/local/lsws/lsphp81/bin/phar.phar
ln -s -f phar.phar /usr/local/lsws/lsphp81/bin/phar
Installing PDO headers:           /usr/local/lsws/lsphp81/include/php/ext/pdo/

上記が終わったらもうひとつだけ不足するファイルを移動してやります。


fcgi-binへコピーとシンボリックリンクを張る

$ sudo cp /usr/local/lsws/lsphp81/bin/lsphp /usr/local/lsws/fcgi-bin/lsphp-8.1.3
$ sudo ln -s  /usr/local/lsws/fcgi-bin/lsphp-8.1.3 /usr/local/lsws/fcgi-bin/lsphp81

はい、これで必要なファイルの配置が終わり、インストールが完了です。

あとはOpenLiteSpeedの管理画面でPHP8.1.3を使えるように設定することで利用可能になります。



まとめ

今回はOpenLiteSpeedでPHP8.1.3を手動でコンパイルしてインストールする方法について
紹介しました。

やっと筆者のやりたかったことができて今回は満足度が高いですね。

何かの参考になれば幸いです。