阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 下编译安装PHP

145次阅读
没有评论

共计 9330 个字符,预计需要花费 24 分钟才能阅读完成。

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

深入理解 PHP 中的 ini 配置 http://www.linuxidc.com/Linux/2016-02/128442.htm

剖析 PHP 脚本的超时机制 http://www.linuxidc.com/Linux/2016-02/128441.htm

Ubuntu 14.04 下搭建 PHP 开发环境 PDF  http://www.linuxidc.com/Linux/2016-02/128330.htm

PHP 7 革新与性能优化 http://www.linuxidc.com/Linux/2015-09/123136.htm

PHP 7,你值得拥有  http://www.linuxidc.com/Linux/2015-06/118847.htm 

在 CentOS 7.x / Fedora 21 上面体验 PHP 7.0  http://www.linuxidc.com/Linux/2015-05/117960.htm 

CentOS 6.3 安装 LNMP (PHP 5.4,MyySQL5.6) http://www.linuxidc.com/Linux/2013-04/82069.htm 

在部署 LNMP 的时候遇到 Nginx 启动失败的 2 个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm 

Ubuntu 安装 Nginx php5-fpm MySQL(LNMP 环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm 

《细说 PHP》高清扫描 PDF+ 光盘源码 + 全套教学视频 http://www.linuxidc.com/Linux/2014-03/97536.htm 

CentOS 6 中配置 PHP 的 LNMP 的开发环境  http://www.linuxidc.com/Linux/2013-12/93869.htm 

PHP 的详细介绍 :请点这里
PHP 的下载地址 :请点这里

更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-03/128958.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计9330字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中