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 a copy of the dynamic link library libphp5.so to the modules directory of the APACHE2 installation directory, and also need to Add the LoadModule statement 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 " " >/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.
The Nginx in the LNMP environment does not support PHP and requires FASTCGI to process requests for PHP. and PHP needs to php-fpm this component to support it.
Prior to php5.3.3 version php-fpm is in the form of a patch package, and php5.3.3 php-fpm only need to open this function in the installation php-fpm. This is the front, we then configure PHP to use the command--enable-fpm.
After the PHP-FPM function is turned on, we also need to configure PHP-FPM. In fact, the PHP-FPM configuration file in the installation of PHP, has provided us with a profile template. This template is/usr/local/etc/php-fpm.conf.default, as follows:
More/usr/local/etc/php-fpm.conf.default
All we need now is to copy the file and rename it to Php-fpm.conf, as follows:
Cp/usr/local/etc/php-fpm.conf.default/usr/local/etc/php-fpm.conf
In order for PHP-FPM to be started in a serviced form. We need to copy the/sapi/fpm/init.d.php-fpm file in the PHP installation directory. As follows:
CP./SAPI/FPM/INIT.D.PHP-FPM/ETC/INIT.D/PHP-FPM
With the above illustration, we can also see clearly that the PHP-FPM file currently does not have execute permissions. Give PHP-FPM Execute permissions and start PHP-FPM, as follows:
chmod a+x/etc/init.d/php-fpm
/ETC/INIT.D/PHP-FPM start
NETSTAT-TUNLP |grep 9000
With the above diagram, we can clearly see that PHP-FPM has started normally.
Note that the default listener for PHP-FPM is Port 9000.
Now let's configure Nginx to support PHP as follows:
Location ~. php$ {
root HTML;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}
Then, under Nginx's Web site root directory, the new index.php file contains the following:
vi/usr/local/nginx/html/index.php
Now to start Nginx, as follows:
/usr/local/nginx/sbin/nginx
NETSTAT-TUNLP |grep 80
After the Nginx is started, you can now visit the Web site as follows:
We can see it clearly with the figure above. PHP is currently installed successfully and successfully supports MySQL database. At the same time also with Nginx integration completed.
So far. This is the end of our php5.6 installation.