php的安装及遇到问题解决方法
admin
2023-06-25 21:42:09
0次

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

# 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下面的。

找到:

Options FollowSymLinks

AllowOverride None

Order deny,allow

Deny from all

将最后一行的Deny改成Allow,如果不修改,以后用浏览器访问我们的服务器的时候,会403禁访的。


然后找到:AddType application/x-gzip .gz .tgz

在该行下面添加: AddType application/x-httpd-php .php

说明:要想支持php脚本解析,必须要加上对应的类型。


再找到:

             DirectoryIndex index.html

     

将中间参数修改为: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的时候,就可以直接执行命令了。

完了,喝口水!如果发现有错误,请留言,

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...