Linux系统服务器上安装PHP

第一步:下载安装包

在下载之前都先查看一下是否安装了php需要的依赖包,

zlib和libxml2,rpm -q libxml2, rpm -q zlib有就不用安装了。

再看看libxml2-devel,libpng-devel有没有,没有同样需要安装 yum install libxml2-devel,yum install libpng-devel

jpeg

下载地址:http://www.ijg.org/files/

下载安装包:http://www.ijg.org/files/jpegsrc.v8b.tar.gz

libpng

下载地址:https://sourceforge.net/projects/libpng/files/libpng16/1.6.30/

下载安装包:https://sourceforge.net/projects/libpng/files/libpng16/1.6.30/libpng-1.6.30.tar.gz

freetype

下载地址:http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/

下载安装包:http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.7.tar.gz

gd

下载地址:https://github.com/libgd/libgd/releases

下载安装包:https://github.com/libgd/libgd/releases/download/gd-2.1.0/libgd-2.1.0.tar.gz

openssl

下载地址:https://www.openssl.org/source/

下载安装包:https://www.openssl.org/source/openssl-1.0.2l.tar.gz

PHP

下载地址:http://php.net/downloads.php

下载安装包:http://hk1.php.net/get/php-5.6.31.tar.gz/from/this/mirror

用wget方法下载

#wget 下载安装包的路径

下载好之后再解压,我这里下载的都是.gz的压缩包并都放在root/lamp/中,所以我用# tar -zxvf 文件名 来解压

准备工作做好后开始一个个安装。

第二步:安装zlib

[root@iZ2ze5cti43o69css0svslZ lamp]# cd zlib-1.2.11

[root@iZ2ze5cti43o69css0svslZzlib-1.2.11]#./configure

[root@iZ2ze5cti43o69css0svslZzlib-1.2.11]#make && make install 

第三步:安装libxml2

[root@iZ2ze5cti43o69css0svslZ lamp]# cd libxml2-2.7.3

[root@iZ2ze5cti43o69css0svslZ libxml2-2.7.3]# ./configure --prefix=/usr/local/libxml2 --without-zlib

[root@iZ2ze5cti43o69css0svslZ libxml2-2.7.3]#make && make install 

第四步:安装jpeg

[root@iZ2ze5cti43o69css0svslZ lamp]# cd jpeg-8b

[root@iZ2ze5cti43o69css0svslZ jpeg-8b]# ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static

[root@iZ2ze5cti43o69css0svslZ jpeg-8b]# make && make install     

第五步:安装libpng

[root@iZ2ze5cti43o69css0svslZ lamp]# cd libpng-1.6.30

[root@iZ2ze5cti43o69css0svslZ libpng-1.6.30]# ./configure --prefix=/usr/local/libpng

[root@iZ2ze5cti43o69css0svslZ libpng-1.6.30]#make && make install 

第六步:安装freetype

[root@iZ2ze5cti43o69css0svslZ lamp]# cd freetype-2.7

[root@iZ2ze5cti43o69css0svslZ freetype-2.7]# ./configure --prefix=/usr/local/freetype


[root@iZ2ze5cti43o69css0svslZ freetype-2.7]#make && make install  


第七步:安装gd

在安装gd之前需要安装安装libxpm,不然会报错后面的错误3

yum install libXpm-devel.x86_64

[root@iZ2ze5cti43o69css0svslZ lamp]# cd libgd-2.2.3

[root@iZ2ze5cti43o69css0svslZlibgd-2.2.3]# ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg/ \

--with-png=/usr/local/libpng/ --with-zlib --with-freetype=/usr/local/freetype


[root@iZ2ze5cti43o69css0svslZ src]#make && make install  


第八步:安装openssl

[root@iZ2ze5cti43o69css0svslZ lamp]# cd openssl-1.0.2l

[root@iZ2ze5cti43o69css0svslZ openssl-1.0.2l]# ./config -fPIC --prefix=/usr/local/openssl


