[Ubuntu14.04] build a PHP5 + Apache2 + Oracle environment

Source: Internet
Author: User
[Ubuntu14.04] build PHP5 + Apache2 + Oracle environment 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. Note that you cannot directly right-click it to generate the link to 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:

Check whether the following content is displayed 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 library file cannot be found during compilation:

Configure: error: Oracle Instant Client libraries libnnz. so and libclntsh. so not found

Check whether you have created a soft link through the command line.


3. checking Oracle Instant Client SDK header directory... configure: error: Oracle Instant Client 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 behind the with-oci8 is correct, it should be the directory we copied.



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

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.