3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[OCI]Oracle Linux 8にOracle Instant Client 21c+SQL*Plus+Apache 2.4+PHP 7.4+php-oci8-21cをセットアップしたときのメモ

Last updated at Posted at 2023-04-10

はじめに

Oracle Linux 8のComputeインスタンスに、
・Oracle Instant Client 21c+SQL*Plus
・Apache 2.4
・PHP 7.4
・php-oci8-21c
をセットアップした時のメモです。

1. Oracle Instant ClientとSQL*Plusのインストール

rootユーザにスイッチ

[opc@ol8 ~]$ sudo su -
[root@ol8 ~]

Oracle Instant ClientとSQL*Plusのインストール

dnf install -y oracle-instantclient-release-el8
dnf install -y oracle-instantclient-sqlplus

実行ログ

[root@ol8 ~]# dnf install -y oracle-instantclient-release-el8
Ksplice for Oracle Linux 8 (x86_64)                         28 MB/s | 2.1 MB     00:00    
MySQL 8.0 for Oracle Linux 8 (x86_64)                       29 MB/s | 2.8 MB     00:00    
MySQL 8.0 Tools Community for Oracle Linux 8 (x86_64)      6.1 MB/s | 426 kB     00:00    
MySQL 8.0 Connectors Community for Oracle Linux 8 (x86_64) 524 kB/s |  28 kB     00:00    
Oracle Software for OCI users on Oracle Linux 8 (x86_64)    73 MB/s |  74 MB     00:01    
Oracle Linux 8 BaseOS Latest (x86_64)                       73 MB/s |  57 MB     00:00    
Oracle Linux 8 Application Stream (x86_64)                  72 MB/s |  43 MB     00:00    
Oracle Linux 8 Addons (x86_64)                              49 MB/s | 6.9 MB     00:00    
Latest Unbreakable Enterprise Kernel Release 7 for Oracle   61 MB/s |  14 MB     00:00    
Dependencies resolved.
===========================================================================================
 Package                              Arch       Version       Repository             Size
===========================================================================================
Installing:
 oracle-instantclient-release-el8     x86_64     1.0-1.el8     ol8_baseos_latest      16 k

Transaction Summary
===========================================================================================
Install  1 Package

Total download size: 16 k
Installed size: 18 k
Downloading Packages:
oracle-instantclient-release-el8-1.0-1.el8.x86_64.rpm      948 kB/s |  16 kB     00:00    
-------------------------------------------------------------------------------------------
Total                                                      863 kB/s |  16 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                   1/1 
  Installing       : oracle-instantclient-release-el8-1.0-1.el8.x86_64                 1/1 
  Running scriptlet: oracle-instantclient-release-el8-1.0-1.el8.x86_64                 1/1 
  Verifying        : oracle-instantclient-release-el8-1.0-1.el8.x86_64                 1/1 

Installed:
  oracle-instantclient-release-el8-1.0-1.el8.x86_64                                        

Complete!
[root@ol8 ~]# dnf install -y oracle-instantclient-sqlplus
Oracle Instant Client 21 for Oracle Linux 8 (x86_64)        44 kB/s |  18 kB     00:00    
Dependencies resolved.
===========================================================================================
 Package                       Arch    Version           Repository                   Size
===========================================================================================
Installing:
 oracle-instantclient-sqlplus  x86_64  21.9.0.0.0-1.el8  ol8_oracle_instantclient21  711 k
Installing dependencies:
 oracle-instantclient-basic    x86_64  21.9.0.0.0-1.el8  ol8_oracle_instantclient21   53 M

Transaction Summary
===========================================================================================
Install  2 Packages