[root@iZ2ze5cti43o69css0svslZ openssl-1.0.2l]#make && make install  


第九步:安装PHP

[root@iZ2ze5cti43o69css0svslZ lamp]# cd php-5.6.31

[root@iZ2ze5cti43o69css0svslZ php-5.6.31]# ./configure --prefix=/usr/local/php \

--with-apxs2=/usr/local/apache/bin/apxs--with-mysql=mysqlnd--with-pdo-mysql=mysqlnd \

--with-mysqli=mysqlnd--with-freetype-dir=/usr/local/freetype--with-gd=/usr/local/gd--with-zlib \

--with-libxml-dir=/usr/local/libxml2--with-jpeg-dir=/usr/local/jpeg--with-png-dir--enable-mbstring=all--enable-mbregex \

--enable-shared --with-openssl-dir=/usr/local/openssl--with-openssl


[root@iZ2ze5cti43o69css0svslZ php-5.6.31]#make && make install  


复制PHP配置文件到指定目录

[root@iZ2ze5cti43o69css0svslZ php-5.6.31]# cp php.ini-development /usr/local/php/lib/php.ini

修改Apache的配置文件,让Apache认识PHP

[root@iZ2ze5cti43o69css0svslZ php-5.6.31]# vi /usr/local/apache/conf/httpd.conf

在httpd.conf找到addtype添加下面这一条

AddType application/x-httpd-php .php


找到这个<IfModule dir_module>在DirectoryIndex  index.html里面添加index.php


例如:

<IfModule dir_module>

    DirectoryIndex index.php index.html

</IfModule>

然后重启Apache

[root@iZ2ze5cti43o69css0svslZ php-5.6.31]#/usr/local/apache/bin/apachectl restart


第十步:测试PHP脚本访问

创建PHP文件存放的位置:/usr/local/apache/htdocs/

创建index.php: [root@iZ2ze5cti43o69css0svslZ php-5.6.31]# vi /usr/local/apache/htdocs/index.php

进入之后写入:<?php phpinfo(); ?>,然后保存退出:wq

然后在浏览器上输入服务器地址访问该文件出现如下图所示即表示PHP安装成功:

安装PHP中遇到的问题:

错误1、报错:Unable to find libgd.(a|so) >= 2.1.0 anywhere under /usr/local/gd


这是因为gd库的版本过低,重新安装gd库,可以选择安装个版本2.1.0的

错误2、报错:/usr/local/openssl/lib/libcrypto.a: could not read symbols: Bad value

这是openssl编译错误,需要重新编译,重新安装,在重新安装之前需要把旧的先卸载。

然后编译:./config -fPIC --prefix=/usr/local/openssl

错误3、报错:/usr/local/src/php-5.5.6/ext/gd/gd.c:57:22: error: X11/xpm.h: No such file or directory

make: *** [ext/gd/gd.lo] Error 1

这是提示gd库不支持xpm

解决方法

a、安装libxpm

yum install libXpm-devel.x86_64

b、按照上面的第七步重新安装gd库

安装成功后会看到如下信息,说明gd已经支持xpm了

** Configuration summary for libgd 2.1.0:
Support for Zlib:                 yes
Support for PNG library:          yes
Support for JPEG library:         yes
Support for VPX library:          no
Support for TIFF library:         no
Support for Freetype 2.x library: yes
Support for Fontconfig library:   no
Support for Xpm library:          yes
Support for pthreads:             yes 

c、再次按照上面的方法安装php

错误4、报错:ext/gd/gd.c:1330: undefined reference to `XpmLibraryVersion'

问题说明:没有找到xpm库的安装位置

解决方法:

a、rpm -ql libXpm :查询出libXpm的安装位置,发现在/usr/lib64/ 下

b、重新编译php,./configure中增加 --with-xpm-dir=/usr/lib64/ 

c、make && make install 成功!

5、出现如图问题

这是因为PHP默认没有指定时区。

猜你喜欢

转载自blog.csdn.net/zyj_15067066062/article/details/76169704