您的位置:首页 > 编程语言 > PHP开发

php的安装及遇到问题解决方法

2015-09-21 16:48 791 查看
php的安装遇到的麻烦比较多,这里将自己安装的心得分享给大家,希望可以帮到大家。
因为我在编译php的时候,有指定mysql以及apache的路径,所以要先安装mysql和apache,两者的顺序随意,具体方法可以查看我mysql和apache的安装方法。关于PHP版本,我选择的是5.4版本。

1. php源码包下载
# cd /usr/local/src ##我习惯将下载的包放到这个路径
# wget http://cn2.php.net/distributions/php-5.4.44.tar.gz # tar -zxvf php-5.4.44.tar.gz

2. 配置编译参数
# cd ./php-5.4.44
接下来要进行配置编译参数的过程,因为中间会一系列的报错,缺少的库非常多,所以建议先安装完所有需要的包,这样就不会太麻烦了,因为checking的时间会比较长。如果有时间想体验一下完整的过程,可以按部就班的yum。
先声明一下,libmcrypt-devel在centos的yum源中是找不到的,需要借助epel的yum源,阿里云的epel源是个不错的选择。可以在/etc/yum.repo.d/下新建一个CentOS-Base.repo,将如下内容粘贴并保存:
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

下面是遇到的报错和解决办法:
error: xml2-config not found. Please check your libxml2 installation
# yum install -y libxml2-devel
error: Cannot find OpenSSL's <evp.h>
# yum install -y openssl openssl-devel
checking for BZip2 in default path... not found
error: Please reinstall the BZip2 distribution
# yum install -y bzip2 bzip2-devel
error: png.h not found.
# yum install -y libpng libpng-devel
error: freetype.h not found.
# yum install -y freetype freetype-devel
error: mcrypt.h not found. Please reinstall libmcrypt
# yum install -y epel-release
# yum install -y libmcrypt-devel
error: jpeglib.h not found.
# yum install libjpeg-devel

接下来命令行输入如下配置参数:

#./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
只要安装完上面提到的包,一般配置过程是不会报错的。如果报错了,根据错误信息,查找相应的包,自行安装就好了。
配置完毕可以用# echo $?来查看配置过程中有无错误,如果返回时0,就说明配置成功了。

3. 接下来就是编译和安装了:
# make && make install
经过漫长的编译安装过程,php就顺利安装完了。别忘啦echo $?来查看过程是否有出错,不过一般是不会出错的,返回结果依然是0!
恭喜你,php顺利安装完了!!!但是,安装完了还是不能用的,需要进行下面的操作:
# cp php.ini-production /usr/local/php/etc/php.ini
修改apache配置文件# vim /usr/local/apache2/conf/httpd.conf ## 在这里解释一下,我之前安装的apache是在/usr/local/apache2下面的。
找到: <Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
将最后一行的Deny改成Allow,如果不修改,以后用浏览器访问我们的服务器的时候,会403禁访的。

然后找到:AddType application/x-gzip .gz .tgz
在该行下面添加: AddType application/x-httpd-php .php
说明:要想支持php脚本解析,必须要加上对应的类型。

再找到: <IfModule dir_module>
DirectoryIndex index.html
</IfModule>将中间参数修改为:DirectoryIndexindex.html index.htm index.php
修改的目的是增加针对php的索引,如果一个站点默认页为index.php,那么就得加上这个index.php的支持。比如我们要在服务器上安装一个php论坛,没有上面的php解析,我们在浏览器上面打开配置好的虚拟主机地址的时候,显示的不是安装的图形界面,而是一片源码!!!

再找到: #ServerName www.example.com:80
修改为: ServerName localhost:80,将注释的#去掉,如果不去掉,在启动apache时,会有警告信息“httpd: Could not reliably determine the server'sfully qualified domain name, using localhost.localdomain for ServerName”,看起来像是错误,其实没有影响。

查看配置文件是否有语法问题:
# /usr/local/apache2/bin/apachectl -t;如果显示Syntax OK,说明配置没问题了。
然后启动服务: # /usr/local/apache2/bin/apachectl start
查看一下httpd的进程: # ps aux |grep httpd,可以看到已经在进程表里面出现了httpd,说明已经成功完成了配置安装和最后的参数配置。
顺便说一下,apachectl的路径太长了,可以在PATH里面增加一个目录来实现快速执行apachectl的命令,具体操作如下:
# vim /etc/init.d/path.sh
#! /bin/bash

export PATH=$PATH:/usr/local/apache2/bin/ -->:wq
# source /etc/init.d/path.sh
这样,在命令行下面直接输入apachectl的时候,就可以直接执行命令了。
完了,喝口水!如果发现有错误,请留言,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux centos php 安装