轉載修改自:
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/
完!