和6年能登半島地震により亡くなられた方々のご冥福をお祈りするとともに、被害に遭われた皆さまに対し、心よりお見舞い申し上げます。一日も早く被災地の安全が確保され、復旧が進む事を心よりお祈り申し上げます。

KVMのゲストOS(FreeBSD)にApacheインストール

KVMでは、ゲストOS用にvirbr0という仮想L2スイッチが自動作成されNAT接続されている。

アウトバウンドのみ通信許可・・・ゲストOSとホストOSを同じセグメントにしたい。

# ip addr show dev virbr0
3: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 52:54:00:c4:20:e3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever

ホストOS(Debian)の/etc/network/interfacesファイルを修正して、virbr0(仮想L2スイッチ)でゲストOS(FreeBSD)とホストOS(Debian)を同一セグメントに「ネットワークを共有」でブリッジ接続を行った。

そして、ゲストOS(FreeBSD)にApacheとPHPをインストールして、LAN内のWindowsPCからテストページを確認した。

ゲストOS(FreeBSD)にApacheインストール

Apacheのバージョン(インストール後に確認した)

# httpd -v
Server version: Apache/2.4.46 (FreeBSD)
# pkg install -y apache24
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 6 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        apache24: 2.4.46
        apr: 1.7.0.1.6.1_1
        curl: 7.72.0
        db5: 5.3.28_7
        jansson: 2.13.1
        libnghttp2: 1.41.0

Number of packages to be installed: 6

The process will require 84 MiB more space.
19 MiB to be downloaded.
[1/6] Fetching apache24-2.4.46.txz: 100%    5 MiB   5.3MB/s    00:01
[2/6] Fetching libnghttp2-1.41.0.txz: 100%  116 KiB 118.8kB/s    00:01
[3/6] Fetching curl-7.72.0.txz: 100%    1 MiB   1.3MB/s    00:01
[4/6] Fetching jansson-2.13.1.txz: 100%   44 KiB  44.7kB/s    00:01
[5/6] Fetching apr-1.7.0.1.6.1_1.txz: 100%  468 KiB 479.5kB/s    00:01
[6/6] Fetching db5-5.3.28_7.txz: 100%   12 MiB  12.9MB/s    00:01
Checking integrity... done (0 conflicting)
[1/6] Installing libnghttp2-1.41.0...
[1/6] Extracting libnghttp2-1.41.0: 100%
[2/6] Installing db5-5.3.28_7...
[2/6] Extracting db5-5.3.28_7: 100%
[3/6] Installing curl-7.72.0...
[3/6] Extracting curl-7.72.0: 100%
[4/6] Installing jansson-2.13.1...
[4/6] Extracting jansson-2.13.1: 100%
[5/6] Installing apr-1.7.0.1.6.1_1...
[5/6] Extracting apr-1.7.0.1.6.1_1: 100%
[6/6] Installing apache24-2.4.46...
===> Creating groups.
Using existing group 'www'.
===> Creating users
Using existing user 'www'.
[6/6] Extracting apache24-2.4.46: 100%
=====
Message from apr-1.7.0.1.6.1_1:

--
The Apache Portable Runtime project removed support for FreeTDS with
version 1.6. Users requiring MS-SQL connectivity must migrate
configurations to use the added ODBC driver and FreeTDS' ODBC features.
=====
Message from apache24-2.4.46:

--
To run apache www server from startup, add apache24_enable="yes"
in your /etc/rc.conf. Extra options can be found in startup script.

Your hostname must be resolvable using at least 1 mechanism in
/etc/nsswitch.conf typically DNS or /etc/hosts or apache might
have issues starting depending on the modules you are using.


- apache24 default build changed from static MPM to modular MPM
- more modules are now enabled per default in the port
- icons and error pages moved from WWWDIR to DATADIR

   If build with modular MPM and no MPM is activated in
   httpd.conf, then mpm_prefork will be activated as default
   MPM in etc/apache24/modules.d to keep compatibility with
   existing php/perl/python modules!

Please compare the existing httpd.conf with httpd.conf.sample
and merge missing modules/instructions into httpd.conf!

サービスとして有効にする。

# sysrc apache24_enable=yes
apache24_enable:  -> yes

Apache起動!

# service apache24 start
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.

ゲストOS(FreeBSD)にPHPインストール

PHPのバージョン(インストール後に確認した)

# php --version
PHP 7.4.12 (cli) (built: Nov  3 2020 01:13:53) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
# pkg install -y php74 php74-mysqli mod_php74
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 5 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        libargon2: 20190702
        mod_php74: 7.4.12
        pcre2: 10.35
        php74: 7.4.12
        php74-mysqli: 7.4.12

Number of packages to be installed: 5

The process will require 41 MiB more space.
7 MiB to be downloaded.
[1/5] Fetching php74-7.4.12.txz: 100%    4 MiB   4.2MB/s    00:01
[2/5] Fetching php74-mysqli-7.4.12.txz: 100%   41 KiB  42.1kB/s    00:01
[3/5] Fetching mod_php74-7.4.12.txz: 100%    1 MiB   1.5MB/s    00:01
[4/5] Fetching libargon2-20190702.txz: 100%   64 KiB  65.6kB/s    00:01
[5/5] Fetching pcre2-10.35.txz: 100%    1 MiB   1.3MB/s    00:01
Checking integrity... done (0 conflicting)
[1/5] Installing libargon2-20190702...
[1/5] Extracting libargon2-20190702: 100%
[2/5] Installing pcre2-10.35...
[2/5] Extracting pcre2-10.35: 100%
[3/5] Installing php74-7.4.12...
[3/5] Extracting php74-7.4.12: 100%
[4/5] Installing php74-mysqli-7.4.12...
[4/5] Extracting php74-mysqli-7.4.12: 100%
[5/5] Installing mod_php74-7.4.12...
[5/5] Extracting mod_php74-7.4.12: 100%
[activating module `php7' in /usr/local/etc/apache24/httpd.conf]
=====
Message from php74-mysqli-7.4.12:

--
This file has been added to automatically load the installed extension:
/usr/local/etc/php/ext-20-mysqli.ini
=====
Message from mod_php74-7.4.12:

--
******************************************************************************

Make sure index.php is part of your DirectoryIndex.

You should add the following to your Apache configuration file:

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

******************************************************************************

If you are building PHP-based ports in poudriere(8) or Synth with ZTS enabled,
add WITH_MPM=event to /etc/make.conf to prevent build failures.

******************************************************************************

サービスとして有効にする。

# sysrc php_fpm_enable=yes
php_fpm_enable:  -> yes

起動!

# service php-fpm start
Performing sanity check on php-fpm configuration:
[28-Nov-2020 20:30:45] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful

Starting php_fpm.

PHPモジュールを001_mod-php.confファイルに作成する。

# vi /usr/local/etc/apache24/modules.d/001_mod-php.conf

<IfModule dir_module>
  DirectoryIndex index.php index.html
  <FilesMatch "\.php$">
    SetHandler application/x-httpd-php
  </FilesMatch>
  <FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
  </FilesMatch>
</IfModule>

Apacheの構成をテストする。

# apachectl configtest
Performing sanity check on apache24 configuration:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.xxx.xxx. Set the 'ServerName' directive globally to suppress this message
Syntax OK

Apache再起動!

# apachectl restart
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.

公開ディレクトリに、index.htmlとphpinfo.phpファイルを作成する。

vi phpinfo.php

<?php phpinfo(); ?>
vi index.html

<html><body><h1>Hello World(*^^*)</h1></body></html>

LAN内のWindowsPCから、ゲストOS(FreeBSD)のipアドレスを入力して確認

コメント