Total download size: 54 M
Installed size: 241 M
Downloading Packages:
(1/2): oracle-instantclient-sqlplus-21.9.0.0.0-1.el8.x86_6 8.8 MB/s | 711 kB     00:00    
(2/2): oracle-instantclient-basic-21.9.0.0.0-1.el8.x86_64.  61 MB/s |  53 MB     00:00    
-------------------------------------------------------------------------------------------
Total                                                       61 MB/s |  54 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                   1/1 
  Installing       : oracle-instantclient-basic-21.9.0.0.0-1.el8.x86_64                1/2 
  Running scriptlet: oracle-instantclient-basic-21.9.0.0.0-1.el8.x86_64                1/2 
  Installing       : oracle-instantclient-sqlplus-21.9.0.0.0-1.el8.x86_64              2/2 
  Running scriptlet: oracle-instantclient-sqlplus-21.9.0.0.0-1.el8.x86_64              2/2 
  Verifying        : oracle-instantclient-basic-21.9.0.0.0-1.el8.x86_64                1/2 
  Verifying        : oracle-instantclient-sqlplus-21.9.0.0.0-1.el8.x86_64              2/2 

Installed:
  oracle-instantclient-basic-21.9.0.0.0-1.el8.x86_64                                       
  oracle-instantclient-sqlplus-21.9.0.0.0-1.el8.x86_64                                     

Complete!
[root@ol8 ~]# 

環境変数の設定

cat <<'EOL' >> /etc/profile
export ORACLE_HOME=/usr/lib/oracle/21/client64/lib
export NLS_LANG=Japanese_Japan.AL32UTF8
export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
EOL

source /etc/profile

実行ログ

[root@ol8 ~]# cat <<'EOL' >> /etc/profile
> export ORACLE_HOME=/usr/lib/oracle/21/client64/lib
> export NLS_LANG=Japanese_Japan.AL32UTF8
> export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
> EOL
[root@ol8 ~]# source /etc/profile
[root@ol8 ~]# 

2. Apache、PHP7.4、php-oci8のインストール

Apache、PHP7.4、php-oci8のインストール

dnf config-manager --set-enabled ol8_developer
dnf module enable -y php:7.4 php-oci8:21c
dnf install -y php php-oci8-21c

実行ログ

[root@ol8 ~]# dnf config-manager --set-enabled ol8_developer
[root@ol8 ~]# dnf module enable -y php:7.4 php-oci8
Oracle Linux 8 Development Packages (x86_64)                76 MB/s |  80 MB     00:01    
Last metadata expiration check: 0:00:32 ago on Mon 10 Apr 2023 05:07:52 AM GMT.
Dependencies resolved.
===========================================================================================
 Package              Architecture        Version               Repository            Size
===========================================================================================
Enabling module streams:
 httpd                                    2.4                                             
 nginx                                    1.14                                            
 php                                      7.4                                             
 php-oci8                                 21c                                             

Transaction Summary
===========================================================================================

Complete!
[root@ol8 ~]# dnf install -y php php-oci8-21c
Last metadata expiration check: 0:00:55 ago on Mon 10 Apr 2023 05:07:52 AM GMT.
Dependencies resolved.
===========================================================================================
 Package          Arch   Version                                       Repository     Size
===========================================================================================
Installing:
 php              x86_64 7.4.30-1.module+el8.7.0+20800+8e29b882        ol8_appstream 1.5 M
 php-oci8-21c     x86_64 2.2.0-1.0.1.module+el8.5.0+20481+e337f400     ol8_developer  74 k
Installing dependencies:
 apr              x86_64 1.6.3-12.el8                                  ol8_appstream 129 k
 apr-util         x86_64 1.6.1-6.el8                                   ol8_appstream 105 k
 httpd            x86_64 2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5 ol8_appstream 1.4 M
 httpd-filesystem noarch 2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5 ol8_appstream  43 k
 httpd-tools      x86_64 2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5 ol8_appstream 110 k
 libxslt          x86_64 1.1.32-6.0.1.el8                              ol8_baseos_latest
                                                                                     250 k
 mod_http2        x86_64 1.15.7-5.module+el8.7.0+21029+de29ba63.4      ol8_appstream 155 k
 nginx-filesystem noarch 1:1.14.1-9.0.1.module+el8.0.0+5347+9282027e   ol8_appstream  25 k
 oracle-logos-httpd
                  noarch 84.5-1.0.1.el8                                ol8_baseos_latest
                                                                                      29 k
 php-common       x86_64 7.4.30-1.module+el8.7.0+20800+8e29b882        ol8_appstream 706 k
