>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的配置文件移动到./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中也会自动添加相应配置内容。服务器
[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