PHP,一个嵌套的缩写名称,是英文超级文本预处理语言(PHP:Hypertext Preprocessor)的缩写。PHP 是一种 HTML 内嵌式的语言,PHP与微软的ASP颇有几分相似,都是一种在服务器端执行的嵌入HTML文档的脚本语言,语言的风格有类似于C语言,现在被很多的网站编程人员广泛的运用。

本次让我们完成PHP的编译安装,并让Apache支持PHP。

  • 首先我们先用yum仓库安装一些关联程序,:

yum install
libjpeg-devel
libpng-devel
freetype-devel
zlib-devel
gettext-devel
libXpm-devel
libxml2-devel
fontconfig-devel
openssl-devel
bzip2-devel

  • 安装GD库,用来处理和生成图片:
tar xzvf /opt/lamp/gd-2.0.35.tar.gz -C /opt    //解压软件包
cd /opt/gd/2.0.35    //移动到目录中
./configure --prefix=/usr/local/gd    //配置
make && make install    //编译安装
  • 安装PHP,进入PHP目录输入配置文本,并进行编译安装:

tar xjvf /opt/lamp/php-5.4.5.tar.bz2 -C /opt //解压软件包 cd /opt/php-5.4.5/ //移动到php目录 #输入配置文本: ./configure
--prefix=/usr/local/php
--with-apxs2=/usr/local/apache/bin/apxs
--with-gd
--with-mysql=/usr/local/mysql
--with-config-file-path=/etc
--enable-sqlite-utf8
--with-zlib-dir
--with-libxml-dir
--with-freetype-dir
--with-jpeg-dir
--with-png-dir
--with-ttf
--with-iconv
--with-openssl
--with-gettext
--enable-mbstring
--enable-gd-native-ttf
--enable-gd-jis-conv
--enable-static
--enable-zend-multibyte
--enable-inline-optimization
--enable-sockets
--enable-soap
--enable-ftp
--disable-ipv6

#编译安装: make && make install


解决make过程中的错误--可忽略----

vi /usr/local/gd/include/gd_io.h

void (*gd_free) (struct gdIOCtx *);

void (*data); //添加//

}
gdIOCtx;

cp php.ini-production /etc/php.ini //优化调整PHP//

  • 下面,我们来让Apache支持PHP:

vim /usr/local/apache/conf/httpd.conf //进入编辑httpd配置文件

找到 AddType application/x-gzip .gz .tgz 在下面添加如下内容 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps

LoadModule php5_module modules/libphp5.so //检查是否存在

DirectoryIndex index.html index.php(添加)//调整首页文件设置

  • 此时我们可以重启httpd服务并进行php测试:
#重启服务
service httpd restart
#创建一个php测试页
vim /usr/local/apache/htdocs/index.php
#添加以下内容
<?php
phpinfo();
?>
  • 用另一台机器访问测试php页: