LAMP搭建3:PHP安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LAMP搭建3:PHP安装相关的知识,希望对你有一定的参考价值。

1.进入/usr/local/src/目录下载安装包php-5.4.36.tar.bz2

[[email protected] ~]# cd /usr/local/src

[[email protected] src]# ls

php-5.4.36.tar.bz2

2.解压安装包

[[email protected] src]# tar jxvf php-5.4.36.tar.bz2

[[email protected] src]# echo $?

0

3.进入安装目录

[[email protected] src]# cd php-5.4.36

4.配置安装选项

[[email protected] php-5.4.36]# ./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

php编译安装中常见配置错误处理请参考:

(1)http://www.poluoluo.com/jzxy/201505/364819.html

(2)http://blog.sina.com.cn/s/blog_75a07c3b0101kcwb.html

错误1:configure: error: Cannot find OpenSSL‘s <evp.h>

解决:[[email protected] php-5.4.36]# yum install -y openssl openssl-devel

错误2:configure: error: Please reinstall the BZip2 distribution

解决:[[email protected] php-5.4.36]# yum install bzip2 bzip2-devel

错误3:configure: error: jpeglib.h not found.

解决:[[email protected] php-5.4.36]# yum -y install libjpeg-devel

错误4:configure: error: png.h not found.

解决:[[email protected] php-5.4.36]# yum -y install libpng-devel

错误5:configure: error: freetype-config not found.

解决:[[email protected] php-5.4.36]# yum -y install freetype-devel

错误6:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决:由于centos官方源中没有libmcrypy-devel这个包,我们需要安装一个工具epel,然后再安装libmcrypy-devel。

[[email protected] php-5.4.36]# rpm -ivh ‘http://www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm‘

[[email protected] php-5.4.36]# yum list |grep -i mcrypt

libmcrypt.i686                              2.5.8-9.el6                  epel

libmcrypt-devel.i686                        2.5.8-9.el6                  epel

libtomcrypt.i686                            1.17-21.el6                  epel

libtomcrypt-devel.i686                      1.17-21.el6                  epel

libtomcrypt-doc.noarch                      1.17-21.el6                  epel

mcrypt.i686                                 2.6.8-10.el6                 epel

php-mcrypt.i686                             5.3.3-5.el6                  epel

[[email protected] php-5.4.36]# yum install -y libmcrypt-devel

直到配置全部正确:

[[email protected] php-5.4.36]# echo $?

0

5.编译:

[[email protected] php-5.4.36]# make

[[email protected] php-5.4.36]# echo $?

0

6.安装:

[[email protected] php-5.4.36]# make install

[[email protected] php-5.4.36]# echo $?

0

7.查看安装结果:

[[email protected] php-5.4.36]# ls /usr/local/php/

bin  etc  include  lib  php

8.将php加入系统环境变量:

[[email protected] support-files]# vim /etc/profile.d/path.sh

#!/bin/bash

export PATH=$PATH:/etc/init.d/:/usr/local/mysql/bin/:/usr/local/apache2/bin/:/usr/local

/php/bin/

[[email protected] support-files]# source /etc/profile.d/path.sh

9.测试PHP

[[email protected] php-5.4.36]# php -m # -m选项查看php的静态模块

[[email protected] php-5.4.36]# php -i # -i选项列出php配置的详细信息,包括模块的

部分配置选项说明:

[[email protected] php-5.4.36]# ./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

--with-apxs2 帮助安装动态模块的工具

[[email protected] php-5.4.36]# ls /usr/local/apache2/modules/

httpd.exp  libphp5.so  mod_deflate.so  mod_expires.so  mod_rewrite.so

Apache目录下多了一个动态模块libphp5就是apxs的功劳

--with-mysql 说明php依赖MySQL,所以才先安装MySQL


以上是关于LAMP搭建3:PHP安装的主要内容,如果未能解决你的问题,请参考以下文章

搭建LAMP架构— 3手工编译安装PHP

LAMP环境应用搭建

LAMP 搭建练习

LAMP 搭建

linux下lamp环境搭建(apache安装,mysql安装,php安装)

lamp论坛搭建