PHP: Source Configuration Install PHP Environment under Linux

```

Description: When setting up PHP environment, the source installation method failed, and the last yum cloud used was successfully installed (see another log for details), followed by a more detailed source installation method, which was first reloaded and recorded for later learning.

```

Install Configuration apache

Generally, apache environments already exist on linux servers, and you can skip this step if you have one.If you want to see if linux has apache installed, you can use the following command:

[root@localhost htdocs]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Aug 13 2013 17:29:28

[root@localhost htdocs]# apachectl -v
Server version: Apache/2.2.15 (Unix)
Server built:   Aug 13 2013 17:29:28
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

Both commands are line.Almost all linux versions come with apache, which is usually named httpd, not apache.

/etc/init.d/httpd is its startup script.

Sometimes we don't want to use our own apache, so we may need to remove it before installing our own.

The steps to delete are as follows:

1 View and httpd Related packages. 
# rpm -qa|grep httpd,
httpd-2.2.3-11.el5_2.centos.4

2 Then delete httpd: 
# rpm -e httpd

//Possible problems:
error: Failed dependencies:
httpd >= 2.2.0 is needed by (installed) gnome-user-share-0.10-6.el5.i386

3 There is also a dependent package that has not been deleted
# rpm -e gnome-user-share

4 Remove httpd
# rpm -e httpd
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

Download Address

http://httpd.apache.org/

I downloaded

httpd-2.2.31.tar.gz

Switch to the root user and use root for all subsequent operations.

new directory

mkdir /usr/local/apache2
  • 1

The installed apache2 will be installed in this folder.This directory can be created without actually creating a new one. It will also be created dynamically if it is not later compiled and installed

Alternatively, you can specify a directory under a user in the / home / directory.

Unzip, configure, compile and install

[root@localhost /]# tar -zxvf httpd-2.2.31.tar.gz 

[root@localhost httpd-2.2.31]#  ./configure --prefix=/usr/local/apache2 --enable-module=shared

[root@localhost httpd-2.2.31]# make
[root@localhost httpd-2.2.31]# make install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Once completed, the following

[root@localhost apache2]# pwd
/usr/local/apache2
[root@localhost apache2]# ll
//Total dosage 60
drwxr-xr-x.  2 root root  4096 9month  20 15:00 bin
drwxr-xr-x.  2 root root  4096 9month  20 15:00 build
drwxr-xr-x.  2 root root  4096 9month  20 15:00 cgi-bin
drwxr-xr-x.  4 root root  4096 9month  20 15:00 conf
drwxr-xr-x.  3 root root  4096 9month  20 15:00 error
drwxr-xr-x.  2 root root  4096 7month  16 2015 htdocs
drwxr-xr-x.  3 root root  4096 9month  20 15:00 icons
drwxr-xr-x.  2 root root  4096 9month  20 15:00 include
drwxr-xr-x.  4 root root  4096 9month  20 15:00 lib
drwxr-xr-x.  2 root root  4096 9month  20 15:00 logs
drwxr-xr-x.  4 root root  4096 9month  20 15:00 man
drwxr-xr-x. 14 root root 12288 7month  16 2015 manual
drwxr-xr-x.  2 root root  4096 9month  20 15:00 modules
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

Startup encountered an error:

[root@localhost bin]# ./apachectl start
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
  • 1
  • 2

To solve this problem, you need to edit the httpd.conf file (/apache2/conf/directory), found:

#ServerName www.example.com:80 
Modify to:
ServerName 127.0.0.1:80 or ServerName localhost:80

Then restart:

[root@localhost bin]# ./apachectl start
  • 1

Open your browser, enter the localhost address, and you will see that the boot was successful.

If the following error occurs at startup:

