ubuntu下apache服务器搭建网站,Ubuntu安装Web服务器-Apache篇

时间:2024-10-12 12:17:01

讲解环境

linux ubuntu Ubuntu 10.04.3 x64 +Apache2

一、登陆你的系统,记得使用root

二、安装Apache

1、输入如下命令安装

#apt-get install apache2

正常情况下会给出如下提示,说明Apache2默认已经安装好了:

:~# apt-get install apache2

Reading package lists... Done

Building dependency tree... Done

apache2 is already the newest version.

0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

2、开启 Apache2 的伪静态

如果希望开启Apache2 伪静态 rewrite 支持,输入如下命令安装

#a2enmod rewrite

正常情况下会给出如下提示,说明已经安装成功:

:~# a2enmod rewrite

Module rewrite installed; run /etc//apache2 force-reload to enable.

或出现如下提示,表示已经开启了 rewrite

:~# a2enmod rewrite

Mudule rewrite already enabled

3、安装php环境

执行如下命令安装apache2的php5扩展和php的mysql扩展

#apt-get install libapache2-mod-php5 php5-gd php5-mysql php5-curl php5-mcrypt php5-common php-apc

如下提示:

:~# apt-get install libapache2-mod-php5 php5-gd php5-mysql php5-mcrypt

php5-common php-apc

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following extra packages will be installed:

libgd2-xpm libjpeg62 libt1-5 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6

libxpm4 php5-cli php5-common php-apc

Suggested packages:

php-pear libgd-tools php5-suhosin

The following NEW packages will be installed:

libapache2-mod-php5 libgd2-xpm libjpeg62 libt1-5 libx11-6 libx11-data

libxau6 libxcb1 libxdmcp6 libxpm4 php5-cli php5-common php5-gd php5-mysql php5-

mcrypt

0 upgraded, 15 newly installed, 0 to remove and 26 not upgraded.

Need to get 8128kB of archives.

After this operation, 22.7MB of additional disk space will be used.

Do you want to continue [Y/n]?

输入 Y,回车继续,以下表示安装完成。

重新启动apache2, 输入如下命令:

#/etc//apache2 restart

提示如下,表示启动成功:

:~# /etc//apache2 restart

* Restarting web server apache2

apache2: Could not reliably determine the server’s fully qualified domain name,

using 0.3.175.133 for ServerName

[ OK ]

测试站点

以上命令已经完整安装好一台Web服务器所具有的环境,以下来搭建一个最简单的站点。

web 的根目录位于 /var/www 你可以将自己的程序直接放到此目录。

如新建一个php测试页面  #vi /var/www/

然后按 i   开始编辑 ,把下面代码复制进去

phpinfo();

?>

按Esc取消编辑后,按:wq 保存。输入http://192.168.1.10/ 测试一下。