Build a PHP5 + Apache2 + Oracle environment in Ubuntu 14.04
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.small-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
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 update
Sudo 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 Client
LD_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 successfully
Installing '/usr/lib/php5/20121212/oci8.so'
Install OK: channel: // pecl.php.net/oci8-2.0.8
Configuration option "php_ini" is not set to php. ini location
You shoshould 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 and then add the Enable oci8.so statement in the file,
Extension = oci8.so and then restart apache
[Html] view plaincopyprint? View the CODE piece derived from my CODE piece on CODE
Sudo/etc/init. d/apache2 restart
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 as follows:
When compiling and installing Fileinfo for php, report configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
Solution:
Wget http://sourceforge.net/projects/re2c/files/re2c/0.13.5/re2c-0.13.5.tar.gz/download
Tar zxf re2c-0.13.5.tar.gz & cd re2c-0.13.5
./Configure
Make & make install
Then compile and install Fileinfo, And the re2c error will not be reported.
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.
Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)
Detailed php hd scanning PDF + CD source code + full set of teaching videos
Configure the php lnmp development environment in CentOS 6
Install the LAMP \ Vsftpd \ Webmin \ phpMyAdmin service and settings in Ubuntu 13.04
Compile and install LAMP in CentOS 5.9 (Apache 2.2.44 + MySQL 5.6.10 + PHP 5.4.12)
Source code for Web server architecture in RedHat 5.4 build the LAMP environment and application PHPWind
PHP details: click here
PHP: click here