[Ubuntu14.04] Build the PHP5 + Apache2 + Oracle environment and ubuntu14.04php5

Source: Internet
Author: User

[Ubuntu14.04] Build the PHP5 + Apache2 + Oracle environment and ubuntu14.04php5

RT

A recently developed project where the database uses oracle. Oracle itself supports Red Hat, which is not good for ubuntu. If ubuntu needs to install oracle, the system itself needs to do a lot of work such as disguise, so I only plan to use the oracle database on the remote server.

Local Environment:

Linux xxx-ThinkPad-T400 3.13.0-46-generic #75-Ubuntu SMP Tue Feb 10 15:24:04 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

PHP version: 5.5.9-1ubuntu4. 6


PHP does not provide oracle Database Management Extensions during installation. We need to download, compile, and install and configure it on our own.

Here I mainly refer to the following article:

https://help.ubuntu.com/community/PHPOracle
http://blog.sina.com.cn/s/blog_8f4fbe030100y5q3.html


There are many related tutorials on the internet, mainly divided into two categories, but the main ideas are as follows:

1. Download the installation packages of instantclient basic and instantclient sdk from the oracle official website;

2. decompress the package and create a soft link to the database file;

3. Download and compile php oci8.so

4. Configure PHP

The difference is that some download php oci8.so files directly, decompress the files and manually compile them, or use the pear command to download and automatically compile the files as instructed in the tutorial above.


The key point is that there will be many unexpected problems during the course of following the tutorial. Next I will write the tutorial according to my successful configuration process, then explain the problem and solution:

1. Solve the dependency problem:

sudo apt-get updatesudo apt-get upgrade
sudo apt-get install php5-dev build-essential php-pear libaio1
sudo apt-get install unzip make


2. Download the Instant Client from the oracle official website.

http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

The corresponding instantclient-basic-xxx.zip and instantclient-sdk-xxx.zip are downloaded separately.

3. decompress the package and create a soft link to the database file;

The processing of this step is very important. improper processing will cause the following compilation steps to fail.

3.1 decompress the file and remove the version numbers from the two folders. That is, instantclient and sdk. Then, the sdk folder is moved to the instantclient directory to coexist with other library files. Most of the other tutorials on the Internet do not describe the storage relationship between these two folders, or directly put them under the same level Directory, which leads to the failure to find the sdk during subsequent compilation. Here we must move the sdk folder to the instantclient directory. You cannot refer to other tutorials on the Internet.

3.2 Create a soft link to the library file, go to the instantclient directory, and create a soft link to the file (Other tutorials do not describe the storage location of the linked file ). Note: you cannot directly right-click the link to generate the library file:

ln -s libnnz12(version number).so libnnz.so
As shown above, the version information in the original library file is removed to generate the extension Library File Link without version information;

At the same time, we need to generate

ln -s libclntsh.so.12.1 libclntsh.so
ln –s libocci.so.12.1 libocci.so

After completing this step, we can move the entire oracle instantclient folder to our pre-arranged location. The recommended location is:

/usr/local/lib/

After the entire directory is copied, the directory is elevation:

sudo chmod 777 -R /usr/local/lib/instantclient/
Then configure some system constants that we may need next ,:

sudo vim /etc/environment
Add the following constant at the end of the file:

# Oracle Instant ClientLD_LIBRARY_PATH="/usr/local/lib/instantclient"TNS_ADMIN="/usr/local/lib/instantclient"ORACLE_BASE="/usr/local/lib/instantclient"ORACLE_HOME=$ORACLE_BASE

4. Download and compile oci8.so
sudo pecl install oci8

Next, the source code package of oci8 will be automatically downloaded and compiled. Then, you will be prompted to enter the relevant PATH variable of instantclient during the process: Enter

instantclient,/usr/local/lib/instantclient

After compilation, the system prompts:

Build process completed successfullyInstalling '/usr/lib/php5/20121212/oci8.so'install ok: channel://pecl.php.net/oci8-2.0.8configuration option "php_ini" is not set to php.ini locationYou should add "extension=oci8.so" to php.ini

If there are no similar prompts, congratulations, it must have been an error in this process. Let's assume that it has been smooth till now. Now we have successfully compiled the oci8.so extension. The next step is to allocate it to the use environment.

5. Configure PHP

We can directly enable extension in php. ini, but this operation is not recommended for PHP now, so we operate like this: Because my server is ubuntu + apache, the operation is as follows:

In/etc/php5/apache2/conf. d to create the oci8.ini file, apache2/conf. d In this directory, we will find that all the plug-ins are preceded by numbers. Here we don't need to worry about it, just ignore it:

sudo vim /etc/php5/apache2/conf.d/oci8.ini
Add the Enable oci8.so statement to the file,
extension=oci8.so
Restart apache

sudo /etc/init.d/apache2 restart

After the restart, create a file test. php In the root directory of the server and write the file:

<? Php phpinfo ()?>

Check whether the following content appears on the PHP page:

OCI8

OCI8 Support Enabled
OCI8 DTrace Support Disabled
OCI8 Version 2.0.8
Revision $ Id: f04114d4d67cffea4cdc2ed3b7f0229c2caa5016 $
Oracle Run-time Client Library Version 12.1.0.2.0
Oracle Compile-time Instant Client Version 12.1

If the following information is printed, the configuration is successful.


Below is the debug link:

1. The compilation process appears:

Configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
Solve the problem through the following article:

Http://blog.slogra.com/post-421.html
2. the database file cannot be found during compilation: configure: error: Oracle Instant Client libraries libnnz. so and libclntsh. so not found: Check whether you created a soft link through the command line.
3. checking Oracle Instant Client SDK header directory... configure: error: Oracle Instant Client SDK sdk header files not found whether your SDK folder is located in the instantclient directory.
4. ERROR: '/tmp/pear/temp/oci8/configure -- with-oci8 = instantclient,/usr/local/lib/instantclient' failed -- the path followed by the with-oci8 is correct, it should be the last directory we copied.

If you encounter other problems, you are welcome to leave comments for discussion.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.