1.   去php官网下载源码 http://www.php.net/downloads.php ,我下载使用的版本是(php-5.4.8.tar.gz)

2.   安装环境

yum install xml2

2.   解压到/usr/src目录,执行命令:sudo tar -zxvf php-5.4.8.tar.gz -C /usr/src

3.执行./configure \

--prefix=/usr/local/php \

--with-mcrypt=/usr/local/libmcrypt \

--with-zlib --enable-mbstring \

--with-openssl \

--with-mysql \

--with-mysqli --with-mysql-sock \

--with-gd --with-jpeg-dir=/usr/lib \

--with-bz2 \

--with-pdo-mysql \

--with-gettext \

--with-curl \

--with-pdo-mysql \

--enable-sockets \

--enable-bcmath \

--enable-xml \

--enable-zip \

--enable-gd-native-ttf \

--enable-pdo \

--enable-fpm \

--enable-freetype

4.编译遇到问题:error: xml2-config not found.解决办法:

(1)去官网http://xmlsoft.org/sources/ 下载源码。我用的版本是libxml2-2.9.0.tar.gz, 解压到/usr/src,执行命令:sudo tar -zxvf libxml2-2.9.0.tar.gz  -C /usr/src

(2)进入目录/usr/src/libxml2-2.9.0,在root下执行或者用sudo命令执行: sudo ./configure --prefix=/usr/local/libxml2/ ; make; make install

(3) 进入php目录中编译时加上--with-libxml-dir=/usr/local/libxml2

5.再次编译,遇到问题:checking if the location of ZLIB install directory is defined... no ; configure: error: Cannot find libz. 解决办法:

(1)去网址 http://www.zlib.net/ 下载zlib源码。我下的是版本zlib-1.2.7.tar.gz,解压到/usr/src,执行命令:sudo tar -zxvf zlib-1.2.7.tar.gz  -C /usr/src

(2)进入目录/usr/src/zlib-1.2.7/,执行命令:sudo ./configure --prefix=/usr/local/zlib;make;make install

(3)进入php目录中重新编译,增加新参数 --with-zlib-dir=/usr/local/zlib

6.再次编译,遇到问题:error: Please reinstall the BZip2 distribution. 解决办法:

(1)去网站 http://www.bzip.org/downloads.html 下载源码。我用的版本是bzip2-1.0.6.tar.gz,执行命令:sudo tar -zxvf bzip2-1.0.6.tar.gz -C /usr/src

(2)进入目录/usr/src/bzip2-1.0.6/,sudo方式执行:make;make install(下的源码中并没有configure)

(3)重新编译,不用增加新参数

7.再次编译,遇到问题:

checking if we should use cURL for url streams... no checking for cURL in default path... not found

configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/

解决办法是重装libcurl

(1)去网站 http://curl.haxx.se/download/ 下载libcurl源码。我用的版本是curl-7.28.0.tar.gz,执行命令:sudo tar -zxvf curl-7.28.0.tar.gz -C /usr/src

(2)进入/usr/src/curl-7.28.0目录,用sudo执行命令:./configure --prefix=/usr/local/curl;make;make install

(3)重新编译php,增加参数--with-curl=/usr/local/curl

8.再次编译,遇到问题:configure: error: jpeglib.h not found. 解决办法:

(1)去网站 http://www.ijg.org/ 下载源码。我用的版本是jpegsrc.v8d.tar.gz,执行命令:sudo tar -zxvf jpegsrc.v8d.tar.gz -C /usr/src

(2)进入/usr/src/jpegsrc.v8d目录,sudo方式执行命令:sudo ./configure --prefix=/usr/local/jpeg;make;make install;

(3)重新编译php,增加参数--with-jpeg-dir=/usr/local/jpeg

9.再次编译,遇到问题:configure: error: png.h not found.

(1)去网站http://www.libpng.org/pub/png/libpng.html 下载源码,我用的版本是libpng-1.5.13.tar.gz,执行命令:sudo tar -zxvflibpng-1.5.13.tar.gz -C /usr/src