Installing weak dependencies:
 apr-util-bdb     x86_64 1.6.1-6.el8                                   ol8_appstream  24 k
 apr-util-openssl x86_64 1.6.1-6.el8                                   ol8_appstream  27 k
 php-cli          x86_64 7.4.30-1.module+el8.7.0+20800+8e29b882        ol8_appstream 3.1 M
 php-fpm          x86_64 7.4.30-1.module+el8.7.0+20800+8e29b882        ol8_appstream 1.6 M
 php-json         x86_64 7.4.30-1.module+el8.7.0+20800+8e29b882        ol8_appstream  74 k
 php-mbstring     x86_64 7.4.30-1.module+el8.7.0+20800+8e29b882        ol8_appstream 484 k
 php-opcache      x86_64 7.4.30-1.module+el8.7.0+20800+8e29b882        ol8_appstream 267 k
 php-pdo          x86_64 7.4.30-1.module+el8.7.0+20800+8e29b882        ol8_appstream 123 k
 php-xml          x86_64 7.4.30-1.module+el8.7.0+20800+8e29b882        ol8_appstream 174 k

Transaction Summary
===========================================================================================
Install  21 Packages

Total download size: 10 M
Installed size: 38 M
Downloading Packages:
(1/21): apr-1.6.3-12.el8.x86_64.rpm                        3.7 MB/s | 129 kB     00:00    
(2/21): oracle-logos-httpd-84.5-1.0.1.el8.noarch.rpm       796 kB/s |  29 kB     00:00    
(3/21): libxslt-1.1.32-6.0.1.el8.x86_64.rpm                5.8 MB/s | 250 kB     00:00    
(4/21): apr-util-openssl-1.6.1-6.el8.x86_64.rpm             11 MB/s |  27 kB     00:00    
(5/21): apr-util-bdb-1.6.1-6.el8.x86_64.rpm                1.9 MB/s |  24 kB     00:00    
(6/21): httpd-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.  61 MB/s | 1.4 MB     00:00    
(7/21): httpd-tools-2.4.37-51.0.1.module+el8.7.0+21029+de2  31 MB/s | 110 kB     00:00    
(8/21): mod_http2-1.15.7-5.module+el8.7.0+21029+de29ba63.4  40 MB/s | 155 kB     00:00    
(9/21): nginx-filesystem-1.14.1-9.0.1.module+el8.0.0+5347+ 416 kB/s |  25 kB     00:00    
(10/21): httpd-filesystem-2.4.37-51.0.1.module+el8.7.0+210 429 kB/s |  43 kB     00:00    
(11/21): php-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64  60 MB/s | 1.5 MB     00:00    
(12/21): php-common-7.4.30-1.module+el8.7.0+20800+8e29b882  58 MB/s | 706 kB     00:00    
(13/21): php-fpm-7.4.30-1.module+el8.7.0+20800+8e29b882.x8  66 MB/s | 1.6 MB     00:00    
(14/21): php-json-7.4.30-1.module+el8.7.0+20800+8e29b882.x 5.3 MB/s |  74 kB     00:00    
(15/21): apr-util-1.6.1-6.el8.x86_64.rpm                   483 kB/s | 105 kB     00:00    
(16/21): php-cli-7.4.30-1.module+el8.7.0+20800+8e29b882.x8  21 MB/s | 3.1 MB     00:00    
(17/21): php-pdo-7.4.30-1.module+el8.7.0+20800+8e29b882.x8  25 MB/s | 123 kB     00:00    
(18/21): php-xml-7.4.30-1.module+el8.7.0+20800+8e29b882.x8  40 MB/s | 174 kB     00:00    
(19/21): php-oci8-21c-2.2.0-1.0.1.module+el8.5.0+20481+e33  24 MB/s |  74 kB     00:00    
(20/21): php-opcache-7.4.30-1.module+el8.7.0+20800+8e29b88 2.0 MB/s | 267 kB     00:00    
(21/21): php-mbstring-7.4.30-1.module+el8.7.0+20800+8e29b8 1.5 MB/s | 484 kB     00:00    
-------------------------------------------------------------------------------------------
Total                                                       19 MB/s |  10 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                   1/1 
  Installing       : php-common-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64         1/21 
  Running scriptlet: httpd-filesystem-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.    2/21 
  Installing       : httpd-filesystem-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.    2/21 
  Installing       : apr-1.6.3-12.el8.x86_64                                          3/21 
  Running scriptlet: apr-1.6.3-12.el8.x86_64                                          3/21 
  Installing       : apr-util-bdb-1.6.1-6.el8.x86_64                                  4/21 
  Installing       : apr-util-openssl-1.6.1-6.el8.x86_64                              5/21 
  Installing       : apr-util-1.6.1-6.el8.x86_64                                      6/21 
  Running scriptlet: apr-util-1.6.1-6.el8.x86_64                                      6/21 
  Installing       : httpd-tools-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5.x86    7/21 
  Installing       : php-cli-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64            8/21 
  Installing       : php-json-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64           9/21 
  Installing       : php-mbstring-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64      10/21 
  Installing       : php-opcache-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64       11/21 
  Installing       : php-pdo-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64           12/21 
  Running scriptlet: nginx-filesystem-1:1.14.1-9.0.1.module+el8.0.0+5347+9282027e.   13/21 
  Installing       : nginx-filesystem-1:1.14.1-9.0.1.module+el8.0.0+5347+9282027e.   13/21 
  Installing       : php-fpm-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64           14/21 
  Running scriptlet: php-fpm-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64           14/21 
  Installing       : oracle-logos-httpd-84.5-1.0.1.el8.noarch                        15/21 
  Installing       : mod_http2-1.15.7-5.module+el8.7.0+21029+de29ba63.4.x86_64       16/21 
  Installing       : httpd-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5.x86_64      17/21 
  Running scriptlet: httpd-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5.x86_64      17/21 
  Installing       : libxslt-1.1.32-6.0.1.el8.x86_64                                 18/21 
  Installing       : php-xml-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64           19/21 
  Installing       : php-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64               20/21 
  Installing       : php-oci8-21c-2.2.0-1.0.1.module+el8.5.0+20481+e337f400.x86_64   21/21 
  Running scriptlet: httpd-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5.x86_64      21/21 
  Running scriptlet: php-oci8-21c-2.2.0-1.0.1.module+el8.5.0+20481+e337f400.x86_64   21/21 
  Running scriptlet: php-fpm-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64           21/21 
  Verifying        : libxslt-1.1.32-6.0.1.el8.x86_64                                  1/21 
  Verifying        : oracle-logos-httpd-84.5-1.0.1.el8.noarch                         2/21 
  Verifying        : apr-1.6.3-12.el8.x86_64                                          3/21 
  Verifying        : apr-util-1.6.1-6.el8.x86_64                                      4/21 
  Verifying        : apr-util-bdb-1.6.1-6.el8.x86_64                                  5/21 
  Verifying        : apr-util-openssl-1.6.1-6.el8.x86_64                              6/21 
  Verifying        : httpd-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5.x86_64       7/21 
  Verifying        : httpd-filesystem-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.    8/21 
  Verifying        : httpd-tools-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5.x86    9/21 
  Verifying        : mod_http2-1.15.7-5.module+el8.7.0+21029+de29ba63.4.x86_64       10/21 
  Verifying        : nginx-filesystem-1:1.14.1-9.0.1.module+el8.0.0+5347+9282027e.   11/21 
  Verifying        : php-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64               12/21 
  Verifying        : php-cli-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64           13/21 
  Verifying        : php-common-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64        14/21 
  Verifying        : php-fpm-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64           15/21 
  Verifying        : php-json-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64          16/21 
  Verifying        : php-mbstring-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64      17/21 
  Verifying        : php-opcache-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64       18/21 
  Verifying        : php-pdo-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64           19/21 
  Verifying        : php-xml-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64           20/21 
  Verifying        : php-oci8-21c-2.2.0-1.0.1.module+el8.5.0+20481+e337f400.x86_64   21/21 

