當前系統版本
[root@localhost ~]# uname -a
Linuxlocalhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# cat /etc/redhat-release
Red HatEnterprise Linux Server release 6.4 (Santiago)
關閉防火牆
[root@localhost ~]# service iptables stop
iptables:Flushing firewall rules: [ OK ]
iptables:Setting chains to policy ACCEPT: filter [ OK ]
iptables:Unloading modules: [ OK ]
啓動時關閉防火牆
[root@localhost ~]# chkconfig iptables off
創建目錄,掛載,安裝.
[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cd /mnt/cdrom/Packages/
[root@localhost Packages]# ls httpd*
測試
在創建APACHE會自動創建一個新的賬戶
[root@localhostPackages]# tail /etc/passwd
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
vcsa:x:69:69:virtual console memoryowner:/dev:/sbin/nologin
saslauth:x:499:76:"Saslauthduser":/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separatedSSH:/var/empty/sshd:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
Apache服務器安裝與基本配置
配置每個用戶的WEB站點
1.啓用配置每個用戶的WEB站點
[root@localhost conf]# vi/etc/httpd/conf/httpd.conf
<IfModule mod_userdir.c>
#
#UserDir is disabled by default since it can confirm the presence
#of a username on the system (depending on home directory
#permissions).
#
UserDir disabled root
#
#To enable requests to /~user/ to serve the user's public_html
#directory, remove the "UserDir disabled" line above, and uncomment
#the following line instead:
#
UserDir public_html
</IfModule>
#
# Control access to UserDirdirectories. The following is an example
# for a site where these directories arerestricted to read-only.
#
<Directory/home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatchIncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
重啓服務
[root@localhost conf]#service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
創建用戶
[root@localhost conf]#useradd alice
轉換成ALICE用戶
[root@localhostconf]# su - alice
創建目錄,更改權限
[alice@localhost ~]$ cd
[alice@localhost ~]$mkdir public_html
[alice@localhost ~]$ ll-d /home/alice/
drwx------. 3 alice alice4096 Aug 21 04:27 /home/alice/
[alice@localhost ~]$chmod 711 /home/alice/
[alice@localhost ~]$ ll-d /home/alice/
drwx--x--x. 3 alice alice4096 Aug 21 04:27 /home/alice/
進入目錄修改所創個人站點
[alice@localhostpublic_html]$ vi index.html
內容爲Alice's Web Site
檢測
創建虛擬目錄
[root@localhost ~]# mkdir/opt/bbs
[root@localhost ~]# ls-ld /opt/bbs
drwxr-xr-x 2 root root 4096 Aug 21 05:31/opt/bbs
創建測試頁
[root@localhost ~]# echo'BBS test page' > /opt/bbs/index.html
方法一:
[root@localhost ~]# ln -s/opt/bbs/ /var/www/html/bbs
[root@localhost ~]# ls -l/var/www/html/bbs
lrwxrwxrwx 1 root root 9 Aug 21 05:33/var/www/html/bbs -> /opt/bbs/
清除換方法
[root@localhost ~]# rm/var/www/html/bbs
rm: remove symbolic link`/var/www/html/bbs'? y
方法二:
[root@localhost ~]# vi/etc/httpd/conf/httpd.conf
清除
[root@localhost ~]# rm-rf /opt/bbs/
創建虛擬主機
配置域名解析和站點文件
[root@localhost ~]# mkdir/opt/crm
[root@localhost ~]# echo'CRM test page' > /opt/crm/index.html
[root@localhost ~]# mkdir/opt/oa
[root@localhost ~]# echo'OA test page' > /opt/oa/index.html
[root@localhost ~]# cd/etc/httpd/
[root@localhost httpd]#ls
conf conf.d logs modules run
[root@localhost httpd]#mkdir vhost-conf.d
[root@localhost httpd]#echo "Include vhost-conf.d/*.conf" >> conf/httpd.conf
[root@localhost httpd]#
配置基於端口的虛擬主機
[root@localhost httpd]#vi /etc/httpd/vhost-conf.d/vhost-ip.conf
Listen8001
Listen 8002
<VirtualHost *:8001>
DocumentRoot /opt/crm/
</VirtualHost>
<VirtualHost *:8002>
DocumentRoot /opt/oa/
</VirtualHost>
[root@localhost httpd]#apachectl configtest
Syntax OK
[root@localhost httpd]#service httpd restart
Stopping httpd: [ OK ]
Startinghttpd: [ OK ]
清除環境
[root@localhost crm]# rm-i /etc/httpd/vhost-conf.d/vhost-ip.conf
rm: remove regular file`/etc/httpd/vhost-conf.d/vhost-ip.conf'? y
[root@localhost crm]#
配置基於域名的虛擬機
[root@localhost crm]# vi/etc/httpd/vhost-conf.d/vhost-name.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName crm.abc.local
DocumentRoot /opt/crm/
</VirtualHost>
<VirtualHost *:80>
ServerName oa.abc.local
DocumentRoot /opt/oa/
</VirtualHost>
[root@localhost crm]#apachectl configtest
Syntax OK
[root@localhost crm]#service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]