安装PHP与Apache、mysql匹配

本文提供了一步一步的指导来帮助读者安装最新的PHP版本。包括从下载到配置的全过程,并解决了可能出现的问题,如缺少libxml2包及配置选项错误等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、http://www.php.net/downloads.php下载最新版本的PHP

2、存至/home目录  ,解压

tar -zxvf php-5.5.13.tar.gz  

3、编译

./configure --prefix=/usr/local/php5513 --with-apxs2=/usr/local/apache2.2.25/bin/apxs --with-config-file-path=/usr/local/lib--enable-track-vars --with-xml--with-MySQL

./configure --prefix=/usr/local/php5513 --with-apxs2=/usr/local/apache2.2.25/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql=/usr/local/mysql []

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/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --enable-track-vars, --with-xml

查看configure文件,里面没有--enable-track-vars, --with-xml,删除之。

注释:

//如果mysql是以rpm方式安装的,在编译apache的时候加入选项--with-mysql即启用mysql。如果不是rpm方式安装的要加编译选项比如--with-mysql=/usr/local/mysql等路 径才可以识别。【http://bbs.chinaunix.net/thread-1639517-1-1.html】

出现问题:

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

检查是否安装了libxml2:

rpm -qa |grep libxml2

没有显示。

libxml2库没装,安装库:apt-get install libxml2-dev

重新编译:

./configure --prefix=/usr/local/php5513 --with-apxs2=/usr/local/apache2.2.25/bin/apxs --with-config-file-path=/usr/local/lib --with-mysql=/usr/local/mysql

其中apache和mysql是根据你安装的目录名变,我的是 =/usr/local/php5513/bin/apxs 和==/usr/local/mysql

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

较新的PHP里的文件是php.ini-production与php.ini-development,任意拷贝一个。

网上的大多为老版本,代码为cp php.ini-dist /usr/local/lib/php.ini ,之前的--enable-track-vars --with-xml 也在较近的版本里没有,估计也是版本问题。


以dso方式安装php至/usr/local/php 设置配置文件目录为/usr/local/lib 开启mysql,xml支持

4、配置

vi /usr/local/apache/conf/httpd.conf 

 LoadModule php5_module        modules/libphp5.so

  
AddType application/x-httpd-php .php .phtml .php5 .inc//设置apache的默认文件名次序

AddType application/x-httpd-php-source .phps//设置php文件后缀


//在浏览器中打入 localhost/info.php ,就能看到php的信息了。如果还是出现的是 <? phpinfo(); ?> 字样的页面,那就是没有成功:( ,可能是您改变了apache的配制文件,忘记了重启apache服务器了,要重启一下试试看。【http://hi.baidu.com/dengyunwen/item/5f07842f39f5adf950fd8797】

5、启动服务

/usr/local/apache2.2.25/bin/apachectl start

6、测试

写个php测试页info.php:内容如下

<?php phpinfo(); ?>

正常的话,应该能看到php的信息了,恭喜你的Apche+Mysql+PHP安装成功 【貌似mysql没关系】


参考:

http://www.webjx.com/server/linux/server_linux_2008_01_28_3214.html

http://blog.sina.com.cn/s/blog_6ccd0a11010113kc.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值