Installed:
  apr-1.6.3-12.el8.x86_64                                                                  
  apr-util-1.6.1-6.el8.x86_64                                                              
  apr-util-bdb-1.6.1-6.el8.x86_64                                                          
  apr-util-openssl-1.6.1-6.el8.x86_64                                                      
  httpd-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5.x86_64                               
  httpd-filesystem-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5.noarch                    
  httpd-tools-2.4.37-51.0.1.module+el8.7.0+21029+de29ba63.5.x86_64                         
  libxslt-1.1.32-6.0.1.el8.x86_64                                                          
  mod_http2-1.15.7-5.module+el8.7.0+21029+de29ba63.4.x86_64                                
  nginx-filesystem-1:1.14.1-9.0.1.module+el8.0.0+5347+9282027e.noarch                      
  oracle-logos-httpd-84.5-1.0.1.el8.noarch                                                 
  php-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64                                        
  php-cli-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64                                    
  php-common-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64                                 
  php-fpm-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64                                    
  php-json-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64                                   
  php-mbstring-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64                               
  php-oci8-21c-2.2.0-1.0.1.module+el8.5.0+20481+e337f400.x86_64                            
  php-opcache-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64                                
  php-pdo-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64                                    
  php-xml-7.4.30-1.module+el8.7.0+20800+8e29b882.x86_64                                    

