服务器篇04-配置apache编译安装

  • 来源:
  • 更新日期:2018-05-04

摘要:安装apache 安装apache所需环境组件 yum -y install gcc gcc-c++ autoconf automake make cmake pcre* openssl* libtool ncurses-devel libxm12-devel bison zlib-devel 下载apache编译安装包

安装apache

安装apache所需环境组件

002UASMrzy7605pjKJv15&690.jpg

yum -y install gcc gcc-c++ autoconf automake make cmake pcre* openssl* libtool ncurses-devel libxm12-devel bison zlib-devel

下载apache编译安装包

wget 

==注意!如遇到rm: cannot remove \'libtoolT\': No such file or directory问题,可以vi编辑configure文件,搜索RM=\'$RM\',更改为RM=\'$RM -f\'保存退出即可==

tar xvf apr-1.5.2.tar.gz cd apr-1.5.2 ./configure --prefix=/usr/local/apr make && make install

编译安装apr-util

tar xvf apr-util-1.5.4.tar.gz cd apr-util-1.5.4 ./configure --with-apr=/usr/local/apr make && make install

编译安装apache,安装常用的apache组件

tar xvf httpd-2.4.25.tar.gz cd 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/apr make && make install

新建网站管理用户和目录并赋予权限

useradd www mkdir -p /www/wwwroot/www.test.com touch /www/wwwroot/www.test.com/index.html echo \'this is web test !!!\' > /www/wwwroot/www.test.com/index.html chmod -R 755 /www chown -R www.www /www

备份并修改配置文件

cp /usr/local/apache2/conf/httpd.conf /usr/local/apache2/conf/httpd.conf.bak vi /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 start echo \'/usr/local/apache2/bin/apachectl start\' >> /etc/rc.local

可在配置文件中添加链接配置文件,如:

Include /usr/local/apache2/vhost/*.conf

虚拟主机配置示例

<VirtualHost *:80> ServerAdmin web@email.com 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测试