11.10/11.11/11.12 安裝PHP5 11.13 安裝PHP7

11.10-11.12 安裝PHP5

>PHP(Hypertext Preprocessor)英文超級文本預處理語言。PHP 是一種HTML內嵌式的語言,是一種在服務器端執行的嵌入HTML文檔的腳本語言。官網:www.php.net,能用PHP7就用PHP7php

 

準備安裝包

[root@cham002 src]# cd /usr/local/src

[root@cham002 src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
[root@cham002 src]# du -sh php-5.6.30.tar.gz 
19M	php-5.6.30.tar.gz


[root@cham002 src]# tar -zxvf php-5.6.30.tar.gz 

安裝PHP-5
[root@cham002 src]# cd php-5.6.30/
環境配置
[root@cham002 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif


#參數解析:
--prefix=/usr/local/php 指定安裝目錄
--with-apxs2=/usr/local/apache2.4/bin/apxs 該文件是Apache的一個工具,能夠將擴展模塊添加到Apache的module文件。
--with-config-file-path=/usr/local/php/etc 指定配置文件所在路徑
--with-mysql=/usr/local/mysql 指定mysql的路徑
--with-mysqli=/usr/local/mysql/bin/mysql_config
--with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config 
上面兩項參數是指定相關mysql庫!
--with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
#以上參數是指定PHP相關的一些模塊(通用)。

1報錯了!!!!!!!!!!!!!!!!!
configure: error: xml2-config not found. Please check your libxml2 installation.

[root@cham002 php-5.6.30]# echo $?
1
說明:缺乏xml2庫。

[root@cham002 php-5.6.30]# yum list |grep xml2
libxml2.x86_64                          2.9.1-6.el7_2.3                @anaconda
libxml2.i686                            2.9.1-6.el7_2.3                base     
libxml2-devel.i686                      2.9.1-6.el7_2.3                base     
libxml2-devel.x86_64                    2.9.1-6.el7_2.3                base     
libxml2-python.x86_64                   2.9.1-6.el7_2.3                base     
libxml2-static.i686                     2.9.1-6.el7_2.3                base     
libxml2-static.x86_64                   2.9.1-6.el7_2.3                base     
mingw32-libxml2.noarch                  2.9.3-1.el7                    epel     
mingw32-libxml2-static.noarch           2.9.3-1.el7                    epel     
mingw64-libxml2.noarch                  2.9.3-1.el7                    epel     
mingw64-libxml2-static.noarch           2.9.3-1.el7                    epel     
python-xml2rfc.noarch                   2.5.2-2.el7                    epel     
tinyxml2.x86_64                         2.1.0-2.20140406git6ee53e7.el7 epel     
tinyxml2-devel.x86_64                   2.1.0-2.20140406git6ee53e7.el7 epel     
xml2.x86_64                             0.5-7.el7                      epel     


[root@cham002 php-5.6.30]# yum install -y libxml2-devel
已加載插件:fastestmirror

再次configure
[root@cham002 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

2再次報錯!!!!!!
configure: error: Cannot find OpenSSL's <evp.h>
[root@cham002 php-5.6.30]# echo $?
1
說明:缺乏OpenSSL's。

[root@cham002 php-5.6.30]# yum install -y openssl-devel
已加載插件:fastestmirror

再次configure
[root@cham002 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

3再次報錯!!!!
configure: error: Please reinstall the BZip2 distribution
說明:從新安裝BZip2。

[root@cham002 php-5.6.30]# yum install -y bzip2-devel
已加載插件:fastestmirror


再次configure
[root@cham002 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

4再次報錯!!!
configure: error: jpeglib.h not found.
說明:缺乏jpeg庫。

[root@cham002 php-5.6.30]# yum install -y jpeglib-devel
已加載插件:fastestmirror

再次configure
[root@cham002 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

5再次報錯!!!
configure: error: png.h not found.
說明:缺乏png庫。

[root@cham002 php-5.6.30]# yum list |grep png
libpng.x86_64                             2:1.5.13-7.el7_2             @anaconda
libpng.i686                               2:1.5.13-7.el7_2             base     
libpng-devel.i686                         2:1.5.13-7.el7_2             base     
libpng-devel.x86_64                       2:1.5.13-7.el7_2             base     
libpng-static.i686                        2:1.5.13-7.el7_2             base     
libpng-static.x86_64                      2:1.5.13-7.el7_2             base     
libpng12.i686                             1.2.50-10.el7                base     
libpng12.x86_64                           1.2.50-10.el7                base     
libpng12-devel.i686                       1.2.50-10.el7                base     
libpng12-devel.x86_64                     1.2.50-10.el7                base     
mingw32-libpng.noarch                     1.6.21-1.el7                 epel     
mingw32-libpng-static.noarch              1.6.21-1.el7                 epel     
mingw64-libpng.noarch                     1.6.21-1.el7                 epel     
mingw64-libpng-static.noarch              1.6.21-1.el7                 epel     
optipng.x86_64                            0.7.4-4.el7                  base     
pngcrush.x86_64                           1.7.59-4.el7                 base     
pnglite.x86_64                            0.1.17-1.el7.8               epel     
pnglite-devel.x86_64                      0.1.17-1.el7.8               epel     
pngnq.x86_64                              1.1-9.el7                    base     
pngquant.x86_64                           2.7.2-1.el7                  epel     
python-pypng.noarch                       0.0.16-1.el7                 epel     
texlive-dvipng.noarch                     2:svn26689.1.14-38.el7       base     
texlive-dvipng-bin.x86_64                 2:svn26509.0-38.20130427_r30134.el7
texlive-dvipng-doc.noarch                 2:svn26689.1.14-38.el7       base     
[root@cham002 php-5.6.30]# yum libpng-devel
已加載插件:fastestmirror
沒有該命令:libpng-devel。請使用 /usr/bin/yum --help


再次configure
[root@cham002 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

6再次報錯!!
configure: error: freetype-config not found.
說明:缺乏freetype庫。

[root@cham002 php-5.6.30]# yum install -y freetype-devel
已加載插件:fastestmirror

再次configure
[root@cham002 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

7再次報錯!!
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
說明:缺乏mcrypt庫。注意這包是在擴展源裏面~~~~若是沒有安裝須要先安裝yum install -y epel-release
!

[root@cham002 php-5.6.30]# yum list |grep mcrypt
libmcrypt.x86_64                          2.5.8-13.el7                 epel     
libmcrypt-devel.x86_64                    2.5.8-13.el7                 epel     
libtomcrypt.x86_64                        1.17-26.el7                  extras   
libtomcrypt-devel.x86_64                  1.17-26.el7                  extras   
libtomcrypt-doc.noarch                    1.17-26.el7                  extras   
mcrypt.x86_64                             2.6.8-11.el7                 epel     
php-mcrypt.x86_64                         5.4.16-7.el7                 epel     
[root@cham002 php-5.6.30]# yum install -y libmcrypt-devel
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile

再次configure
[root@cham002 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif


[root@cham002 php-5.6.30]# echo $?
0

環境配置完成!python

 

編譯和安裝

[root@cham002 php-5.6.30]# make
這一步時間會長一點
[root@cham002 php-5.6.30]# echo $?
0
[root@cham002 php-5.6.30]# make install
[root@cham002 php-5.6.30]# echo $?
0
[root@cham002 php-5.6.30]# ls /usr/local/php/
bin  etc  include  lib  php
核心的二進制文件在這個目錄下
[root@cham002 php-5.6.30]# ls /usr/local/php/bin/
pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize

安裝完成!mysql

PHP工做原理

將PHP的配置文件移動到./configure時指定的目錄:git

[root@cham002 php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini

PHP在系統中是做爲Apache的一個模塊被調用的,因此不用執行名啓動該PHP。sql

查看Apache的模塊:apache

# /usr/local/apache2.4/bin/apachectl -M
……dir_module (shared)
 alias_module (shared)
 php5_module (shared)

說明: 安裝完成PHP後會在Apache中自動添加相應模塊,同時在Apache配置文件/usr/local/apache2.4/conf/httpd.conf中也會自動添加相應配置內容。服務器

 

11.13 安裝PHP7

[root@cham002 src]# cd ..

[root@cham002 src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

[root@cham002 src]# tar jvxf php-7.1.6.tar.bz2 


環境配置
[root@cham002 src]# cd php-7.1.6/

[root@cham002 php-7.1.6]#  ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc  --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
注:次數與PHP-5的主要差別就是沒有「--with-mysql」選項。

[root@cham002 php-7.1.6]# echo $?
0
[root@cham002 php-7.1.6]# make
[root@cham002 php-7.1.6]# echo $?
0
[root@cham002 php-7.1.6]# make install
[root@cham002 php-7.1.6]# echo $?
0

[root@cham002 php-7.1.6]# ls /usr/local/apache2.4/modules/libphp
libphp5.so  libphp7.so  
[root@cham002 php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so
/usr/local/apache2.4/modules/libphp7.so
[root@cham002 php-7.1.6]# du -sh !$
du -sh /usr/local/apache2.4/modules/libphp7.so
37M	/usr/local/apache2.4/modules/libphp7.so

工做原理

將PHP的配置文件移動到./configure時指定的目錄:如php5php7

查看Apache加載的PHP模塊: dom

[root@cham002 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::6f15:52d3:ebeb:e193. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
 php5_module (shared)
 php7_module (shared)

此時Apache默認加載兩個PHP模塊,那麼爲了正常使用須要經過編輯Apache的配置文件來指定其工做時默認調用哪一個PHP模塊(加(#)註釋掉其中一個調用參數便可):socket

相關文章
相關標籤/搜索