安装apache安装apache所需环境组件yum -y install gcc gcc-c++ autoconf automake make cmake pcre* openssl* libtool
安装apache
安装apache所需环境组件
yum -y install gcc gcc-c++ autoconf automake make cmake pcre* openssl* libtool ncurses-devel libxm12-devel bison zlib-devel
下载apache编译安装包
wget http://apache.fayea.com/httpd/httpd-2.4.25.tar.gz wget http://apache.fayea.com/apr/apr-1.5.2.tar.gzwget http://apache.fayea.com/apr/apr-util-1.5.4.tar.gz
编译安装apr
==注意!如遇到rm: cannot remove 'libtoolT': No such file or directory问题,可以vi编辑configure文件,搜索RM='$RM',更改为RM='$RM -f'保存退出即可==
tar xvf apr-1.5.2.tar.gzcd apr-1.5.2./configure --prefix=/usr/local/aprmake && make install
编译安装apr-util
tar xvf apr-util-1.5.4.tar.gzcd apr-util-1.5.4./configure --with-apr=/usr/local/aprmake && make install
编译安装apache,安装常用的apache组件
tar xvf httpd-2.4.25.tar.gzcd httpd-2.4.25./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl --enable-rewrite --with-mpm=worker --with-suexec-bin --with-apr=/usr/local/aprmake && make install
新建网站管理用户和目录并赋予权限
useradd wwwmkdir -p /www/wwwroot/www.test.comtouch /www/wwwroot/www.test.com/index.htmlecho 'this is web test !!!' > /www/wwwroot/www.test.com/index.htmlchmod -R 755 /wwwchown -R www.www /www
备份并修改配置文件
cp /usr/local/apache2/conf/httpd.conf /usr/local/apache2/conf/httpd.conf.bakvi /usr/local/apache2/conf/httpd.conf#搜索"#ServerName",添加ServerName localhost:80#搜索'daemon'把user和group用户改为自己新建的网站管理用户www#搜索'Require all denied'默认禁止所有,更改为'Require all granted'允许所有
/usr/local/apache2/bin/apachectl startecho '/usr/local/apache2/bin/apachectl start' >> /etc/rc.local
可在配置文件中添加链接配置文件,如:
Include /usr/local/apache2/vhost/*.conf
虚拟主机配置示例
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/www/wwwroot/www.test.com" ServerName www.test.com ServerAlias www.test.com test.com ErrorLog "/www/wwwlogs/www.test.com-error_log" CustomLog "/www/wwwlogs/www.test.com-access_log" combined #PATH <Directory "/www/wwwroot/www.test.com"> SetOutputFilter DEFLATE Options FollowSymLinks AllowOverride All Order allow,deny Allow from all DirectoryIndex index.html index.htm index.php default.php default.html default.htm </Directory></VirtualHost>
访问测试
curl http://127.0.0.1<html><body><h1>It works!</h1></body></html>
至此说明apache服务已经可以正常使用了,局域网也可绑定host访问www.test.com测试