[root@localhost apache2]# /usr/local/apache2/bin/apachectl start(源码包安装需要这样才能开启服务)
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
httpd (pid 902) already running 显示已经开启了,会出现命令的提示,解决这个问题
新建配置文件里面指定的虚拟主机目录,因为没有,那就要新建
cd /data/web/ (切换目录,在这个目录里面去新建)
mkdir test1 test2 log (新建两个存放网页目录的文件和一个存放日志的文件)
cd log/ (切换到日志的目录文件中)
touch test1.err.log test1.acc.log test2.err.log test2.acc.log (新建四个日志文件)
vim /data/web/test1/index.html (编辑两个网页文件便于测试)
this is test1 page
vim /data/web/test2/index.html
this is test2 page
访问测试 http://ip:8001 (看见this is test1 page 就ok了)
http://ip:8002 (看见this is test2 page 就ok了)
b)同ip不同域名同端口
vim /usr/local/apache2/conf/httpd.conf
修改配置文件
#####保存退出
重启服务
模拟ip出来
ifconfig eth0:0 172.16.1.10 up
ifconfig eth0:1 172.16.1.20 up
访问测试 http://172.16.1.10 (看见this is test1 page 就ok了)
http://172.16.1.20 (看见this is test2 page 就ok了)
3.系统用户的个人主页
a)修改配置文件
vim /usr/local/apache2/conf/httpd.conf
####把配置文件中的这两句前面的#去掉
LoadModule userdir_module modules/mod_userdir.so
Include conf/extra/httpd-userdir.conf
#####保存退出,这里就采用默认的路径
b)新建用户给出密码
#################################
useradd li
useradd liuh
passwd li(li)
passwd liu(liu)
#################################
c)在li和liu用户的宿主目录中新建文件
cd /home/li
mkdir public_html
cd public_html
vim index.html(为li用户新建自己的主页)
cd /home/liu
mkdir public_html
cd public_html
vim index.html(为liu用户新建自己的主页)
chmod o+x /home/li* (为宿主目录中的用户修改权限)
d)重启服务
#################访问浏览器##################
http://ip/~li/ (其中li为用户名)
###############################################
4.做授权认证
修改配置文件
vim /usr/local/apache2/conf/httpd.conf
#####添加这几句(用了一个虚拟目录)
Alias /test "/data/web"
Options Indexes MultiViews FollowSymLinks
AllowOverride All
AuthType basic
AuthName "welcome test"
AuthUserFile /usr/local/apache2/conf/httppwd
Require user liu
####保存退出
建立网页目录和文件
mkdir -p /data/web
vim /data/web/index.html
建立存储认证用户账号及口令的文件
/usr/local/apache2/bin/htpasswd -c /usr/local/apache2/conf/httppwd liu
New password:
Re-type new password:
(添加第二个,或者多个的时候都不需要-c了)
/usr/local/apache2/conf/httppwd 这个就是AuthUserFile认证用户文件的路径文件)
然后重启服务
访问 http://ip/test
输入用户名和密码
组的认证
修改配置文件
vim /usr/local/apache2/conf/httpd.conf
#####添加这几句(用了一个虚拟目录)
Alias /test "/data/web"
Options Indexes MultiViews FollowSymLinks
AllowOverride All
AuthType basic
AuthName "welcome test"
AuthUserFile /usr/local/apache2/conf/httppwd
AuthGroupFile /usr/local/apache2/conf/httpgrp
Require group admin
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$参考脚本$$$$$$$$$$$$$$$$$$$$$
运行脚本提示:
这个是一个脚本,运行这个脚本能够一次性成功安装完源码包搭建的apache,此脚本只供方便,我执行这个脚本是已经成功安装几遍了,此脚本运行成功,先要搭建好yum(如何搭建yum这里不在此介绍了),然后解压好所需的源码包。解压没有先后顺序,但是安装的时候有先后顺序。
tar zxvf httpd-2.4.3.tar.gz -C /usr/src/
tar zxvf apr-1.4.2.tar.gz -C /usr/src/
tar zxvf apr-util-1.3.10.tar.gz -C /usr/src/
tar zxvf pcre-8.11.tar.gz -C /usr/src/
然后在/usr/src/目录下面vim 一个文件
eg:vim httpd.sh
然后把下面的copy到httpd.sh里面保存退出在给httpd.sh添加可执行的权限
chmod +x /usr/src/httpd.sh
然后在执行脚本 /usr/src/httpd.sh
以下所有都是需要复制的内容(从#bin/bash都开始复制)
#bin/bash
echo "####first,use yum install this rpm####"
yum -y install gcc
yum -y install gcc-c++
yum -y install openssl-devel
echo "###second,install httpd the dependencies###"
echo "#####welcome to apr install#####"
cd /usr/src/apr-1.4.2
./configure --prefix=/usr/local/apr && make && make install
echo "#####apr is installed#####"
echo "#####welcome to apr-util install#####"
cd /usr/src/apr-util-1.3.10
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config && make && make install
echo "#####apr-util is installed#####"
echo "#####welcome to pcre install#####"
cd /usr/src/pcre-8.11
./configure --prefix=/usr/local/pcre && make && make install
echo "#####prce is installed#####"
echo "###now,install httpd###"
echo "#####welcome to httpd install######"
cd /usr/src/httpd-2.4.3
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-rewrite --enable-ssl --with-ssl=/usr/lib--enable-auth-digest --enable-cgi --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/apache2/htdocs && make && make install
echo "#####httpd is installed#####"
echo "####please check httpd is ok,if no error above before,please start httpd #####"