源代码安装apache服务器

来源:互联网 发布:淘宝大学好不好 编辑:程序博客网 时间:2024/05/16 16:23

    apache是流行的http(超文本传输协议)服务器。http是让www(万维网)工作起来的协议。

1、
    去http://httpd.apache.org/ 下载httpd-2.2.34.tar.gz
    去http://apr.apache.org/ 下载apr-1.6.2.tar.gz和apr-util-1.6.0.tar.gz

2、先安装apr

 cd apr-1.6.2/ //--prefix指定安装位置 ./configure --prefix=/usr/local/apr //编译,需要已经安装了gcc编译器 make//安装需要root权限,ubuntu下用sudo sudo make install

3、安装apr-util

cd ../apr-util-1.6.0///指定安装目录以及依赖apr的位置,.configure --help可以看到相关语法 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmake    //这时会提示fatal error: expat.h: No such file or directory,先跳到4sudo make install

4、

sudo apt-get install libexpat1-dev

5、安装apache

cd httpd-2.2.34///--enable-module=shared以后可以把模块编译成动态共享对象,让apache启动时动态加载。以后需要加载新模块,只需要在配置文件中设置即可./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-module=sharedmakesudo make install//这时提示httpd:could not reliably determine the server's fullyqualified domain name

6、修改httpd.conf

cd usr/local/apache/conf/sudo gedit httpd.conf 在#ServerName www.example.com:80下加,即修改服务器名称和监听端口号ServerName localhost:80

httpd.conf指定apache监听端口,需要动态加载的模块,服务器根目录,默认加载的根文件,

7、启动apache服务器

sudo /usr/local/apache/bin/apachectl start//cp /usr/local/apache/bin/apachectl   /usr/sbin///sudo apachectl start 

在浏览器输入http://localhost出现It works!

8、为php动态模块的调入做准备
gedit /usr/local/apache/conf/httpd.conf

找到:
AddType application/x-gzip .gz .tgz

在下面添加:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

找到:
DirectoryIndex index.html

在后面添加 index.php:
DirectoryIndex index.html index.php

找到:
#ServerName www.example.com:80

修改为:
ServerName 127.0.0.1:80 或者 ServerName localhost:80

原创粉丝点击