(2)进入/usr/src/libpng-1.5.13目录,sudo方式执行命令:sudo ./configure --prefix=/usr/local/png;make;make install;

(3)这时出现了configure: error: zlib not installed的错误,明明之前已经装过的,但是这里还是报错。在网上查了解决办法如下:

3.1)进入zlib的源文件目录(这里我的是/usr/src/zlib-1.2.7/),执行命令 make clean,清除zlib;

    3.2)重新配置 ./configure,后面不要接--prefix参数;

    3.3)make && make install;

    3.4)进入libpng目录(我的是/usr/src/libpng-1.5.13/),执行命令 ./configure --prefix=/usr/local/png;

    3.5)make && make install;

(4)重新编译php,这时增加参数--with-png-dir=/usr/local/png。

10.再次编译,遇到问题:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

(1)去网站http://mcrypt.hellug.gr/lib/index.html 的下载源码,我下的版本是libmcrypt-2.5.7.tar.gz;执行命令:sudo tar -zxvf libmcrypt-2.5.7.tar.gz -C /usr/src

(2)进入/usr/src/libmcrypt-2.5.7目录,sudo方式执行命令:./configure prefix=/usr/local/libmcrypt/;make ;make install

(3)重新编译php,这时增加参数--with-mcrypt=/usr/local/libmcrypt

11.再次编译,就没有遇到问题了,虽然显示了configure: WARNING: unrecognized options: --enable-freetype,但结果依然是Thank you for using PHP. 此时的编译php的参数如下:

(1)sudo ./configure --prefix=/usr/local/php --enable-fpm  --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --enable-gd-native-ttf  --enable-pdo --with-pdo-mysql --with-gettext --with-curl --with-pdo-mysql --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip --enable-freetype --with-libxml-dir=/usr/local/libxml2 --with-zlib-dir=/usr/local/zlib --with-curl=/usr/local/curl --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-mcrypt=/usr/local/libmcrypt --with-apxs2=/usr/local/apache2/bin/apxs

(备注:一定要加这个 apxs - APache eXtenSion tool 用来制作apache的扩展模块DSO,要使用这个工具,安装apache的时候就必须添加enable-so以支持DSO. 如果没有这个的话apache是只会解析静态页面的,第一次编译时没加,怎么配置都不行,第二次加了该选项重新编译以后就都OK了。)

(2)sudo make

(3)sudo make install

12.为了在命令行可以直接使用php命令,编辑 sudo vim /etc/environment,将php的bin目录路径添加进去,我的是/usr/local/php/bin,然后reboot机器

13.为了使Apache支持PHP,解决办法:

(1)进入apache配置目录,执行命令:cd /usr/local/apache2/conf。 编辑文件:sudo vim httpd.conf

(2)查找字符串AddType,并增加

AddType application/x-httpd-php .php .php3 .htm .phtml .php4

AddType application/x-httpd-php-source .phps

添加LoadModule php5_module modules/libphp5.so #如果存在就不必要了

然后重启apache使配置生效

(3)查找字符串DirectoryIndex,并修改为 DirectoryIndex index.html index.php3 index.php default.php

14. 修改php配置.

(1)进入php源码目录,选择php.ini-development复制一份到/usr/local/lib,并改名为php.ini使用vim打开,查找extension_dir,修改为extension_dir = "D:/php/php5/ext",读      者根据自己的目录结构配置,目的是找到和php.ini同目录下的ext文件夹中的扩展库。

(2)查找extension=php_,去掉extension=php_curl.dll,extension=php_gd2.dll,extension=php_mbstring.dll,extension=php_mysql.dll,extension=php_mysqli.dll,extension=php_pdo_mysql.dll,extension=php_xmlrpc.dll前面 的分号。查找short_open_tag = Off把它修改成short_open_tag = On,让其支持短标签(我看注释这个默认是打开的)。

Php.ini配置完成

配置apache的config

15.查找字符串DocumentRoot,可以设置Apache虚拟根目录

16.查找字符串ServerAdmin,并修改成自己的邮箱

