日期:2014-05-17  浏览次数:20826 次

php5.4安装与配置apache

在ubuntu10.0.4环境中。。

?

1.下载安装php-5.4.0.tar.gz

下载地址:? PHP website, http://www.php.net/?

?

然后解压

#tar zxvf php-5.4.0.tar.gz

#cd? php-5.4.0
#./configure --with-apxs2=/opt/apache/bin/apxs --prefix=/opt/php5

?

如果会提示:

xml2-config not found. Please check your libxml2 installation

操作以下步骤:

#cd ~/Downloads

#sudo? wget ftp://xmlsoft.org/libxml2/LATEST_LIBXML2

#sudo tar -zxvf LATEST_LIBXML2

#cd libxml2-2.7.8/

#./configure

#make

#sudo make install

?

?

configure之后没问题的话,就继续编译安装php了。

#cd ~/Downloads/php-5.4.0

#make

#sudo make install

加入php配置文件

#cp php.ini-development? /opt/php5/lib/php.ini

?

2.配置

# sudo vi /opt/apache/conf/httpd.conf
在httpd.conf加入以下配置:

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>
?

?

?

3.安装完毕,测试下,

#cd /opt/apache/htdocs/??????????????? 这里htdocs是网页根目录

#sudo vi phpinfo.php

编辑phpinfo.php内容如下:

<html>
<head>
	<title>PHP Test</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
	<h1>PHP Test</h1>
	<p>
	<b>An Example of PHP in Action</b><br />
		<?php echo "The Current Date and Time is: <br>";
			echo date("g:i A l, F j Y.");?>
	</p>

	<h2>PHP Information</h2>
	<p>
		<?php phpinfo(); ?>
	</p>
</body>
</html>
?

然后启动apache,

#sudo /opt/apache/bin/apachectl start
http://localhost/phpinfo.php 应该可以看到内容了,哈哈

?

?

4.参考

http://dan.drydog.com/apache2php.html

?http://www.php.net/manual/zh/install.unix.apache2.php