PHP的安装

进入/usr/local/src

cd /usr/local/src

下载php-5.6.31

wget http://mirrors.sohu.com/php/php-5.6.31.tar.gz

解压压缩包

tar -zxvf php-5.6.31.tar.gz

创建PHP的安装目录

mkdir /usr/local/php

配置PHP安装信息

```

./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-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 \

--disable-ipv6

```


参数解释:

--prefix=/usr/local/php \        

指定PHP的安装目录

--with-apxs2=/usr/local/apache2/bin/apxs \

编译共享的 Apache 2.0 模块。FILE 是可选的 Apache apxs 工具的路径,默认指向 apxs。

--with-config-file-path=/usr/local/php/etc \

设置 php.ini 的搜索路径

--with-mysql=/usr/local/mysql \

MySQL安装目录,对mysql的支持

--with-libxml-dir \

打开libxml2库的支持

--with-gd \

打开gd库的支持

--with-jpeg-dir \

打开对jpeg图片的支持

--with-png-dir \

打开对png图片的支持

--with-freetype-dir \

打开对freetype字体库的支持

--with-iconv-dir \

PHP 编译时指定 iconv 在系统里的路径,否则会扫描默认路径

--with-zlib-dir \

打开zlib库的支持,用于http压缩传输

--with-bz2 \

打开对bz2文件的支持

--with-openssl \

openssl的支持,加密传输https时用到的

--with-mcrypt \

mcrypt算法扩展

--enable-soap \

启用SOAP支持

--enable-gd-native-ttf  \

支持TrueType字符串函数库

--enable-mbstring \

多字节,字符串的支持

--enable-sockets \

打开 sockets 支持

--enable-exif \

图片的元数据支持

--disable-ipv6

禁用IPv6支持


编译PHP

make

安装PHP

make install

拷贝PHP配置文件

cp /usr/local/src/php-5.6.31/php.ini-production /usr/local/php/etc/php.ini

修改Apache配置文件(很重要!!!)

vim /usr/local/apache2/conf/httpd.conf

在一般模式下输入     :set nu 回车可显示行号

1. 找到119行

Options FollowSymLinks

AllowOverride None

Order deny,allow

Deny from all

改为

Options FollowSymLinks

AllowOverride None

Order deny,allow

Allow from all

2. 找到322行

AddType application/x-gzip .gz .tgz

后面追加一行

AddType application/x-httpd-php .php

3. 找到170行


DirectoryIndex index.html


改成


DirectoryIndex index.html index.htm index.php


4. 找到102行

#ServerNamewww.example.com:80

改为

ServerName localhost:80

测试配置是否成功

/usr/local/apache2/bin/apachectl -t

显示Syntax OK,配置成功

启动Apache服务

/usr/local/apache2/bin/apachectl start

检测服务是否正常启动

pa aux | grep httpd

查看是否有httpd进程列表

测试PHP解析

写入一个简单的php程序

vim /usr/local/apache2/htdocs/1.php

echo "php works.";

?>

保存后测试

curl localhost/1.php

只有显示php works.这个信息时才算是正常解析


问题集锦:

在./configure过程中可能会出现以下错误

错误1:

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

解决:

yum install libxml2 -y

yum install libxml2-devel -y

问题2:

error: Cannot find OpenSSL's

解决:

yum install openssl openssl-devel -y

问题3:

error: Please reinstall the BZip2 distribution

解决:

yum install bzip2 bzip2-devel -y

问题4:

error: jpeglib.h not found

解决:

yum -y install libjpeg libjpeg-devel

问题5:

error: png.h not found

解决:

yum -y install libpng libpng-devel

问题6:

error: freetype-config not found.

解决:

yum install -y freetype-devel

问题7:

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

解决:

yum  install epel-release

yum install libmcrypt libmcrypt-devel

问题7:

Cannot retrieve metalink for repository: epel. Please verify its path and try again

原因:

yum-epel升级到0.5.2版本,更换了https链接,所以原来的镜像列表就过时了

解决:

yum –disablerepo=epel -y update ca-certificates 

yum install libmcrypt libmcrypt-devel

问题8:

Error: File /var/cache/yum/i386/6/epel/metalink.xml does not exist

原因:

这个epel-7是不能用于centos6.x的,卸载了,再安装就行了:

如果是CentOS6.x执行下面就行了:

解决:

yum remove epel-release --disablerepo=epel

yum install epel-release

问题9:

curl localhost/1.php时出现

echo "php works.";

?>

解决:

iptables -F

service iptables save

小伙子,当你看到这还没解决,就说明你肯定配置错误,或则没按照KK说的步骤走哦,自己回去检查一下哦,如果配置确实有问题,记得更改后重启Apache

/usr/local/apache2/bin/apachectl graceful

有什么问题欢迎留言,一起学习!

你可能感兴趣的:(PHP的安装)