17.在apache根文件中增加一个test.php文件,<?php phpinfo(); ?>,然后访问127.0.0.1/test.php,查看结果。

自己用的编译版本

./configure

--profix=/user/local/php

--with-apxs2=/usr/local/apache/bin/apxs

--with-config-file-path=/usr/local/PHP/etc

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

--with-mysqli=/usr/local/mysql/bin/mysql_config

--with-libxml-dir= #libxml目录

--with-zlib-dir= #zlib目录

--enable-sysvsem

--enable-sockets

--enable-pcntl

--enable-mbstring

--enable-mysqlnd

--enable-opcache

--enable-shmop

--enable-zip

--enable-ftp

--enable-gd-native-ttf

--enable-wddx

--enable-soap

--enable-fpm

附录:网上找的php各个版本的编译参数如下。

Fast-CGI:

./configure --prefix=/usr/local/php --enable-fastcgi --enable-force-cgi-redirect --with-config-file-path=/etc --with-zlib --with-mysql --with-xml --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --enable-mbstring

PHP4-Server:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-config-file-path=/etc --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --enable-mbstring

PHP4-Max:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --with-openssl=/usr/local/openssl-0.9.7e --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-bz2 --with-inifile --with-hyperwave --enable-xml --enable-track-vars --enable-dba --enable-dbase --enable-filepro --enable-ftp --enable-versioning --enable-memory-limit --enable-calendar --enable-session --enable-sockets --enable-sysmsg --enable-sysvsem --enable-sysvshm --enable-tokenizer --enable-overload --enable-ctype --enable-sigchild --enable-magic-quotes --enable-roxen-zts --enable-fastcgi --enable-dbx --enable-dio --enable-shmop --enable-mbstring

PHP5-Server:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib-dir --with-bz2 --with-tiff-dir --with-libxml-dir --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf --enable-mbstring --with-mysql=/usr/lib/mysql --with-config-file-path=/etc --disable-ipv6 --enable-gd-native-ttf

PHP5-Standard:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-openssl=/usr/local/openssl-0.9.7e --with-zlib --with-bz2 --with-tiff-dir --with-libxml-dir --enable-dio --enable-ftp --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-bz2-dir --with-ttf --enable-mbstring --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --disable-ipv6 --enable-gd-native-ttf

PHP5-Max:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-openssl=/usr/local/openssl-0.9.7e --with-zlib --with-bz2 --with-tiff-dir --with-libxml-dir --enable-dio --enable-ftp --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-bz2-dir --with-ttf --with-inifile --enable-dba --enable-dbase --enable-filepro --enable-versioning --enable-memory-limit --enable-calendar --enable-sockets --enable-sysvsem --enable-sigchild --enable-magic-quotes --enable-roxen-zts --enable-fastcgi --enable-dbx --enable-shmop --enable-mbstring --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --disable-ipv6 --enable-gd-native-ttf

