11.10-11.12 安装PHP5
>PHP(Hypertext Preprocessor)英文超级文本预处理语言。PHP 是一种HTML内嵌式的语言,是一种在服务器端执行的嵌入HTML文档的脚本语言。官网:www.php.net,能用PHP7就用PHP7
准备安装包
[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 xml2libxml2.x86_64 2.9.1-6.el7_2.3 @anacondalibxml2.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-exif2再次报错!!!!!!configure: error: Cannot find OpenSSL's[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-exif3再次报错!!!!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-exif4再次报错!!!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-exif5再次报错!!!configure: error: png.h not found.说明:缺少png库。[root@cham002 php-5.6.30]# yum list |grep pnglibpng.x86_64 2:1.5.13-7.el7_2 @anacondalibpng.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.el7texlive-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-exif6再次报错!!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-exif7再次报错!!configure: error: mcrypt.h not found. Please reinstall libmcrypt.说明:缺少mcrypt库。注意这包是在扩展源里面~~~~如果没有安装需要先安装yum install -y epel-release![root@cham002 php-5.6.30]# yum list |grep mcryptlibmcrypt.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已加载插件:fastestmirrorLoading 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
环境配置完成!
编译和安装
[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
安装完成!
PHP工作原理
将PHP的配置文件移动到./configure时指定的目录:
[root@cham002 php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini
PHP在系统中是作为Apache的一个模块被调用的,所以不用执行名启动该PHP。
查看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/libphplibphp5.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.so37M /usr/local/apache2.4/modules/libphp7.so
工作原理
将PHP的配置文件移动到./configure时指定的目录:如php5
查看Apache加载的PHP模块:
[root@cham002 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -MAH00558: 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 messageLoaded 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模块(加(#)注释掉其中一个调用参数即可):