Detailed explanation of building method of PHP+Oracle local development environment
- 2021-12-05 05:44:50
- OfStack
Installing instant client
First, download the rpm package or zip compressed package of basic and devel corresponding to the corresponding database version from https://www. oracle. com/technetwork/topics/linuxx86-64soft-092277. html. I choose rpm package here. Then install:
rpm -Uvh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
rpm -Uvh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
In this way, the instant client tool is installed. Next is oci8, an extension of PHP.
Installing oci8 extensions
The installation method of oci8 is described in detail in the official document of PHP, and the online address is http://php.net/manual/en/oci8.installation.php. I choose pecl installation here. Run the command directly:
pecl install oci8
Note that if you and I are also using PHP version 7.0 or above, then use the above command. If it is another version, you can see that the oci8 page of pecl has relevant instructions:
Use 'pecl install oci8-2.0.12' to install
for PHP 5.2 - PHP 5.6. Use 'pecl install oci8-1.4.10' to install for
PHP 4.3.9 - PHP 5.1
After you run the install command, you will be prompted for the instant client path. The original prompt is:
Please provide the path to the ORACLE_HOME directory.
Use 'instantclient,/path/to/instant/client/lib' if you're compiling
with Oracle Instant Client [autodetect] :
The default path is/usr/lib/oracle/11. 2/client64/lib. Note that to precede instantclient, the complete input is:
instantclient,/usr/lib/oracle/11.2/client64/lib
When I first installed, I didn't read it carefully, only saw the last autodetect and entered directly, which led to the failure of connecting to the database in the later test. After waiting for the installation, the last step is to add configuration extension=oci8. so or another. ini file in php. ini, and restart php-fpm
service php-fpm restart
Now, you can connect to the Oracle database, and the local development environment is set up.