下载依赖包:
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.6.5.tar.gz wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
下载httpd
wget
安装编译依赖:
yum install gcc gcc-c++ libxml2-devel bzip2-devel libmcrypt-devel openssl-devel\ libcurl-devel libjpeg-devel libpng-devel freetype-devel readline-devel libxslt-devel\ perl-devel psmisc.x86_64 recode-devel libtidy-devel expat-devel curl-devel -y
解压依赖包并编译安装
tar -zxf apr-1.6.5.tar.gz cd apr-1.6.5 ./configure --prefix=/usr/local/apr-1.6.5 make && make install
tar -zxf apr-util-1.6.1.tar.gz cd apr-util-1.6.1 ./configure --prefix=/usr/local/apr-util-1.6.1 --with-apr=/usr/local/apr-1.6.5 make && make install
解压httpd并编译安装:
tar -zxf httpd-2.4.38.tar.gz ./configure --prefix=/usr/local/http-2.4.41 --sysconfdir=/usr/local/http-2.4.41/etc\ --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most\ --enable-mpms-shared=all --with-mpm=prefork --with-zlib --with-pcre\ --with-apr=/usr/local/apr-1.6.5 --with-apr-util=/usr/local/apr-util-1.6.1 make&&make install
启动httpd
./usr/local/http-2.4.41/bin/apachectl start
解决启动报ServerName错误提示
cd /usr/local/http-2.4.41/etc # # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # #ServerName www.example.com:80 ServerName www.example.com:80
配置端口多站点访问
1. 修改httpd.conf # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/usr/share/http" <Directory "/usr/share/http"> 2. Allowoverri 修改为All # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit AllowOverride None # 修改为 All # Controls who can get stuff from this server. Require all granted 3.释放virtual hosts # Virtual hosts #Include etc/extra/httpd-vhosts.conf Include etc/extra/httpd-vhosts.conf
修改httpd-vhost.conf
vi /usr/local/http-2.4.41/etc/extra/httpd-vhost.conf <VirtualHost *:8081> ServerAdmin [email protected] DocumentRoot "/usr/share/http/shop" ServerName dummy-host.example.com ServerAlias www.dummy-host.example.com ErrorLog "logs/shop-error_log" CustomLog "logs/shop-access_log" common </VirtualHost> <VirtualHost *:8082> ServerAdmin [email protected] DocumentRoot "/usr/share/http/blog" ServerName dummy-host2.example.com ErrorLog "logs/blog-error_log" CustomLog "logs/blog-access_log" common </VirtualHost>