CentOS 下编译安装PHP的更多相关文章

  1. centos下编译安装lnmp

    centos下编译安装lnmp 本文以centos为背景在其中编译安装nginx搭建lnmp环境. 编译安装nginx时,需要事先安装 开发包组"Development Tools" ...

  2. 转:在CentOS下编译安装GCC

    转:https://teddysun.com/432.html 在CentOS下编译安装GCC 技术  秋水逸冰  发布于: 2015-09-02  更新于: 2015-09-02  6519 次围观 ...

  3. CentOS 下编译安装Apache

    CentOS 下编译安装Apache 卸载原有的apache 首先从 http://httpd.apache.or 下载apache源码包httpd-2.4.4.tar.gz然后从 http://ap ...

  4. centos下编译安装mysql5.6

    CentOS 6.4下编译安装MySQL 5.6.14 参考:http://www.cnblogs.com/xiongpq/p/3384681.html 概述: CentOS 6.4下通过yum安装的 ...

  5. CentOS下编译安装MySQL 5.6.21

    一.编译安装MySQL前的准备工作 安装编译源码所需的工具和库 yum install gcc gcc-c++ ncurses-devel perl 安装cmake:http://www.cnblog ...

  6. CentOS 下编译安装MySQL

    CnetOS 下编译安装 MySql 查看是否存在旧版本: rpm -qa | grep mysql 卸载旧版本: rpm -e mysql   #普通删除模式 rpm -e --nodeps mys ...

  7. centos下编译安装mysql5.5/5.6

    2013年11月16日 19:39:13 centos 6 mysql 5.5.28 我只说些我出错的地方: cmake后删除的方法是 xargs rm < install_manifest.t ...

  8. 2、CentOS下编译安装Python2.7.6(转)

    CentOS系统下面Python在升级到2.7.6的时候,没有找到安装包直接安装,只能通过源代码编译的方式来安装Python 2.7.6版本.这篇是编译和安装Python2.7.6的过程记录. Cen ...

  9. centos下编译安装mysql5.5/5.6/5.7

    2018-12-28 14:38:46 星期五 centos 系统在mysql官网, 按照教程去配置yum源, 然后安装, 不用自己找依赖了: https://dev.mysql.com/doc/my ...

  10. CentOS下编译安装Apache(httpd)

    官网下载最新版本的apache, apr, apr-util http://httpd.apache.org/download.cgi#apache24 http://apr.apache.org/d ...

随机推荐

  1. Qt浅谈之二:钟表(时分秒针)

    一.简介 QT编写的模拟时钟,demo里的时钟只有时针和分针,在其基础上添加了秒针,构成了一个完整的时钟.能对2D绘图中坐标系统.平移变换(translate).比例变换(scale).旋转变换(ro ...

  2. python-监控服务

    最近写了一个web测试程序,因为部署在其他地方,所以想弄个监控的进程去看服务是不是还在,要是不在好发邮件,就用python简单的写了一个. 想法是这样的,单独运行一个monitor的脚本,每隔一段时间 ...

  3. Java 函数传入参数后,究竟发生了什么?java函数传参数原理解析

    JAVA函数在传入参数A时,会在函数作用周期内生成一个与参数相同类型的局部变量B. B与A指向同一块内存区域,并且具有相同的名字如param. 在函数内所有对param的操作都是对B的操作.对B进行赋 ...

  4. spring boot之security

    上一节的时候,我们打开了springboot的端点,有一些数据是非常敏感的,比如/shutdown. 这一节,我们要给一些敏感信息加上权限控制. spring boot本身的security模块就很好 ...

  5. Vim入门操作整理

    根据小甲鱼的vim入门视频整理,供查阅 移动指令:上下左右 k j h l 翻页: ctrl + b  ctrl + f 保存退出:ZZ 普通模式:vim fileName 首次进入的就是普通模式 从 ...

  6. MAC 安装telnet

    https://blog.csdn.net/licheng70356213/article/details/81162660 在10.12及以下版本,都内置了telnet命令,但是在10.13中,已经 ...

  7. vux loadmore + axios 实现点击加载更多

    在微信项目中有应用过几个上拉加载更多的组件,但总会出现一些兼容性方面的bug,需要各种补漏(注:组件都是基于iscroll实现的, iscroll原本就有些坑).Vux也有提供Scroller组件实现 ...

  8. 线性模型之LDA和PCA推导

    线性模型之LDA和PCA 线性判别分析LDA LDA是一种无监督学习的降维技术. 思想:投影后类内方差最小,类间方差最大,即期望同类实例投影后的协方差尽可能小,异类实例的投影后的类中心距离尽量大. 二 ...

  9. 设计模式-桥接模式(Bridge)

    桥接模式是构造型模式之一.把抽象(Abstraction)与行为实现(Implementor)分离开来,从而可以保持各部分的独立性以及应对它们的功能扩展. 角色和职责: 1.抽象类(Abstracti ...

  10. gh-ost

    目录 1.简介 2.为什么不用触发器 ? 3.命名由来 4.亮点 5.使用 6.它是如何工作的? 7.工作模式 7.1.模式1 -- 连上从库,在主库上修改 7.2.模式2 -- 直接在主库上修改 7 ...