CentOS 下源码安装php

下载编译安装php 5.3.6:

http://php.net/downloads.php

sudo yum install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel libtool-ltdl-devel
tar -jxvf php-5.3.6.tar.bz2
cd php-5.3.6
./configure --prefix=/opt/php -with-apxs2=/opt/httpd/bin/apxs --with-curl --with-mcrypt --enable-mbstring --with-iconv --with-gd -with-jpeg-dir=/usr/local/lib --enable-pdo --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd
make
sudo make install
sudo cp php.ini-development /opt/php/lib/php.ini
sudo ln -s /opt/php/bin/php /usr/bin/php
sudo vi /opt/php/lib/php.ini

把include_path前面的分号删除,改成include_path = "/opt/php/lib/php"
sudo vi /opt/httpd/conf/httpd.conf
在最下面加入一行AddHandler application/x-httpd-php .php
sudo /opt/httpd/bin/httpd -k restart
sudo vi /opt/httpd/htdocs/phpinfo.php



####################个人从头安装到尾###################################################################


 
 

环境:centos X64 最小化安装 

php版本:php-5.4.3

安装前.先安装些软件和库文件

yum install -y gcc gcc-c++  make zlib zlib-devel pcre pcre-devel  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

领导要我们自己手动装 不允许我们直接用yum 所以上面的都没执行

编译安装PHP

进入php的解压目录

./configure --prefix=/usr/local/php --enable-fpm  --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 --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-apxs2=/usr/local/apache2/bin/apxs

运行之后遇到的问题:

error 1

checking for xml2-config path... configure: error: xml2-config not found. Please check your libxml2 installation.

(看提示就明白 是一个lib库没装  先用 yum search 名字 看是否能搜到名字 ,找到名字后 把软件包 开发包装上)

解决办法

yum install libxml2-devel.x86_64

error 2

checking for pkg-config... /usr/bin/pkg-config configure: error: Cannot find OpenSSL's <evp.h>

这是ssl没装

解决办法

 yum  install  openssl.x86_64 openssl-devel.x86_64 -y

error 3

checking for BZip2 in default path... not found configure: error: Please reinstall the BZip2 distribution

这是bzip2软件包没有安装

解决办法

yum install bzip2-devel.x86_64 -y

error 4

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

curl和curl库文件没有安装

解决办法

yum install libcurl.x86_64 libcurl-devel.x86_64 -y

error 5

checking whether to enable JIS-mapped Japanese font support in GD... no checking for fabsf... yes checking for floorf... yes configure: error: jpeglib.h not found

GD库没有安装

解决办法

yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y

error 6

checking for stdarg.h... (cached) yes checking for mcrypt support... yes configure: error: mcrypt.h not found. Please reinstall libmcrypt.

libmcrypt库没有安装 ,要是不能用yun安装的话  就要去下载个gz包 自己编译安装

(编译安装  ./configure --piefix=/usr/local/libmcrypt   make && make install)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

要是错误里面含有mysql的  那是mysql-devel 没有安装

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error 7

.再次编译,就没有遇到问题了,虽然显示了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了。)

出现

Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c

+--------------------------------------------------------------------+

| License:                                                           |

| This software is subject to the PHP License, available in this     |

| distribution in the file LICENSE.  By continuing this installation |

| process, you are bound by the terms of this license agreement.     |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                            |

+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec

config.status: creating main/build-defs.h

config.status: creating scripts/phpize

config.status: creating scripts/man1/phpize.1

config.status: creating scripts/php-config

config.status: creating scripts/man1/php-config.1

config.status: creating sapi/cli/php.1

config.status: creating sapi/fpm/php-fpm.conf

config.status: creating sapi/fpm/init.d.php-fpm

config.status: creating sapi/fpm/php-fpm.8

config.status: creating sapi/fpm/status.html

config.status: creating main/php_config.h

config.status: executing default commands

表示安装成功

 make  && make install

make完成之后  到php的解压目录 找出php.ini-production 复制到 /usr/local/php/lib/ 下 文件名改成php.ini

cp php.ini-production /usr/local/php/lib/php.ini 

完成..

PS:不知道美国那边的源是不是好一些 很多的包 在中国需要手动下载  在美国的服务器上 能直接用yum.......

人生其实就这样,睁一只眼,闭一只眼,就这样过去了
LoadModule  php5_module  modules/libphp5.so  AddType application/x-httpd-php  .php ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

         然后重启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,让其支持短标签(我看注释这个默认是打开的)。

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

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值