Slime: php5.6 source installation and Apache integration

Source: Internet
Author: User
Tags sapi

This article by show according to Lin Feng to provide friendship sponsorship, starting in the mud row world.

Apache Support for PHP is supported by Apache's MOD_PHP5 module, which is different from Nginx. Nginx is through the third-party fastcgi processor to be able to parse PHP, about nginx and PHP integration, see "Slime: php5.6 source installation and PHP-FPM configuration and Nginx integration."

If the source code compiled to install PHP, you need to specify at compile time--with-apxs2=/usr/local/apache2/bin/apxs to tell the compiler through the Apache MOD_PHP5 module to provide the parsing of PHP.

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 in the httpd.conf configuration file to dynamically load the Libphp5.so module in order to enable Apache support for PHP.

PHP integration with Apache requires the following steps:

1. Install Libiconv Library

2. PHP Source Installation

3. Configure Apache to support PHP

4. Test PHP

First, install the Libiconv library

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

When PHP integrates with Apache, be sure to install the Libiconv library, or the system will error 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

Unzip the Libiconv library as follows:

TAR-XF libiconv-1.14.tar.gz

To install the Libiconv library, first review the installation Help information. As follows:

./configure--help

With help, 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 use/sbin/ldconfig to make it effective. As follows:

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

/sbin/ldconfig

If you do not do this, the system will error if you install PHP to 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, PHP source installation

For PHP source installation can refer to the "Slime: php5.6 source installation and PHP-FPM configuration and Nginx integration" article, 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 turn on the fastcgi function of PHP, that is to turn on php-fpm function.

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

--enable-mbstring means that the primary function of enabling the Mbstring Module Mbstring module is to detect and convert the encoding, providing a string function for the corresponding multibyte operation. At present PHP internal code only supports iso-8859-*, EUC-JP, UTF-8, the other encoding language is not able to display correctly in the PHP program, so we want to enable the Mbstring module.

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

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

Once the compilation is complete, let's make again. In make, we note that the-liconv parameter is added. If you do not add the-liconv parameter, the system will error in make 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

Use the following command:

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

Through, we can obviously see the Apache configuration file httpd enabled PHP support, but also the libphp5.so files copied to the Apache module directory.

Third, configure Apache to support the PHP

Once the PHP installation is complete, we can modify the Apache configuration file httpd.conf 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, where LoadModule php5_module modules/libphp5.so line, we see that the row already exists when we view the httpd.conf file. That's because when you install PHP, you add the. Now we just need to add AddType application/x-httpd-php. PHP line.

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

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

echo " " >/usr/local/apache2/htdocs/index.php

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

Iv. testing PHP

Once the above modifications are complete, we restart Apache using the following command:

/ETC/INIT.D/HTTPD Graceful

Note that this command can gracefully restart Apache.

Open the site as follows:

Through, we can obviously see that Apache has supported PHP.

The above describes the slime: php5.6 source installation and Apache integration, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.