1.获取安装文件: http://www.php.net/downloads.php php-5.3.8.tar.gz
获取安装php需要的支持文件:http://download.csdn.net/download/netlong339/1351852 libxml2-2.6.32.tar.gz
2.安装libxml2
tar zxvf libxml2-2.6.32.tar.gz
cd libxml2-2.6.32
./configure --prefix=/usr/local/libxml2
make
make install
如果安装成功以后,在/usr/local/libxml2/目录下将生成bin、include、lib、man和share五个目录。在后面安装PHP5源代码包的配置时,会通过在configure命令的选项中加上"--with-libxml-dir=/usr/ local/libxml2"选项,用于指定安装libxml2库文件的位置。
3.安装php5
#tar zvxf php-5.3.8.tar.gz
#cd php-5.3.8
#./configure --prefix=/usr/local/php --with-mysql-dir=/user/local/mysql --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/local/libxml2
#make
#make install
4.重新配置apache2让他支持php
- 配置 httpd.conf 让apache支持PHP:
# vi /usr/local/apache/conf/httpd.conf
找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容
AddType application/x-httpd-php .php (.前面有空格)
AddType application/x-httpd-php-source .phps (.前面有空格)
cp php-5.3.8/php.ini.dist /usr/local/php/lib/php.ini
(如果没有php.ini.dist 则把php.ini-development php.ini-production中的任何一个重命名为php.ini.dist即可。)
修改php.ini文件 register_globals = On
service apache restart
5.测试php是否成功安装
写一个php测试页info.php,放到apache2/htdocs中。
<?php
phpinfo();
?>;
在浏览器中输入:服务器地址/info.php
如果能正常显示出php的信息,则说明Apche+Mysql+PHP安装成功!
解决:
httpd: Syntax error on line 114 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
百度了一下基本问题就是SELinux保护模式引起的
1、关闭SELINUX的方法:
编辑/etc/selinux/config,找到这段:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=enforcing
把 SELINUX=enforcing 注释掉:#SELINUX=enforcing ,然后新加一行为:
SELINUX=disabled
保存,关闭。
编辑/etc/sysconfig/selinux,找到:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=enforcing
如果SELINUX已经是 SELINUX=disabled,那么就不用改了,否则就把SELINUX=enforcing 注释掉,新加一行:
SELINUX=disabled
保存,退出。重启
如果你碰到其他类似提示:
cannot restore segment prot after reloc: Permission denied
哪应该是SELinux的问题,可以考虑把它关闭。
2、不关闭SELINUX的方法:
# setenforce 0
# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so
# service httpd restart
# setenforce 1
实验了一下确实管用apapche启动正常,php正常显示。