提示:本教程使用的是Apache编译安装的方式,相对而言较困难,对于初学者,建议直接使用ubuntu的安装包管理工具apt-get命令安装:
sudo apt-get install apache2
在安装Apache之前,必须要安装它所依赖的类库,如下步骤本人亲测,注意下载上面提到的包时需解压,下面的命令都是在进入解压后的目录下执行的。
1.安装libtool
从http://www.gnu.org/software/libtool/下载libtool
./configure
make
sudo make install
2.安装expat
从http://sourceforge.net/projects/expat/下载expat,XML Parser
./configure
make
sudo make install
3.安装pcre
从http://pcre.org/下载pcre(Perl Compatible Regular Expressions)依赖库
./configure --prefix=/usr/local/pcre
make
sudo make install
这里的--prefix表示设置安装目录.
4.安装APR(Apache Portable Runtime)
从http://apr.apache.org/download.cgi处下载APR 1.4.6与APR-util 1.5.2
4.1安装APR
./configure --prefix=/usr/local/apr
make
sudo make install
4.2安装APR-util
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
sudo make install
5.安装Apache
从Apache的官网http://httpd.apache.org/下载最近的Apache服务器包,我下载的是最新的httpd-2.4.4.tar.gz,2.4.4版。
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
make
sudo make install
6.检证安装
检查配置是否正常,输入如下命令:
cd /usr/local/apache2/bin
进入apache的bin目录,执行命令:
sudo ./apachectl configtest
测试配置信息是否正确,这时会出现一个错误:httpd: Could not reliably determine the server's fully qualified domain name:
解决办法,输入如下命令:
sudo gedit ../conf/httpd.conf
打开gedit编辑器,修改httpd.conf文件,将里面的大概187行#ServerName www.example.com:80 注释去掉并改为ServerName localhost:80即可,参考: http://www.cnblogs.com/52linux/archive/2012/03/24/2415637.html
再次运行:sudo ./apachectl configtest,提示:Syntax OK
启动服务:
sudo ./apachectl start
对应停止命令为stop, 重启为restart。
运行start命令后,在浏览器中输入http://localhost,出现如下页面就说明Apache安装成功:
这里运行的页面为<apach安装目录>/htdocs目录下的index.html文件,从这可知,htdocs为Apache默认的web根目录。