安装过Apache之后就是安装php了,这个也很简单,需要改一下配置信息就可以了
[root@localhost ~]# yum install libxml2-devel curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel net-snmp net-snmp-devel
[root@localhost src]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
[root@localhost src]# tar zxvf libiconv-1.14.tar.gz
[root@localhost src]# cd libiconv-1.14
[root@localhost libiconv-1.14]# ./configure --prefix=/usr/local/php/libiconv
[root@localhost libiconv-1.14]# make && make install
[root@localhost src]# wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
[root@localhost src]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@localhost src]# cd libmcrypt-2.5.8
[root@localhost libmcrypt-2.5.8]# ./configure
[root@localhost libmcrypt-2.5.8]# make && make install
[root@localhost libltdl]# /sbin/ldconfig && cd libltdl/
[root@localhost libltdl]# ./configure --enable-ltdl-install
[root@localhost libltdl]# make && make install
[root@localhost src]# wget http://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
[root@localhost src]# tar zxvf mhash-0.9.9.9.tar.gz
[root@localhost src]# cd mhash-0.9.9.9
[root@localhost mhash-0.9.9.9]# ./configure
[root@localhost mhash-0.9.9.9]# make && make install
[root@localhost src]# wget http://nchc.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
[root@localhost src]# tar zxvf mcrypt-2.6.8.tar.gz
[root@localhost src]# cd mcrypt-2.6.8
[root@localhost mcrypt-2.6.8]# /sbin/ldconfig && export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
[root@localhost mcrypt-2.6.8]# ./configure
[root@localhost mcrypt-2.6.8]# make && make install
[root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.15.tar.gz
[root@localhost src]# tar zxvf php-5.6.15.tar.gz
[root@localhost src]# cd php-5.6.15
[root@localhost php-5.6.15]# ./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-iconv=/usr/local/php/libiconv \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-pear \
--with-freetype-dir \
--with-zlib \
--with-libxml-dir \
--with-iconv-dir \
--with-xmlrpc \
--with-mhash \
--with-mcrypt \
--with-curl \
--with-openssl \
--with-snmp \
--with-gettext \
--enable-pdo \
--enable-mbstring \
--enable-ctype \
--enable-simplexml \
--enable-ftp \
--enable-sockets \
--enable-gd-native-ttf \
--enable-sysvsem \
--enable-exif \
--enable-sysvshm \
--enable-xml \
--enable-dom \
--enable-simplexml \
--enable-shmop \
--enable-zip \
--enable-mbregex \
--enable-bcmath \
--enable-inline-optimization \
--enable-soap
[root@localhost php-5.6.15]# make && make install
[root@localhost php-5.6.15]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost ~]# ln -s /usr/local/php/bin/* /usr/sbin/
以下就是配置信息:修改配置文件: /usr/local/apache/conf/httpd.conf
配置 httpd.conf让apache支持PHP
# vi /usr/local/apache/conf/httpd.conf
php安装完后会自动在httpd.conf加上下面一行(若无,请手动添加):
LoadModule php5_module modules/libphp5.so
找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
重启apache
# /usr/local/apache/bin/apachectl restart
测试:
在/usr/local/apache/htdocs文件夹下创建一个test.php文件
文件的内容:
<?php
phpinfo();
?>
在浏览器中输入例如: http://192.168.137.128/test.php
成功:出现php的相关配置
失败:错误提示