Home  >  Article  >  Operation and Maintenance  >  How to configure php to connect to the database under linux

How to configure php to connect to the database under linux

王林
王林Original
2019-10-17 14:12:414233browse

How to configure php to connect to the database under linux

1. Install oracle-instantclient

Download oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm

Download oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

Place it in the /usr/packages/ directory.

# rmp -ivh oracle-instantclient*

The /usr/lib/oracle/11.2/client/lib/ directory will be generated at this time.

2. Modify the /etc/ld.so.conf configuration file

Add the following content:

/usr/lib/oracle/11.2/client/lib/

Execute the command:

# ldconfig

3. Install oci8

Download the latest oci8 component

Download oci-2.0.8.tgz

Put it in /usr/packages/ Under contents.

# tar -xvzf oci-2.0.8.tgz

# cd oci-2.0.8

# /usr/local/php/bin/phpize (用phpize生成configure配置文件)

# ./configure --with-php-config=/usr/local/php/bin/php-config --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client/lib

# make && make install

After success, you will be informed that oci8.so has been successfully placed in the following directory.

4. Configure PHP to support OCI extension

Modify the php configuration file

# vi /usr/local/php/lib/php.ini文件

Append the following content after the extension item

extension=oci8.so

5. Restart the Apache service test

# apachectl restart

6. Test the database connection

Write oracle.php in the root directory of the site.

The code is as follows:

";
    ocilogoff($conn);
  }
?>

Enter in the browser address bar: http://192.168.1.131/oracle.php

Instructions: 192.168.1.131 is the server address, which directly points to the site and directory of the server Apache.

Display Connected Oracle Successd! indicates that the database connection is successful.

Recommended tutorial: Linux video tutorial

The above is the detailed content of How to configure php to connect to the database under linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn