centos安装apache

转载修改自:
http://www.centos.bz/2011/07/centos-compile-install-apache-from-source/
更多参考:
http://289972458.iteye.com/blog/1323258
http://www.centos.bz/2011/07/centos-compile-install-apache-from-source/

1) 卸载系统自带的httpd:
rpm -qa|grep httpd
rpm -e httpd-2.2.15-15.el6.centos --nodeps
rpm -e httpd-tools

2)找到最新版下载链接
从http://httpd.apache.org/download.cgi找到最新版下载链接,现在最版稳定版链接是:http://mirror.bjtu.edu.cn/apache//httpd/httpd-2.2.24.tar.gz

3)开始安装Apache
cd /usr/local/src
wget http://mirror.bjtu.edu.cn/apache//httpd/httpd-2.2.24.tar.gz
tar -zxvf httpd-2.2.19.tar.gz
cd httpd-2.2.19
./configure --prefix=/usr/local/apache --enable-vhost-alias --enable-rewrite --enable-info
make
make install

4)复制初始化文件和设置Apache开机启动
cp build/rpm/httpd.init /etc/init.d/httpd
chmod 755 /etc/init.d/httpd
chkconfig --add httpd
chkconfig --level 35 httpd on

5)创建符号链接
检查/etc/init.d/httpd看所需要的文件
CONFFILE=/etc/httpd/conf/httpd.conf
httpd=${HTTPD-/usr/sbin/httpd}
pidfile=${PIDFILE-/var/log/httpd/${prog}.pid}
lockfile=${LOCKFILE-/var/lock/subsys/${prog}}

符号链接如下:
ln -s /usr/local/apache/ /etc/httpd
ln -s /usr/local/apache/bin/httpd /usr/sbin/httpd
ln -s /usr/local/apache/bin/apachectl /usr/sbin/apachectl
ln -s /usr/local/apache/logs /var/log/httpd

6)启动/停止服务
service httpd restart
service httpd start
/usr/local/apache/bin/apachectl start
/usr/local/apache/bin/apachectl stop
/usr/local/apache/bin/apachectl status
/etc/init.d/httpd start
/etc/init.d/httpd stop
/etc/init.d/httpd restart

使用pgrep查找启动的进程。
pgrep httpd

7)在浏览器中查看:
http://192.168.0.120:80
如果看到it works,说明apache已经启动了。

8)apache配置文件
vi /usr/local/apache/conf/httpd.conf
更多的configure选项可参考http://httpd.apache.org/docs/2.2/programs/configure.html

9) 默认地apache配置文件中如下:

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/usr/local/apache/htdocs"

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/usr/local/apache/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>

如果你需要你的home目录可以访问,需要在documentroot下创建symbollink指向你的home,且确保home目录对所有人都有可执行权限。例如:

[AAA@Centos_AAA cgi-bin]$ ll -d /usr/local/apache/htdocs/~AAA
lrwxrwxrwx. 1 root root 9 Apr 7 09:44 /usr/local/apache/htdocs/~AAA -> /home/AAA
[AAA@Centos_AAA cgi-bin]$ ll -d /home/AAA
drwxr-xr-x. 38 AAA AAA 4096 Apr 7 11:10 /home/AAA

可以访问:http://192.168.0.120/~AAA/

完!

posted @ 2013-04-06 18:01  iTech  阅读(12400)  评论(2编辑  收藏  举报