httpd2.4编译安装 和多站点配置

我是安装在Centos5.5上面的。首先去官网http://httpd.apache.org/查看下载最新的。它还有个依赖apr apr-util,和一个pcre(C语言编写的正则表达式数库)还有注意地址。路径。

wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.23.tar.gz
依赖:APR包 pcre(一个用C语言编写的正则表达式函数库)
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.gz
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.gz

tar zxvf apr-1.5.2.tar.gz //解包
cd apr-1.5.2

./configure --prefix=/usr/local/apr
make && make install

tar zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

make && make install

yum install pcre pcre-devel -y //这些yum的安装,就行了

tar zxvf httpd-2.4.23.tar.gz
cd httpd-2.4.23
./configure --prefix=/usr/local/httpd --enable-MODULE=shared --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

make && make install

然后就是打IP到自己的浏览器去。看见 It works! 表示可以了。

下面的一步就是开机启动。
本来百度的一些出来,结果做一些放上去发现不行,算了自己写吧。

需要了解一下,下面的东西
创建一个服务脚本,
#add for chkconfig
#chkconfig:35 80 10
#processname:myhttpd //服务名

/80代表启动优先级 10代表关闭优先级

0-关机
1-单机用户模式
2-多用户,但是没有NFS,不能使用网络
3-完全多用户模式(标注模式)
4-保留
5-桌面模式
6-重新启动
一般我们用3,5即可

//下面直接操作了。

cd /etc/init.d
vim myhttpd


#add for chkconfig 
#chkconfig:35 80 10 
#processname:myhttpd   

/usr/local/httpd/bin/apachectl start

:wq

chmod +x myhttpd
chkconfig --add myhttpd
chkconfig myhttpd on
chkconfig //直接可以看开启的模式,看看myhttpd有没有开启

我这样搞,的确感觉不是最好的方法,不过我已经实现开机启动。行了。
ps -ef | grep httpd //这样可以查看有没有httpd的进程
/usr/local/httpd/bin/apachectl start
/usr/local/httpd/bin/apachectl stop
/usr/local/httpd/bin/apachectl restart

如果想要 service apache2 start,也可以实现,就是在写个shell脚本,
例如vim apache2

#add for chkconfig
#chkconfig:35 80 10
#description:i am httpd22222
#processname:huang123

start()
{

/usr/local/httpd/bin/apachectl start
}
stop()
{

/usr/local/httpd/bin/apachectl stop
}
restart()
{
/usr/local/httpd/bin/apachectl restart
}

   case $1 in
     start )
     start 
     ;;
    stop)
     stop
    ;;
    restart)
     restart
    ;;

    *)
     echo "no"
   ;;
   esac

:wq //保存退出

之后的步骤和上面的一样,就可以service apache2 start , service apache2 stop
不过我喜欢了/usr/local/httpd/bin/apachectl restart,没有什么原因

下面的就是多站点配置。
首先说明就是2.4的配置和2.3。2.2有些不同

/usr/local/httpd/conf //我的是编译安装,和yum安装的路径不同,读者注意地址

#Include conf/extra/httpd-vhosts.conf //把#号去掉变成 Include conf/extra/httpd-vhosts.conf 。就是没有了#号

vim /usr/local/httpd/conf/extra/httpd-vhosts.conf //在这里多站点配置

Listen 80

ServerAdmin [email protected] //服务器邮箱,一般不用,根据情况
DocumentRoot "/usr/local/httpd/docs/" //网站的目录
ServerName dummy-host.example.com //网站的域名
ServerAlias www.dummy-host.example.com //绑定多个域名
DirectoryIndex index.php //设置默认的访问的页面
ErrorLog "logs/dummy-error_log" //错误日志
CustomLog "logs/access_log" common //访问日志

Options FollowSymLinks //代表禁止显示目录结构
AllowOverride all //允许.htaccess 生效,none就是不生效
Require all granted� //允许所有人进行访问

//上面的参数参考一下,记住这个是2.4版本的
我在跟目录下创建了一个www里面写了一个index.html。随便写点东西。

Listen 8888

DocumentRoot "/www/"
ServerName localhost:8888

        
        Options FollowSymLinks  
        AllowOverride all   
        Require all granted�  
    

好了,我成功了,浏览器访问localhost 和 localhost:8888 是不同的结果完成任务。耐心看吧。

你可能感兴趣的:(httpd2.4编译安装 和多站点配置)