安装PHP5和PHP7

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安装PHP5和PHP7相关的知识,希望对你有一定的参考价值。

一、php5安装

PHP,是英文超文本预处理语言Hypertext Preprocessor的缩写。PHP 是一种 html 内嵌式的语言,是一种在服务器端执行的嵌入HTML文档的脚本语言。官网:www.php.net

1、下载并解压源码安装包

[[email protected] bin]# cd /usr/local/src/
[[email protected] src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2
[[email protected] src]# tar jxf php-5.6.30.tar.bz2 

2、配置安装

[[email protected] src]# cd php-5.6.30/
[[email protected] php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/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/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

安装可能会遇到的问题

错误1:

configure: error: xml2-config not found. Please check your libxml2 installation.

解决方法:

[[email protected] php-5.6.30]# yum list | grep libxml2
[[email protected] php-5.6.30]# yum install -y libxml2-devel

错误2:

configure: error: Cannot find OpenSSL‘s <evp.h>

解决方法:

[[email protected] php-5.6.30]# yum install -y openssl-devel

错误3:

configure: error: Please reinstall the BZip2 distribution

解决办法:

[[email protected] php-5.6.30]# yum install -y bzip2-devel

错误4

configure: error: jpeglib.h not found.

解决方法:

[[email protected] php-5.6.30]# yum install -y libjpeg-devel

错误5

configure: error: png.h not found.

解决方法:

[[email protected] php-5.6.30]# yum install -y libpng-devel

错误6

configure: error: freetype-config not found.

解决方法:

[[email protected] php-5.6.30]# yum install -y freetype-devel

错误7

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决方法:

[[email protected] php-5.6.30]# yum list |grep libmcrypt
libmcrypt.x86_64                          2.5.8-13.el7                 epel     
libmcrypt-devel.x86_64                    2.5.8-13.el7                 epel     
[[email protected] php-5.6.30]# yum install -y libmcrypt-devel

如果没有这个安装包,则需要安装下yum扩展包:

[[email protected] php-5.6.30]# yum install epel-release

3、编译安装

[[email protected] php-5.6.30]# make           //编译
[[email protected] php-5.6.30]# echo $?       //检查上一条命令是否正确

[[email protected] php-5.6.30]# make install             //安装
[[email protected] php-5.6.30]# echo $?                   //检查上一条命令是否正确,也就是安装是否出错

4、配置文件

[[email protected] php-5.6.30]# cp php.ini-
php.ini-development  php.ini-production   
[[email protected] php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini       //正常情况下使用php.ini-production,开发环境可以使用php.ini-development
[[email protected] php-5.6.30]# /usr/local/php/bin/php -i | less

5、查看是否被Apache正确调用

[[email protected] php-5.6.30]# cat /usr/local/apache2/conf/httpd.conf | grep php
LoadModule php5_module        modules/libphp5.so

二、PHP7安装

安装过程与PHP5安装过程类似。
需要注意的是:

apache服务器可以存在2种版本的php,通过在apache的配置文件中注释掉相应的行来关闭某个版本的php模块.

 [[email protected] ~]# vim /usr/local/apache2/conf/httpd.conf

技术分享图片
如果不使用PHP7,在LoadMoudle前面加#即可。

以上是关于安装PHP5和PHP7的主要内容,如果未能解决你的问题,请参考以下文章

3.安装PHP5和PHP7

安装PHP5和PHP7

安装PHP5和PHP7

安装PHP5和PHP7

yum安装php5.5,php5.6和php7.0

安装PHP5与安装PHP7