php5配合apache2源码的安装方式,os:centos5.*
首先是下载并解压缩你的php源码了。 解压缩使用tar命令
shell>cd php-5.2.17 进入php目录
shell>vim README 找到相应的安装环境和安装版本这段话
Apache 2.0 on Unix systems
This section contains notes and hints specific to Apache 2.0 installs
of PHP on Unix systems.
按照操作步骤进行
shell>./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5
configure: error: xml2-config not found. Please check your libxml2 installation.
错误是指xml2相关的东西没有安装
shell>yum list | grep xml2
libxml2.i386 2.6.26-2.1.12.el5_7.2 installed
libxml2.x86_64 2.6.26-2.1.12.el5_7.2 installed
libxml2-python.x86_64 2.6.26-2.1.12.el5_7.2 installed
libxml2-devel.i386 2.6.26-2.1.12.el5_7.2 updates
libxml2-devel.x86_64 2.6.26-2.1.12.el5_7.2 updates
shell>yum install libxml2-devel.x86_64
shell>./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5
OK,makefile文件生成
shell>make clean
shell>make
shell>make install
shell>cp php.ini-dist /usr/local/php5/php.ini 安装你的php.ini
shell>vim /usr/local/apache2/conf/httpd.conf
检查是否有这一行:LoadModule php5_module modules/libphp5.so
加入:AddType application/x-httpd-php-source .phps
shell>apachectl stop
shell>apachectl start 重启apache服务器
错误: Syntax error on line 146 of /usr/local/apache2/conf/httpd.conf:...
造成这个问题的主要原因是php和apache版本不兼容
因此,下载新版的php并按照上面的步骤重新执行,记得要删除php老版本文件。在最新版中php5.4,与上面所用的php5.2有所不同
shell>cp php.ini-dist /usr/local/php5/php.ini 改为 shell>cp php.ini-development /usr/local/php5/php.ini
AddType application/x-httpd-php-source .phps 改为
shell>vim /usr/local/apache2/conf/httpd.conf
# AddType allows you to add to or override the MIME configuration
# file specified in TypesConfig for specific file types.
#
#AddType application/x-gzip .tgz
#
#AddType for phptype
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.ph(p[2-6]?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
shell>apachectl stop
shell>apachectl start
OK,没有问题了
接下来我们测试一下:
shell>cd /usr/local/apache2/htdocs
shell>vim test.php
<?
phpinfo();
?>
在其它机子的浏览器输入:http://192.168.1.2/test.php
或者在自己的机子上输入:http://localhost/test.php
oK,你应该会看到一个关于php介绍的页面
congratulation you!
well done!