Install PHP 7 in Ubuntu 16.04, ubuntu16.04

Source: Internet
Author: User

Install PHP 7 in Ubuntu 16.04, ubuntu16.04

Preface

Recently, the development environment needs to be re-installed after the system is changed to Ubuntu16.04, in fact, the default PHP version in the 16.04 source is 7.x, but the problem is that there is no OCI extension, and projects need to use the Oracle database.

Prepare the compiling environment

Because all compilation is too cumbersome and many dependencies may cause problems, we chose another solution to use apt-get for installation. You cannot use apt-get to compile your own files, which saves a lot of time. Some dependencies are really a headache.

On Ubuntu16.04, the default PHP version is 7.x. Since we want to use Apache2.4 + PHP, we can directly parse PHP after installing the following module.

sudo apt-get install php-dev libapache2-mod-php

In this way, the most basic modules are installed. If you need other modules, you can use apt-get to quickly install them. For example, you also need modules related to MySQL and mb_string.

sudo apt-get install php-mysql php-mbstring

This will automatically install the relevant modules.

Install Oracle Client

To compile the OCI extension, we need the Oracle Client. Here we download the Oracle Instant Client and selectInstant Client for Linux x86-64 basicDownload the version.

In addition, to compile OCI, you must alsoinstant client SDK Package, download and decompress the package, and merge it to the Base.

There are also installation steps at the end of the page. Here is a brief introduction.

  • Decompress the zip package and place it in a directory.
  • Create a proper link for the current version of Instant Client
  • Set Environment Variables
Sudo unzip instantclient-basic-linux.x64-12.1.0.2.0.zipsudo unzip instantclient-sdk-linux.x64-12.1.0.2.0.zipsudo mv instantclient_12_1 // opt/oracle/cd/opt/oracle/instantclient_12_1/# create a symbolic link sudo ln-s libclntsh. so.12.1 libclntsh. sosudo ln-s libocci. so.12.1 libocci. so # Open/etc/profile and add export LD_LIBRARY_PATH =/opt/oracle/instantclient_12_1: $ LD_LIBRARY_PATHexport PATH =/opt/oracle/instantclient_12_1: $ PATH # The last source, make the configuration take effect source/etc/profile

Download PHP source code

First, determine the version of PHP that has been installed. Because apt-get is used for installation, the version may not be the latest version on the PHP official website. You can view

php -v

Found that my installed version is 7.0.4, then we corresponding download PHP-7.0.4 version source code.

You can download the source code in two ways.

  1. Download the source code package from the official website
  2. Clone from GitHub Repository

The Download source code on the official website is very simple. Open the Download page of php.net and select the version to Download. You can also clone the specified version from the GitHub repository (or clone the version you want before checkout), as shown in

git clone -b PHP-7.0.4 https://github.com/php/php-src && cd php-src

Compile OCI8/PDO_OCI

After the above steps, we have entered the downloaded PHP source code root directory, so we start to compile.

Compile oci8

Go to the extended oci8 source code directory and use phpize

cd ext/oci8phpize./configure --with-oci8=instantclient,/opt/oracle/instantclient_12_1sudo make

After the above steps are completed, a modules folder should be generated, which contains the extension we want.

Compile pdo_oci

The procedure is the same as that for compiling oci8, but the configure parameter is different, so write it.

Cd.../../ext/pdo_ociphpize # specify the version number at the end./configure -- with-pdo-oci = instantclient,/opt/oracle/instantclient_12_1, 12.1 sudo make

The results are the same as above.

Use our compiled extensions

First, we need to know where the ext directory of the current PHP is.

php -i | grep "extension_dir"

What I show here isextension_dir => /usr/lib/php/20151012 => /usr/lib/php/20151012Then copy the compiled extension/usr/lib/php/20151012Lower

# First enter cp oci8.so/usr/lib/php/20151012cp pdo_oci.so/usr/lib/php/20151012 under the corresponding modules directory

Then we need to add related configuration items in php. ini. First, we need to know the location of php. ini.

p -i | grep "Configuration File"

The following information is printed:

Configuration File (php.ini) Path => /etc/php/7.0/cliLoaded Configuration File => /etc/php/7.0/cli/php.ini

In this way, we know the location of php. ini, but this is the configuration file of CLI (command line interface), we need to use Apache (CGI ). We found a directory named apache2 under the/etc/php/7.0/directory, which also contains the php. ini file. Then we edit php. ini under the directory of apache2.

sudo vim php.ini

Add

extension=oci8.soextension=pdo_oci.so

Restart Apache

systemctl restart apache2.service

Viewphpinfo()It is found that both OCI and PDO_OCI are installed. The installation is complete.

Linux tips

Some useful commands were found during installation and data query, and they were also recorded.

# Restart a service sudo systemctl restart apache2.service # view the status of a service sudo systemctl status apache2.service # view php-related modules (other similar) apt-cache search php-| less # View Details of a module apt-cache show package_name

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

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.