ubuntu 中利用 docker 搭建 php + oracle 开发环境

文章内索引
[隐藏]

利用 docker 部署 oracle 11g

安装 docker

拉取镜像

docker pull sath89/oracle-xe-11g

创建实例

docker run -d --restart always -p 8080:8080 -p 1521:1521 -v /etc/localtime:/etc/localtime:ro -v /my/oracle/data:/u01/app/oracle sath89/oracle-xe-11g

时间同步的参数详见: https://jerry.red/453/docker-容器与宿主机时间不同步的解决办法

连接信息

Connect database with following setting:

hostname: localhost
port: 1521
sid: xe
username: system
password: oracle
Password for SYS & SYSTEM:
oracle

Connect to Oracle Application Express web management console with following settings:

http://localhost:8080/apex
workspace: INTERNAL
user: ADMIN
password: oracle

镜像详情:https://hub.docker.com/r/sath89/oracle-xe-11g/,利用 daocloud.io 可加速拉取镜像。


安装 Oracle Instant Client

Install RPMs

  1. Download the Oracle Instantclient RPM files from http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html. Everyone needs either “Basic” or “Basic lite”, and most users will want “SQL*Plus” and the “SDK”.

  2. Convert these .rpm files into .deb packages and install using “alien” (“sudo apt-get install alien” if you don’t have it).

  3. For example, for version 12.1.0.2.0-1 for Linux x86_64 (64-bit):

alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
alien -i oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
alien -i oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
  1. Test your Instantclient install by using “sqlplus” or “sqlplus64” to connect to your database:
sqlplus system/oracle@//localhost:1521/xe

If you execute sqlplus and get “sqlplus: command not found”, see the section below about adding the ORACLE_HOME variable.

If sqlplus complains of a missing libsqlplus.so file, follow the steps in the section “Integrate Oracle Libraries” below.

If sqlplus complains of a missing libaio.so.1 file, run

sudo apt-get install libaio1

or, if you’re installing the 32 bit instant client on 64 bit,

sudo apt-get install libaio1:i386

Integrate Oracle Libraries

If oracle applications, such as sqlplus, are complaining about missing libraries, you can add it to the system library list create a new file as follows:

sudo vi /etc/ld.so.conf.d/oracle.conf && sudo chmod o+r /etc/ld.so.conf.d/oracle.conf

and add the oracle library path as the first line. For example,

/usr/lib/oracle/12.1/client64/lib/

Then run ldconfig:

sudo ldconfig

ORACLE_HOME

Many Oracle database applications look for Oracle software in the location specified in the environment variable ‘ORACLE_HOME’.

Typical workstations will only have one Oracle install, and will want to define this variable in a system-wide location.

sudo vi /etc/profile.d/oracle.sh && sudo chmod o+r /etc/profile.d/oracle.sh

Add the following:

export ORACLE_HOME=/usr/lib/oracle/12.1/client64

Alternatively, each user can define this in their ~/.bash_profile

Note: From Ubuntu 11.04 (confirmed in 11.04 and 14.04) sqlplus was not recognized as a command unless the following line was also included in the oracle.sh file:

export PATH=$PATH:$ORACLE_HOME/bin

更多详情:https://help.ubuntu.com/community/Oracle%20Instant%20Client


安装 php 扩展

sudo apt-get install php-dev php-pear build-essential libaio1
sudo pecl install oci8 # 出现提示直接回车
sudo echo "extension=oci8.so" >> /etc/php/7.x/mods-available/oci8.ini # 注意修改目录(php版本号),文件权限应为 `644`
sudo phpenmod oci8
sudo service apache2 restart

或直接下载对应编译版本,解压后放到 /usr/lib/php/编译日期/ 目录下(文件权限 644):
php/20151012php/20160303php/20170718

发表评论

电子邮件地址不会被公开。 必填项已用*标注

18 + 8 =