Apache Integrated php5.6 method sharing _linux

Source: Internet
Author: User
Tags fpm install php php source code sapi

Apache Support for PHP is supported by the Apache MOD_PHP5 module, which is different from the nginx. Nginx is a Third-party fastcgi processor that can parse PHP.

If the source code is compiled and installed in PHP, you need to specify--WITH-APXS2=/USR/LOCAL/APACHE2/BIN/APXS at compile time to tell the compiler to provide parsing to PHP via the Apache MOD_PHP5 module.

While the last step of the PHP installation is make install, We will see that the dynamic link library libphp5.so is copied to the modules directory of the APACHE2 installation directory, and you also need to add loadmodule statements to the httpd.conf configuration file to dynamically load the Libphp5.so module in order to achieve Apache support for PHP.

The integration of PHP with Apache requires the following steps:

1. Install Libiconv Library

2, PHP source code installation

3, configure Apache so that it supports PHP

4. Test PHP

I. Installation of LIBICONV Library

The Libiconv library provides a ICONV command for applications that need to be converted to implement a conversion of one character encoding to another, such as it can convert UTF8 encoding to GB18030 encoding and vice versa.

When you integrate PHP with Apache, be sure to install the Libiconv library, otherwise the system will complain when make. The error message is as follows:

Make: * * * [sapi/cli/php] Error 1

/usr/bin/ld:cannot Find-liconv

Collect2:ld returned 1 exit status

Make: * * * [sapi/cli/php] Error 1

Now start the formal installation of the Libiconv library, first download the Libiconv library, as follows:

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

Extract the Libiconv library as follows:

TAR-XF libiconv-1.14.tar.gz

Install the Libiconv library to view installation Help information first. As follows:

./configure--help

With the help of the illustration above, we can see that the default installation path for the Libiconv library is/usr/local. Now start installing the Libiconv library as follows:

./configure--prefix=/usr/local

Make && make install

After the Libiconv library is installed, it is recommended that you add the/usr/local/lib library to the/etc/ld.so.conf file and then use/sbin/ldconfig to make it effective. As follows:

echo "/usr/local/lib" >>/etc/ld.so.conf

/sbin/ldconfig

If you do not perform this step, the system will complain when you install PHP execute make install. The error message is as follows:

/root/php-5.6.2/sapi/cli/php:error while loading shared libraries:libiconv.so.2:cannot open shared object File:no such File or directory

Second, the PHP source code installation

Download and compile the PHP command as follows:

wget http://mirrors.sohu.com/php/php-5.6.2.tar.gz

./configure--enable-fpm--enable-mbstring--with-mysql=/usr/local/mysql--with-iconv-dir=/usr/local--with-apxs2=/ Usr/local/apache2/bin/apxs

Note that the function of--ENABLE-FPM in the above command is to open the fastcgi function of PHP, that is, to open the PHP-FPM function.

--with-mysql=/usr/local/mysql is the ability to enable PHP to support MySQL,/usr/local/mysql is the MySQL database installation path.

--enable-mbstring indicates that the main function of enabling the Mbstring Module Mbstring module is to detect and convert the encoding, providing a string function for the corresponding multi-byte operation. At present, PHP internal coding only support iso-8859-*, EUC-JP, UTF-8, other coding language is not in the PHP program to display the correct, so we want to enable the Mbstring module.

--with-iconv-dir=/usr/local Specifies the location where PHP holds the Libiconv library.

--WITH-APXS2=/USR/LOCAL/APACHE2/BIN/APXS Specifies the location of PHP to find Apache.

After compiling, we'll come back to make. When make, we notice to add the-liconv parameter. If you do not add the-liconv parameter, the system will make an error in build compilation. The error message is as follows:

Generating phar.php

Php-5.3.16/sapi/cli/php:error while loading shared libraries:libiconv.so.2:cannot open Shared object file:no such file or directory

The following commands are used:

Make zend_extra_libs= '-liconv '

We can also add-liconv to the Zend_extra_libs line by modifying the makefile file. As follows:

VI Makefile

Make install

With the figure above, we can clearly see that the Apache profile httpd enables PHP support and also copies the libphp5.so files to the Apache module directory.

Three, configure Apache to enable it to support PHP

After the installation of PHP, we can modify the Apache configuration file httpd.conf to enable it to support PHP.

We only need to add the following two lines of code to the httpd.conf file:

LoadModule Php5_module modules/libphp5.so

AddType application/x-httpd-php. php

Note that the LoadModule php5_module modules/libphp5.so Row, which we see when we view the httpd.conf file, already exists. That's because when you install PHP, you add it. Now we just need to add AddType application/x-httpd-php. PHP lines.

Vi/usr/local/apache2/conf/httpd.conf

In addition, we need to modify Apache's default home page file and add index.php. The contents are as follows:

echo "<?php phpinfo ();? > ">/usr/local/apache2/htdocs/index.php

cat/usr/local/apache2/htdocs/index.php

Four, test PHP

After the above modifications, we restart Apache, using the following command:

/ETC/INIT.D/HTTPD Graceful

Note that the command can gracefully restart Apache.

Open the site as follows:

With the above diagram, we can clearly see that Apache already supports PHP.

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.