Apache source code installation and virtual host configuration

Install Apache from source

1. Upload the required software packages for Apache source installation

Insert picture description here

2. Installation:

Installation order
apr—>apr-util—>pcre—>httpd
installation and compilation environment

yum -y install gcc gcc-c++

apr compile and install

tar xzf apr-1.4.6.tar.gz
cd apr-1.4.6
./configure --prefix=/usr/local/apr
make && make install

apr-util compile and install

tar xzf apr-util-1.5.1.tar.gz
cd apr-util-1.5.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
make && make install

pcre compile and install

tar xzf pcre-8.32.tar.gz
cd pcre-8.32
./configure --prefix=/usr/local/pcre
make && make install

httpd compile and install

tar zxf httpd-2.4.41.tar.gz 
cd httpd-2.4.41
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/ --enable-so --with-mpm=prefork
make && make install

Configure IP-based virtual hosting

Add IP to the host

Temporarily add (restart the network card invalid)
[root@localhost ~]# ifconfig eth0:0 192.168.153.155
[root@localhost ~]# ifconfig eth0:1 192.168.153.156
View the effect
Insert picture description here
Permanently add
Copy the network card configuration file and edit it
Insert picture description here
Insert picture description here
Restart the network card to view the result
Insert picture description here
creation The website root directory and test page of the two virtual hosts
[root@localhost ~]# mkdir /opt/1806A
[root@localhost ~]# mkdir /opt/1806B
[root@localhost ~]# echo “1806A”> /opt/ 1806A/index.html
[root@localhost ~]# echo “1806B”> /opt/1806B/index.html

Modify Apache's main configuration file

Location: /usr/local/apache/conf/httpd.conf
Insert picture description here
Authorize the two website root directories of the virtual host,
Insert picture description here
otherwise it will report an access denied error, the status code is 403
Insert picture description here

Uncomment the line containing the virtual host
Insert picture description here

Edit virtual host configuration file

Location: /usr/local/apache/conf/extra/httpd-vhosts.conf
Insert picture description here
Open Apache service to
Insert picture description here
see the effect
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46674735/article/details/109641912