1.1 安装PHP
步骤1: 将php-5.2.5.tar.gz复制到/usr/local中
cp php-5.2.5.tar.gz /usr/local
步骤2: 解压
cd /usr/local
tar xzvf php-5.2.5.tar.gz
步骤3:
cd php-5.2.5
./configure --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs
步骤4:
make
步骤5:
make test
【注意】
如果提示”/usr/local/php-5.2.5/sapi/cli/php:error while loading shared libraries: /usr/local/mysql/lib/libmysqlclient.so.16:cannot restore segment prot after reloc: Permission denied”
原因:SELinux
解决方法:chcon –t texrel_shlib_t /usr/local/mysql/lib/libmysqlclient.so.16
步骤6:
make install
1.2 配置PHP
步骤1: 将php.ini-dist复制到/etc/php.ini
cp php.ini-dist /etc/php.ini
步骤2: 修改apache的httpd.conf文件
vi /usr/local/apache/conf/httpd.conf
在DirectoryIndex 末尾添加index.php
DirectoryIndex index.html index.php
在AddType入口,加入如下代码
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
步骤3: 重新启动apache服务器
/usr/local/apache/bin/apachectl restart
【注意】
如果提示”httpd:Syntax error on line 53 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
解决方法:chcon –t texrel_shlib_t /usr/local/apache/modules/libphp5.so
1.3 测试PHP
步骤1: 在htdocs文件夹(缺省为/usr/local/apache/htdocs)中新建一个名为test.php的文件,内容如下:
<?php phpinfo();?>
步骤2: 重新启动apache
/usr/local/apache/bin/apachectl restart
步骤3: 在浏览器中输入http://localhost/test.php,确定在Apache下正确安装了PHP
【注意】
如果浏览器提示Forbidden You don’t have permission to access /test.php on this server
原因:文件的权限
解决:chmod 744 /usr/local/apache/htdocs/test.php