转: CentOS上安装LAMP之第二步:PHP环境及安装过程报错解决方案(纯净系统环境)

最近有空就配置CentOS系统上的AMP环境,现在配置到PHP环境了

多话不说上传送门:http://blog.csdn.net/zhangatle/article/details/77447653

其中有些改动,毕竟博主的centOS的系统没有安装必须的开发环境包,他是纯净CentOS安装的!佩服

注:本文站在菜鸟的角度看待并解决问题,中间不可避免会遇到许多坑,而本文的目的就在于帮大家解决这些坑

工欲善其事,必先利其器,为了后续工作,需要先进行以下准备工作 
将所需要的软件安装包上传到服务器,本文上传到/home/zhangatle/tar目录,包括以下几个软件:

zlib-1.2.11.tar.gz 
libxml2-2.7.2.tar.gz 
jpegsrc.v9b.tar.gz 
libpng-1.4.3.tar.gz 
freetype-2.8.tar.gz 
libgd-2.2.4.tar.gz 
PHP-7.1.8.tar.gz

接下来进行安装工作,注意,安装这些软件是有顺序的,为了避免不必要的错误,可按以下顺序进行安装

1、zlib的安装

1 cd /home/zhangatle/tar
2 tar zxvf zlib-1.2.11.tar.gz
3 cd zlib-1.2.11
4  ./configure    //这个配置编译命令不要加目录参数
5 make && make install

2、libxml2安装

1 cd /home/zhangatle/tar
2 tar zxvf libxml2-2.7.2.tar.gz 
3 cd libxml2-2.7.2
4 ./configure --prefix=/usr/local/libxml2  --without-zlib
5 make && make install

3、安装jpeg

1 cd /home/zhangatle/tar
2 tar zxvf jpegsrc.v9b.tar.gz
3 cd jpegsrc.v9b
4 ./configure --prefix=/usr/local/jpeg 
5 --enable-shared --enable-static 
6 make && make install

–enable-shared 把jpeg需要的函数库程序都编译到该软件里边 
优点:函数调用速度快 
缺点:软件本身比较大 
–enable-static 静态方式(独立类型)函数处理,需要什么函数,马上include来 
优点:软件本身比较小 
缺点:函数调用速度慢

4、安装libpng

1 cd /home/zhangatle/tar
2 tar zxvf libpng-1.4.3.tar.gz 
3 cd libpng-1.4.3 
4 ./configure  #和zlib一样不要带参数,让它默认安装到相应目录
5 make && make install

5、安装freetype(字体库)

1 cd /home/zhangatle/tar
2 tar zxvf freetype-2.8.tar.gz 
3 cd freetype-2.8
4 ./configure --prefix=/usr/local/freetype 
5 make && make install

6、安装GD库

1 cd /home/zhangatle/tar
2 tar zvxf gd-2.2.4.tar.gz 
3 cd gd-2.2.4
4 ./configure --prefix=/usr/local/gd  
5             --with-jpeg=/usr/local/jpeg/    
6             --with-png --with-zlib 
7             --with-freetype=/usr/local/freetype
8             //惊喜啊,终于报错了,花都谢了

不对啊,我已经安装libpng了,为什么会报错呢?接下来开始解决错误了: 
经过查找相关资料,是缺少libpng-devel,不多说,安装

yum install libpng-devel

安装完成,退回到上级目录,并删除解压后的libgd,重复上述libgd的安装步骤

1 cd ../
2 rm -rf gd-2.2.4

果然,要么不报,要么错误一个接一个,又出现一个错误 

查找相关资料,找到解决方案,安装fontconfig-devel

yum install fontconfig-devel

再回去删除解压后的包,重新解压,再重复上述libgd的安装步骤 
这次发现以下命令终于不报错了,意不意外?

1 cd /home/zhangatle/tar
2 tar -zvxf gd-2.2.4.tar.gz 
3 cd gd-2.2.4
4 ./configure --prefix=/usr/local/gd  
5             --with-jpeg=/usr/local/jpeg/    
6             --with-png --with-zlib 
7             --with-freetype=/usr/local/freetype

接着make&&make install,成功,意料着安装php的准备工作已经完成,下面进行安装php

7、安装PHP7

执行以下命令,参数比较多,注意路径,避免出错

 1 cd /home/zhangatle/tar
 2 tar -jxvf php-7.1.8.tar.gz
 3 cd php-7.1.8
 4 ./configure --prefix=/usr/local/php 
 5             --with-apxs2=/usr/local/httpd/bin/apxs 
 6             --with-mysql=mysqlnd 
 7             --with-pdo-mysql=mysqlnd 
 8             --with-mysqli=mysqlnd 
 9             --with-freetype-dir=/usr/local/freetype 
10             --with-gd=/usr/local/gd 
11             --with-zlib --with-libxml-dir=/usr/local/libxml2 
12             --with-jpeg-dir=/usr/local/jpeg 
13             --with-png-dir 
14             --enable-mbstring=all 
15             --enable-mbregex 
16             --enable-shared
17             //此时会有一个警告,告诉我们mysql的问题,先不要管,因为我们还没有安装mysql,接着make&&make install

make

先去吃饭吧,安装需要的时间比较长,哈哈 
回来一看,TMD,又报错,能不能愉快的玩耍了?又一个致命错误

 

查了好久的资料,终于找到了问题所在,缺少libxpm,那就安装吧

yum install libXpm-devel.x86_64

安装完成后,再次重新安装GD库,显示Xpm安装完成即可再次安装PHP 

 

再次安装PHP,法克,以报错,没完没了

 

问题说明:没有找到xpm库的安装位置 
解决方法: 
1.rpm -ql libXpm :查询出libXpm的安装位置,发现在/usr/lib64/ 下 
2.重新编译php,./configure中增加 –with-xpm-dir=/usr/lib64/

终于安装成功,接下来进行相关的配置工作

首先,复制一份配置文件到项目的安装目录

cp php.ini-development    /usr/local/php/lib/php.ini

配置Apache使其支持php 
vi /usr/local/httpd/conf/httpd.conf 
1) 在httpd.conf(Apache主配置文件)中增加:

AddType application/x-httpd-php .php    

2) 找到下面这段话:(在文件里面输入/ 斜杠再输入要搜索的内容按回车键就能搜索内容了)

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

在index.html 前面添加index.php

 

3) 建立php测试网页 

vi /usr/local/apached/htdocs/index.php 

vi 是创建文件的意思

输入如下内容:

<?php
 echo phpinfo();
?>

4) 重启apache

/usr/local/httpd/bin/apachectl restart

这里报了个小错误,根据提示,是ServerName的问题,更改一下就好了

 

在httpd.conf中找到ServerName并去掉前面的#号,至此,PHP的安装已经成功 

 

码完字,睡个午觉,欢迎指正错误,互相促进

 转自:@zhangatle

原文地址:https://www.cnblogs.com/mrszhou/p/7415382.html