[root@localhost bin]# ./apachectl start
(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
  • 1
  • 2
  • 3
  • 4
  • 5

The reason for this error is that other services are using port 80.Use first
[root@localhost bin]# netstat -lnp|grep 80 
Viewing that process uses port 80.Or:
ps -ef|grep httpd 
Check to see if an httpd process is running.

Then kill it (sudo killall httpd, for example) and restart it.

Add php support

Edit httpd.conf file, find

LoadModule php5_module        modules/libphp5.so
  • 1

This default should be open, mainly under Find Confirmation.

Add the following line (note that there is a space before the number):

AddType application/x-httpd-php .php
  • 1

Install php

Download address:

http://php.net/

I downloaded

php-5.6.26.tar.gz

new directory

mkdir /usr/local/php
  • 1

Unzip, compile, install

[root@localhost /]# tar -zxvf php-5.6.26.tar.gz 

[root@localhost php-5.6.26]#  ./configure --prefix=/usr/local/php  --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc


[root@localhost php-5.6.26]# make clean
[root@localhost php-5.6.26]# make
[root@localhost php-5.6.26]# make test
[root@localhost php-5.6.26]# make install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

- with-config-file-path indicates the path to the configuration file (php.ini), which is important, and don't forget.

From other websites:
Note that there is a -with-apxs2=/usr/local/apache2/bin/apxs option, where apxs are generated when Apache is installed and apxs is a tool for compiling and installing extensions for the Apache HTTP server so that they can be loaded into the Apache server at run time using the LoadModule instructions provided by mod_so.My understanding is that this tool is used to dynamically load PHP modules into Apache

During the configure phase, an error was encountered:

checking for xml2-config path... 
configure: error: xml2-config not found. Please check your libxml2 installation
  • 1
  • 2

After running yum install libxml2 and then running yum install libxml2-devel, rerun the above. /configure command.

Will be under the source directory
Copy the php.ini-development file to the / usr/local/php/etc directory (note that it should match the value specified earlier for -with-config-file-path) and rename it php.ini

Set the default page accessed when the browser accesses the directory

Find the httpd.conf file, and in the / usr/local/apache2/conf/directory, find the IfModule dir_module, add index.php

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
  • 1
  • 2
  • 3

Restart Apache and create a new test.php under /usr/local/apache2/htdocs with the following code:

<?php
      phpinfo();
 ?>
  • 1
  • 2
  • 3

Open your browser and access localhost/test.php. Success:

Note that the red flag is the location of php.ini, which you will use later.

Modify the default site directory

The default site directory is:

/usr/local/apache2/htdocs
  • 1

Sometimes you need to change this directory, such as when my server changes this address to the / home/pony/inn_web directory.The steps are as follows:

Edit the httpd.conf file,
Locate the DocumentRoot and change the directory to:
/home/pony/inn_web 
find

Access oracle database support

php with oracle may be less common, but it's really used in the project, so let's get started.

Install instant client

instantclient is a simple client to oracle's database, downloading only the Basic and Devel rpm packages.

Download address:

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

I downloaded

oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm 
oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
  • 1
  • 2

install

[root@localhost /]# rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:oracle-instantclient11.########################################### [100%]
[root@localhost /]# rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:oracle-instantclient11.########################################### [100%]
[root@localhost /]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

Establish soft links

[root@localhost 11.2]# ln -s /usr/lib/oracle/11.2/client64/ /usr/lib/oracle/11.2/client

[root@localhost oracle]# ln -s /usr/include/oracle/11.2/client64/ /usr/include/oracle/11.2/client
  • 1
  • 2
  • 3
  • 4

Install oci

Oracle Call Interface (OCI) is the most comprehensive, high-performance Oracle database interface based on the native "C" language, which can provide all the functions of Oracle database.OCI provides the basis for building language-specific interfaces such as Oracle JDBC-OCI, ODP.Net, Oracle precompiler, Oracle ODBC, and Oracle C++ Call Interface (OCCI) drivers.Leading open source interfaces such as PHP OCI8 extensions, ruby-oci8, Perl DBD::oracle and Python cx_oracle are also used OCI.As a native interface to Oracle databases, OCI also enhances queries, statements, and calls issued within the core of Oracle databases.

Find the php source and enter the ext/pdo_oci directory.

phpize is used to dynamically add php extensions

[root@localhost pdo_oci]# /usr/local/php/bin/phpize CFLAGS="-I/usr/lib/oracle/11.2/client" CXXFLAGS="-I/usr/lib/oracle/11.2/client"
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
[root@localhost pdo_oci]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Configuration, Compile Installation

[root@localhost pdo_oci]# ./configure --with-pdo-oci=instantclient,/usr,11.2 --with-php-config=/usr/local/php/bin/php-config
[root@localhost pdo_oci]# make clean
[root@localhost pdo_oci]# make
[root@localhost pdo_oci]# make install
  • 1
  • 2
  • 3
  • 4

Edit the php.ini file, adding the following two items:

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/"
extension=pdo_oci.so
  • 1
  • 2

Note that the pdo_oci.so file does exist in the /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/directory

Restart apache, then the browser opens the previous test.php and drops down to find that oci has added successfully:

Code Samples

$tns = "(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.86.132)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )";

define('PDO_DB_DNS', "oci:dbname=".$tns);  //Database dns
define('PDO_DB_USER', 'test');      //Username
define('PDO_DB_PASSWORD', 'test'); //Logon Password


class PDOManage{

    private $_pdo = null;
    private static $_instance = null;

    /**
     * Construction method, private
     */
    private function __construct(){
        try{
            $this->_pdo = new PDO(PDO_DB_DNS, PDO_DB_USER, PDO_DB_PASSWORD);
            $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);//Exceptions can be thrown

        }catch (PDOException $e)
        {
            user_dump('SQL instance:'.$e->getMessage());
            exit($e->getMessage());
        }
    }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

Add php curl support

Curl is a powerful open source library that supports protocols such as http.If curl is used in your project, you need to add a curl extension.There is no need to download them individually, as long as they are compiled and configured.

windows seems to come with it because I ported a project to linux and found that some pages would fail:

Call to undefined function curl_init()
  • 1

Only know that linux needs to be installed separately.

Enter the ext/curl directory under the php source code to configure the installation:

[innpay@localhost curl]$ pwd
/home/innpay/php/soft/php-5.6.26/ext/curl
[innpay@localhost curl]$ 
[innpay@localhost curl]$ /home/inn
inn/    innpay/ 
[innpay@localhost curl]$ /home/innpay/php/php/bin/phpize 
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
[innpay@localhost curl]$ ./configure --with-curl=/usr/local/curl --with-php-config=/home/innpay/php/php/bin/php-config

[innpay@localhost curl]$ make
[innpay@localhost curl]$ make install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

Note - with-php-config is actually modified according to your PHP directory.

When the installation is complete, we are prompted to install the dynamic library in a directory:

I am

PHP installation directory/lib/php/extensions/no-debug-non-zts-20131226/
  • 1

The curl.so file can be found in this directory.

Edit php.ini file
Find the location preceded by pdo_oci.so and add a line:
extension = curl.so

Restart apache to take effect.

Add php openssl support

openssl is also used in the project, so add an openssl extension, similar to the one above.

[innpay@localhost openssl]$ mv config0.m4 config.m4
[innpay@localhost openssl]$ /home/innpay/php/php/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
[innpay@localhost openssl]$ 

[innpay@localhost openssl]$ ./configure --with-openssl --with-php-config=/home/innpay/php/php/bin/php-config  

[innpay@localhost openssl]$ make
[innpay@localhost openssl]$ make install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

Edit php.ini file
Find the location preceded by pdo_oci.so and add a line:
extension = openssl.so

Restart apache to take effect.

```

Attach a link to the original copy:

http://blog.csdn.net/pony_maggie/article/details/52758159

```

Keywords: PHP Oracle Apache curl

Added by raspberryh on Sun, 19 May 2019 04:37:59 +0300