Home > php教程 > php手册 > PHP开发环境的配置(Linux平台上安装Apache和PHP)

PHP开发环境的配置(Linux平台上安装Apache和PHP)

WBOY
Release: 2016-06-13 09:02:34
Original
857 people have browsed it

PHP开发环境的配置(Linux平台上安装Apache和PHP)

PHP开发环境的配置(Linux平台上安装Apache和php):

下载Apache (httpd-2.4.12.tar.gz)、下载PHP(php-5.6.9.tar.gz)、下载与PHP安装相关的libxml2(libxml2-2.7.8.tar.gz)、下载与Apache安装相关的三个文件:apr(apr-1.5.2.tar.gz)、apr-util(apr-util-1.5.4.tar.gz)、pcre (pcre-8.10.zip)

(1)安装Apache:在安装apache之前必须先安装apr、apr-util和pcre,否则会出错:

安装apr:

Gunzip apr-1.5.2.tar.gz

Tar xvf apr-1.5.2.tar

进入apr-1.5.2目录,然后执行:

./configure --prefix=/usr/local/apr

Make && make install

 

安装apr-util:

解压后进入apr-util目录,然后执行:

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

Make && make install

 

安装pcre:在安装之前,必须先安装gcc,否则无法编译pcre文件

安装gcc:yum -y install gcc+ gcc-c++

然后安装pcre:

解压后进入pcre目录,然后执行:

./configure --prefix=/usr/local/pcre

Make && make install

 

安装好这几个文件后,可以安装apache了,解压httpd-2.4.12.tar.gz:

Gunzip httpd-2.4.12.tar.gz

Tar xvf httpd-2.4.12.tar

进入解压目录:cd httpd-2.4.12,然后执行:

./configure --prefix=/usr/local/apache --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util \

--with-pcre=/usr/local/pcre

Make && make install

 

(2)安装PHP:

安装php之前先安装libxml2:

解压后进入目录:libxml2-2.7.8,然后执行:

./configure --prefix=/usr/local/libxml2

Make && make install

 

安装php:解压后进入目录php-5.6.9,然后执行:

./configure --prefix=/usr/local/php --with-libxml-dir=/usr/local/libxml2 --with-apxs2=/usr/local/apache/bin/apxs

Make && make install

 

安装好php之后,将解压后的php-5.6.9目录里的php.ini-development复制到下面目录:

cp php.ini-development /usr/local/php/lib/php.ini

 

(3)配置Apache的conf文件夹里面的httpd-conf,添加下面内容(如果不存在的话):

LoadModule处添加LoadModule php5_module module/libphp5.so

在AddTypeapplication处添加AddType application/x-httpd-php .php

(4)启动或者重启Apache:

/usr/local/apache/bin/apachectl restart (或者start)

(5)测试Apache和PHP安装是否正确:

进入Apache里面的htdocs目录下面,

[root@Masterpc htdocs]# vim hello.php

echo "Hello world!";

phpinfo();

?>

在浏览器输入:http://172.16.2.42/hello.php (本人linux主机的ip地址是 172.16.2.42,通过远程访问),访问成功则显示如下:

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template