Hướng dẫn oracle-php-release-el7
Để kết nối được đến cơ sở dữ liệu Oracle từ CentOS 7, 8, bạn cần cài đặt Oracle InstantClient. Và bạn cũng cần phần mở rộng OCI8 để gọi từ PHP. Show
Nội dung chính
Cài đặt Oracle InstantClientVới el8 / CentOS 8 / stream / Rocky / AlmalinuxTrước hết, cần tải các gói cần thiết. $ cd /usr/local/src $ wget https://download.oracle.com/otn_software/linux/instantclient/215000/oracle-instantclient-basic-21.5.0.0.0-1.el8.x86_64.rpm $ wget https://download.oracle.com/otn_software/linux/instantclient/215000/oracle-instantclient-sqlplus-21.5.0.0.0-1.el8.x86_64.rpm $ wget https://download.oracle.com/otn_software/linux/instantclient/215000/oracle-instantclient-devel-21.5.0.0.0-1.el8.x86_64.rpm $ wget https://download.oracle.com/otn_software/linux/instantclient/215000/oracle-instantclient-jdbc-21.5.0.0.0-1.el8.x86_64.rpm Sau đó, cài đặt bằng lệnh sau. $ cd /usr/local/src $ dnf localinstall oracle* --nogpgcheck Với el7 / CentOS 7Bạn cũng cần tải các gói cần thiết trước. $ cd /usr/local/src $ wget https://download.oracle.com/otn_software/linux/instantclient/215000/oracle-instantclient-basic-21.5.0.0.0-1.x86_64.rpm $ wget https://download.oracle.com/otn_software/linux/instantclient/215000/oracle-instantclient-sqlplus-21.5.0.0.0-1.x86_64.rpm $ wget https://download.oracle.com/otn_software/linux/instantclient/215000/oracle-instantclient-devel-21.5.0.0.0-1.x86_64.rpm $ wget https://download.oracle.com/otn_software/linux/instantclient/215000/oracle-instantclient-jdbc-21.5.0.0.0-1.x86_64.rpm Rồi cài đặt bằng lệnh sau. $ cd /usr/local/src $ yum localinstall oracle* --nogpgcheck Cài đặt OCI8 qua lệnh PECLSau khi cài đặt Oracle InstantClient, bạn cần cài đặt phần mở rộng OCI8 để kết nối đến cơ sở dữ liệu Oracle từ PHP. Việc cài đặt phiên bản nào của OCI8 sẽ phụ thuộc vào phiên bản PHP bạn đang sử dụng. Bạn có hai cách để cài là dùng lệnh PECL hoặc tải package về và tự build bằng phpize và make. Trước hết, hãy tìm hiểu cách thứ nhất. Bạn gõ như sau. $ pecl install oci8 Nếu dùng PHP 7.x, thay vì $ pecl install oci8-2.2.0 Có một lưu ý, trong trường hợp bạn dùng tường lửa, bạn cần thiết lập proxy PEAR trước khi chạy lệnh PECL trên. $ pear config-set http_proxy http://my-proxy.example.com:80/ Cài đặt OCI8 dùng phpize và makeĐầu tiên, chuyển đến /usr/local/src. $ cd /usr/local/src Tải bản OCI8 tương ứng với phiên bản PHPPHP 7.x $ wget https://pecl.php.net/get/oci8-2.2.0.tgz PHP 8.0 $ wget https://pecl.php.net/get/oci8-3.0.1.tgz PHP 8.1 $ wget https://pecl.php.net/get/oci8-3.2.1.tgz Giải nén file vừa tải bằng $ tar -zxvf oci8-2.2.0.tgz $ cd oci8-2.2.0 BuildDùng Chạy phpize và configure. $ phpize $ ./configure Trong trường hợp bạn dùng php selector hay php-fpm, bạn cần cung cấp một đường dẫn cụ thể. Với php selector. $ /opt/alt/php74/usr/bin/phpize $ ./configure --with-php-config=/opt/alt/php74/usr/bin/php-conf Với php-fpm. $ /opt/alt/php-fpm74/usr/bin/phpize $ ./configure --with-php-config=/opt/alt/php-fpm74/usr/bin/php-config Ví dụ bên trên dành cho PHP 7.4. PHP 8.0 và PHP 8.1 cũng tương tự. Sau khi chạy phpize và configure, bạn cần chạy make. $ make && make install Config php/php-fpmSau khi cài OCI8 xong, bạn phải chỉnh sửa extension=oci8.so Với php-fpm, phải chỉnh sửa /etc/php-fpm.d/www.conf thêm dòng sau. env[LD_LIBRARY_PATH] = /usr/lib/oracle/21/client64/lib:$LD_LIBRARY_PATH Tiếp theo, hãy khởi động lại php/php-fpm. Bây giờ, bạn có thể sử dụng OCI8 để kết nối tới cơ sở dữ liệu Oracle được rồi. Nếu kiểm tra phpinfo sẽ thấy OCI8 đã enable. Nguồn
Table of Contents
About PHP for Oracle LinuxThis page describes PHP and related packages for current releases of Oracle Linux. For Oracle Linux 8, the packages are provided via AppStream modules and are covered under Oracle Linux support. Consult the Application Stream Module Life Cycle appendix in the Managing Software in Oracle Linux manual for support timelines. For Oracle Linux 7, these packages are published in developer repositories, for which support is limited to package installation assistance only. Available PHP Releases
Installation on Oracle Linux 7These are the steps to install PHP. Set up Required RepositoriesTo configure the yum repositories shown above on your system, install the repository setup packageoracle-php-release-el7. After installing this package, the default enabled repository is that for the latest available PHP release. To install the repository setup package for Oracle Linux 7:
Installing PHPThen, to install the latest available release of PHP on Oracle Linux 7: Updating PHPIf you have PHP already installed, and a newer release has been published, make sure you update oracle-php-release-el7 first.
Connecting PHP to Oracle Database with the PHP OCI8 ExtensionThe PHP OCI8 database extention enables access to Oracle Database with support for SQL, PL/SQL, bind variables, large object (LOB) types as well connection pooling and result caching features of Oracle Database. Read this blog post for a complete example connecting a PHP 7.4 application to Oracle Database. Installing PHP OCI8Each PHP release has its own repository on Oracle Linux yum server and each of those repositories also contains a corresponding RPM for
the OCI8 extension, built for a specific major release of Oracle Instant Client. These RPMs follow this naming scheme: php-oci8
About Oracle Instant ClientPHP OCI8 depends on Oracle Instant Client. Starting with Oracle Instant Client 21c, yum/dnf configuration files are delivered via the packages oracle-instantclient-release-el8 and oracle-instantclient-release-el7, respectively. Oracle Instant Client packages up to release 19c are in the ol7_oracle_instantclient and ol8_oracle_instantclient repositories, configured with release packages oracle-release-el7 and oracle-release-el8. Assuming you have enabled the repository for Oracle Instant Client appropriate for your Oracle Linux release, it will be installed as a dependency. More details about Oracle Instant Client on this yum server. Installing PHP on Oracle Linux 8 via AppStream ModulesOracle Linux 8 introduces the concept of Application Streams, where multiple versions of user-space components can be delivered and updated more frequently than the core operating system packages in RPM format or groups of related RPMs called Modules. Oracle Linux 8 offers several independently updated versions of PHP via Module Streams. For mode details, please refer to the documentation. To list available Module Streams for PHP:
To install PHP 7.4 :
Installing PHP OCI8 on Oracle Linux 8To install the PHP OCI8 on Oracle Linux 8, enable both the php:7.4 and the php-oci8 modules.
Getting HelpFor help with PHP on Oracle Linux, please visit the PHP space in the Oracle Developer Community. |