Complete!
[root@ol8 ~]# 

3. Apacheの起動と自動起動の設定

Apacheの起動

systemctl start httpd.service

実行ログ

[root@ol8 ~]# systemctl start httpd.service
[root@ol8 ~]#

Apacheの自動起動設定

systemctl enable httpd.service

実行ログ

[root@ol8 ~]# systemctl enable httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@ol8 ~]#

4. firewalldの設定

firewalldの設定

firewall-cmd --add-service=http  --zone=public --permanent
firewall-cmd --add-service=https --zone=public --permanent
firewall-cmd --reload
firewall-cmd --list-all --zone=public

実行ログ

[root@ol8 ~]# firewall-cmd --add-service=http  --zone=public --permanent
success
[root@ol8 ~]# firewall-cmd --add-service=https --zone=public --permanent
success
[root@ol8 ~]# firewall-cmd --reload
success
[root@ol8 ~]# firewall-cmd --list-all --zone=public
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens3
  sources: 
  services: dhcpv6-client http https ssh
  ports: 
  protocols: 
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
[root@ol8 ~]# 

5. SELinuxの設定変更

setsebool -P httpd_can_network_connect=1

実行ログ

[root@ol8 ~]# setsebool -P httpd_can_network_connect=1
[root@ol8 ~]#

6. 動作確認用ファイルの作成

Apacheの動作確認用HTMLファイルの作成

cat <<'EOL' >>/var/www/html/index.html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UTF-8">
    <title>test</title>
  </head>
  <body>
    <h1>やったぜ!</h1>
  </body>
</html>
EOL

cat /var/www/html/index.html

実行ログ

[root@ol8 ~]# cat <<'EOL' >>/var/www/html/index.html
> <!DOCTYPE html>
> <html lang="ja">
>   <head>
>     <meta charset="UTF-8">
>     <title>test</title>
>   </head>
>   <body>
>     <h1>やったぜ!</h1>
>   </body>
> </html>
> EOL
[root@ol8 ~]# cat /var/www/html/index.html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UTF-8">
    <title>test</title>
  </head>
  <body>
    <h1>やったぜ!</h1>
  </body>
</html>


[root@ol8 ~]# 

Apache+PHP連携の動作確認用PHPファイルの作成

cat <<'EOL' >>/var/www/html/info.php
<?php
echo phpinfo();
?>
EOL

cat /var/www/html/info.php

実行ログ

[root@ol8 ~]# cat <<'EOL' >>/var/www/html/info.php
> <?php
> echo phpinfo();
> ?>
> EOL
[root@ol8 ~]# cat /var/www/html/info.php
<?php
echo phpinfo();
?>
[root@ol8 ~]# 

7. Apacheの動作確認

以下のURLにブラウザからアクセス
http://<コンピュート・インスタンスのグローバルIPアドレス>/

スクリーンショット 2023-04-10 14.17.37.png

Apache+PHPの動作確認
以下のURLにブラウザからアクセス
http://<コンピュート・インスタンスのグローバルIPアドレス>/info.php

スクリーンショット 2023-04-10 14.18.11.png
oci8でページ内を検索し、oci8が有効化されているか確認
スクリーンショット 2023-04-10 14.18.45.png

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?