设为首页 收藏本站
查看: 578|回复: 0

[经验分享] php的安装及遇到问题解决方法

[复制链接]

尚未签到

发表于 2018-12-18 10:36:39 | 显示全部楼层 |阅读模式
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、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-652761-1-1.html 上篇帖子: php中curl的详细解说 下篇帖子: 一键安装lnmp之php
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表