安装PHP5与PHP7

  • 目前大多数企业都会使用php5.6以及更高的版本,越来越多的企业使用php7版本。两个版本有较大的差异
    另附:php官网下载地址:www.php.net

安装PHP5

准备

1.下载源码包,并解压

#进入目录,并下载源码包
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2
#解压源码包  注意这里是用的 xjvf
tar xjvf php-5.6.30.tar.bz2

2.设置编译参数:配置编译参数的长短,取决于我们给它设置所要检查的项目多少

[root@centos001 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

错误一:

#输出错误如下:未找到XML2配置。请检查您的libxml2的安装
configure: error: xml2-config not found. Please check your libxml2 installation.

解决方法:
首先,输出结果告诉我们缺少配置文件,然后需要去下载一个包,但是我们不知道名字,所以我们先检索一下

#检索我们需要安装的包
[root@centos001 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   
#一般选择devel 结尾的文件
[root@centos001 php-5.6.30]# yum install -y libxml2-devel

重新设置编译参数
错误二:又出问题了

#输出如下:说是 找不到一个叫OpenSSL的玩意
configure: error: Cannot find OpenSSL's <evp.h>

解决方法:和上面的差不多 找yum包来安装

[root@centos001 php-5.6.30]# yum install -y openssl-devel

错误三:

checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution

解决方法:找包安装

[root@centos001 php-5.6.30]# yum install -y bzip2-devel

错误四:

configure: error: jpeglib.h not found.

解决方法:找包安装

[root@centos001 php-5.6.30]# yum install -y libjpeg-turbo-devel

错误五:

configure: error: png.h not found.

解决方法:

[root@centos001 php-5.6.30]# yum install -y libpng-devel

错误六:输出错误信息并且在使用yum list搜索时也出现了错误

configure: error: freetype-config not found.
[root@centos001 php-5.6.30]# yum list | grep - i freetype
grep: i: 没有那个文件或目录
grep: freetype: 没有那个文件或目录

解决方法:不加i选项(忽略大小写)搜索

 
[root@centos001 php-5.6.30]# yum install -y fretype freetype-devel

错误七、

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

解决办法: yum list报错的原因是:centos默认的yum源里没有我们需要的这个包,所以需要借助epel yum扩展源

[root@centos001 php-5.6.30]# yum install -y epel-release
[root@centos001 php-5.6.30]# yum install -y libmcrypt-devel

3.重新配置编译参数后得到如下就是正确的,要是不放心可以用echo $? 检查一下

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
[root@centos001 php-5.6.30]# echo $?
0

安装:

[root@centos001 php-5.6.30]# make && make install
#输出信息
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/local/src/php-5.6.30/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
#得到目录
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/

目录信息

[root@centos001 php-5.6.30]# ls /usr/local/php/
bin  etc  include  lib  php
#核心文件所在目录
[root@centos001 php-5.6.30]# ls /usr/local/php/bin/
pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize
[root@centos001 php-5.6.30]# du -sh /usr/local/php/bin/php
36M	/usr/local/php/bin/php
# apache 所需要的文件 及时删掉上面的php文件也可以^C
[root@centos001 php-5.6.30]# du -sh /usr/local/apache2.4/modules/libphp5.so 
37M	/usr/local/apache2.4/modules/libphp5.so
#​查看php所加载的模块
[root@centos001 php-5.6.30]# /usr/local/php/bin/php -m
[PHP Modules]

最后:复制配置文件。因为我们刚才配置编译参数时,定义了php的配置文件所在的目录

#复制配置文件。production适用于生产环境中
 [root@centos001 php-5.6.30]# cp php.ini-production  /usr/local/php/etc/php.ini
#用这个命令能看到php的编译参数还有配置文件路径(没有复制配置文件之前,文件路径后的配置文件信息是空的)
[root@centos001 php-5.6.30]# /usr/local/php/bin/php -i |less

使用

当我们安装好后怎么使用呢?答案是需要编辑配置文件
进入下面的目录后/php5.so 就能看见apache所需要的php模块 用#来选择 要不要加载这个模块

[root@centos001 php-5.6.30]# vi /usr/local/apache2.4/conf/httpd.conf

安装PHP7

准备

下载安装包并解压

#进入目录
cd /usr/local/src/
#下载源码包
wget 下载地址
#解压 注意格式
tar jxvf

配置编译信息

  • 注意:因为安装php5时我们装了很多文件依赖包 所以单独后面编译参数时就不需要再次安装了
    编译参数信息:定义的目录文件路径与配置文件路径与php5相区别(不同的地方)
# 进入源码包目录
[root@centos001 php-7.1.6]# cd php-7.1.6
# 配置编译参数
[root@centos001 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

安装

  • 安装php5时 用的make && make install 用了很久很久 这次换一下 (事实证明并没有什么不同ToT)
# make
# make install
#输出
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/

一台机器可以同时有两个php存在,但是注意需要把apache调用指定好

使用

  • 复制配置文件
[root@centos001 php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so
/usr/local/apache2.4/modules/libphp7.so
#复制配置文件
 cp php.ini-production  /usr/local/php7/etc/php.ini
  • 查看apache加载了哪些模块
[root@centos001 php-7.1.6]# /usr/local/apache2.4/bin/apachectl  -M


注意:一台机器可以同时有两个php存在,但是注意需要把apache调用指定好

  • 选择索要加载的模块 加#可以让它不加载
#进入配置文件后用/php5.so搜索
[root@centos001 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf

扩展

一、php中mysql,mysqli,mysqlnd,pdo到底是什么
http://blog.csdn.net/u013785951/article/details/60876816
二、查看编译参数
http://ask.apelearn.com/question/1295

猜你喜欢

转载自my.oschina.net/u/3707523/blog/1593424