11.10-11.12 安装PHP5

  • PHP官网www.php.net
  • 当前主流版本为5.6/7.1
  • cd /usr/local/src/
#进入到src目录
[root@localhost mysql]# cd ../src/
  • 下载
#下载PHP软件包 由于是国内的镜像,有可能失效
[root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
  • 解压
#解压软件包
[root@localhost src]# tar zxvf php-5.6.30.tar.gz 
  • 进入到php-5.6.30目录里

[root@localhost src]# cd php-5.6.30
[root@localhost php-5.6.30]# 
  • yum安装支持库
[root@taoyun php-5.6.30]# yum install -y libxml2-devel

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

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

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

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

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

[root@taoyun php-5.6.30]# yum install -y epel-release

[root@taoyun php-5.6.30]# yum install -y libmcrypt-devel
  • 安装
[root@localhost php-5.6.30]# \
./configure --prefix=/usr/local/php \
#指定安装目录
--with-apxs2=/usr/local/apache2.4/bin/apxs \
#apxs2是Apache的工具,可以自动安装扩展模块和配置
--with-config-file-path=/usr/local/php/etc \
#指定配置文件所在路径
--with-mysql=/usr/local/mysql \
#指定mysql的路径
#老版本的php用mysql
--with-pdo-mysql=/usr/local/mysql \
#指定pdo-mysql的路径
--with-mysqli=/usr/local/mysql/bin/mysql_config \
#指定mysqli的路径
#新版本用mysqli,不在使用mysql
#上述三种是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

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

第1个报错:
安装PHP5和PHP7_第1张图片

翻译:
对不起,我不能运行apxs。可能的原因:
1 .工作Perl是没有安装
2。apx型没有发现。尝试通过使用- apxs2=/path/to/ apxs来传递路径
3 .产品Apache并没有使用- enable -所以(apxs使用页面被显示)
/usr/local/apache2.4/bin/apxs的输出如下:
./configure: /usr/local/apache2.4/bin/apxs: /replace/with/path/to/perl/interpreter:没有这样的文件或目录
配置:错误:异常终止


解决步骤:

1、根据不能run apxs 。cd 到apache的bin目录下运行./apxs 运行结果

[root@localhost bin]# ./apxs
-bash: ./apxs: /replace/with/path/to/perl/interpreter: 坏的解释器: 没有那个文件或目录

2、vim apxs文件 找“/replace/with/path/to/perl/interpreter”关键字

在第一个行 :#!/replace/with/path/to/perl/interpreter -w

根据perl的安装目录 /usr/bin/perl

修改为:#! /usr/bin/perl -w


3、运行第一步。或者直接 ./configure ^^^^^


第2个报错

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

解决方法:

#查找libxml2
[root@localhost php-5.6.30]# yum list |grep libxml2

#yum安装libxml2库
[root@localhost php-5.6.30]# yum -y install libxml2-devel

第3个报错

checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's 

解决方法:

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

第4个报错

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

解决方法:

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

第5个报错

checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=
configure: error: jpeglib.h not found.

解决方法:

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

第6个报错

checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.

解决方法:

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

第7个报错

If configure fails try --with-xpm-dir=
configure: error: freetype-config not found.

解决方法:

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

第8个报错

checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决方法:

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

安装PHP5和PHP7_第2张图片

安装完毕!

开始编译与安装

  • make && make install

查看一下PHP文件

[root@localhost php-5.6.30]# ls /usr/local/php/bin/
pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize

#查看一下文件大小
[root@localhost php-5.6.30]# du -sh /usr/local/php/bin/php
36M /usr/local/php/bin/php
[root@localhost php-5.6.30]# du -sh /usr/local/apache2.4/modules/libphp5.so
37M /usr/local/apache2.4/modules/libphp5.so
#php是通过libphp5.so文件结合起来

#查看PHP所加载的模块命令,并且全部都是静态的
[root@localhost php-5.6.30]# /usr/local/php/bin/php -m
  • 开配置配置文件
[root@localhost php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-5.6.30]# vim /usr/local/php/etc/php.ini

11.13 安装PHP7

  1. 下载源码包到/usr/local/src/目录下
#进入src目录
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# 

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

[root@localhost src]# ls
php-7.1.6.tar.bz2
  1. 解压压缩包
解压
[root@localhost src]# tar jxvf php-7.1.6.tar.bz2 

[root@localhost src]# ls
php-7.1.6  php-7.1.6.tar.bz2
  1. 进入目录
[root@localhost src]# cd php-7.1.6
[root@localhost php-7.1.6]# 
  1. 编译安装
[root@localhost 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

第一个报错:

Configuring SAPI modules
checking for Apache 2.0 handler-module support via DSO through APXS... 

Sorry, I cannot run apxs.  Possible reasons follow:

1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)

The output of /usr/local/apache2.4/bin/apxs follows:
./configure: line 6199: /usr/local/apache2.4/bin/apxs: No such file or directory
configure: error: Aborting

解决方法:
安装apache,安装方法请查看https://blog.51cto.com/3622288/2051242

第二个报错:

checking libxml2 install dir... yes
checking for xml2-config path... 
configure: error: xml2-config not found. Please check your libxml2 installation.

解决方法:

[root@localhost php-7.1.6]# yum -y install libxml2-devel

第三个报错:

checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's 

解决方法:

[root@localhost php-7.1.6]# yum -y install openssl-devel

第四个报错:

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

解决方法:

[root@localhost php-7.1.6]# yum -y install bzip2-devel

第五个报错:

If configure fails try --with-webp-dir=
configure: error: jpeglib.h not found.

解决方法:

[root@localhost php-7.1.6]# yum -y install libjpeg-devel

第六个报错:

checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.

解决方法:

[root@localhost php-7.1.6]# yum -y install libpng-devel

第七个报错:

If configure fails try --with-xpm-dir=
configure: error: freetype-config not found.

解决方法:

[root@localhost php-7.1.6]# yum -y install freetype-devel

第八个报错:

checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决方法:

[root@localhost php-7.1.6]# yum -y install epel-release

#安装libtomcrypt-devel之前必须安装epel-release,原因是依赖关系
[root@localhost php-7.1.6]# yum -y install libtomcrypt-devel

第九个报错:

mysql_config not found
configure: error: Please reinstall the mysql distribution

解决方法:

安装mysql数据库
mysql的安装文档链接如下
https://blog.51cto.com/3622288/2050823

#安装完成后执行
[root@localhost 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和PHP7_第3张图片

最后执行 make && make install
如果不确定有没有编译安装好,可以在执行命令之后 用echo $? 检查命令是否出错。

安装PHP5和PHP7_第4张图片

安装完毕!

  1. php模块路径
[root@localhost php7]# ls /usr/local/apache2.4/modules/libphp7.so 
/usr/local/apache2.4/modules/libphp7.so
  1. 查看php7加载模块
[root@localhost php7]# /usr/local/php7/bin/php -m
  1. 查看apache加载了几个php,通过修改配置文件来指定使用php5还是php7模块,不要的就注释掉
[root@localhost php7]# vim /usr/local/apache2.4/conf/httpd.conf

安装PHP5和PHP7_第5张图片

  1. 把php7的参考配置文件复制到php7的配置文件目录下
[root@taoyun php-7.1.6]# cp php.ini-production /usr/local/php7/etc/php.ini

[root@taoyun php-7.1.6]# ls /usr/local/php7/etc/
pear.conf  php.ini