centos安裝apache

來源:互聯網
上載者:User

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

完!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.