如何在RedHat/CentOS上将PHP 7.x连接到Oracle数据库? [英] How do I connect PHP 7.x to Oracle database on RedHat / CentOS?
问题描述
我正在努力将PHP应用程序连接到Oracle数据库.在过去的一周中,我尝试了多种选择,但均未成功.
I am struggling to connect my PHP application to an Oracle database. I have tried multiple options over the last week with no success.
我设法安装了oci8扩展名,但未识别到oci_connect函数.
I have managed to install oci8 extension but the oci_connect function is not recognised.
请协助.
RedHat Enterprise Linux 7.6
PHP:7.3
甲骨文:12c
RedHat Enterprise Linux 7.6
PHP: 7.3
Oracle: 12c
推荐答案
已经花了一个多星期的时间来解决这个问题,下面是对最终解决方法的总结.我希望这对其他人有帮助.
Having struggled for over a week to figure this out, here is a summary of what ultimately worked. I hope this helps somebody else.
这些说明适用于RedHat/CentOS Linux安装.我的经验是,关于RedHat/CentOS的说明与其他Linux安装略有不同.避免使用Oracle指导...他们根本没有帮助!
These instructions apply to RedHat / CentOS Linux installations. My experience was that the instructions for RedHat / CentOS were slightly different to other Linux installations. AVOID the Oracle guidance... They did not help at all!
第一步: 我按照这个出色的网站上的说明安装了PHP 7.3和其他Remi rpm软件包: https://tecadmin.net/install-php7-on-centos7/
Step1: I followed the instructions on this excellent website to install PHP 7.3 and additional Remi rpm packages:https://tecadmin.net/install-php7-on-centos7/
步骤2:然后,我使用Remi存储库(请参阅步骤1)安装oci8扩展:
Step 2: I then used the Remi repository (see step 1) to install the oci8 extension:
$ sudo yum --enablerepo=remi-php73 install php-oci8
步骤3:现在,我们需要安装oracle Instant Client 18.3软件包.在以下网站上对此进行了很好的解释: https://qiita.com/tkprof/items/2a4eb868f45fb5759110
Step 3: We now need to install the oracle instant client 18.3 packages. This is very nicely explained on this website: https://qiita.com/tkprof/items/2a4eb868f45fb5759110
$ cd /etc/yum.repos.d
$ sudo wget http://yum.oracle.com/public-yum-ol7.repo
$ sudo wget http://yum.oracle.com/RPM-GPG-KEY-oracle-ol7
$ sudo rpm --import RPM-GPG-KEY-oracle-ol7
$ sudo yum-config-manager --enable ol7_oracle_instantclient
$ sudo yum install oracle-instantclient18.3-basic
$ sudo yum install oracle-instantclient18.3-devel
$ sudo yum install oracle-instantclient18.3-jdbc
$ sudo yum install oracle-instantclient18.3-sqlplus
$ sudo yum list oracle-instantclient*
第4步: 已在/usr/lib/oracle/18.3中创建了oracle文件,我们现在需要创建一个符号链接,以便在服务器运行时包括oracle文件:
Step 4: The oracle files have been created in /usr/lib/oracle/18.3 We now need to create a symlink so that the oracle files are included when the server is running:
$ sudo sh -c "echo /usr/lib/oracle/18.3/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf"
$ sudo ldconfig
第5步:重新启动服务器
Step 5: Restart the server
$ sudo systemctl stop httpd
$ sudo systemctl start httpd
步骤6:现在,我们可以创建一个简单的php文件来测试与Oracle的连接:
Step 6: We can now create a simple php file that tests the connection to Oracle:
<?php
$conn = oci_connect("username", "password", "//url/SID");
if (!$conn) {
echo "oci8 working! However the following errors occurred: <br>";
$m = oci_error();
echo $m['message'], "\n";
exit;
} else {
print "Connected to Oracle!";
}
// Close the Oracle connection
oci_close($conn);
如果出现系统错误,则说明安装无效.
If you get a system error then the installation has not worked.
这篇关于如何在RedHat/CentOS上将PHP 7.x连接到Oracle数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!