Installing Apache2 Web server A on CentOS-8.4

CentOS-8.4 + Linux-8 source code compile and install Apache2 Web server "complete essence version

[subject index]

P-01) system & Environment

Running environment: Laboratory Virtual Environment

System model: ctenos-8.4-x86_ sixty-four

Linux version: linux-8-x86_ sixty-four

CPU & Memory: 4H + 4GB

P-02) preparation before installation

  1. 1 update CentOS-8 package
[root@localhost /]# dnf update
  1. 2 turn off the system firewall
[root@localhost /]# systemctl stop firewalld
  1. 3. Turn off the firewall and start up automatically
[root@localhost /]# systemctl disable firewalld
  1. 4 turn off SELINUX
[root@localhost /]# sed -ri '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config
setenforce 0

####P-03) dependency to be installed

[root@localhost /]# yum -y install gcc gcc-c++ make wget

P-04) [Apache] Component download

  1. 1 create a new Apache directory
  • To build the Web running environment of Apache+Ngnix, MySQL and php in Linux, create a new lanmpp home directory and apache subdirectory under the root directory:
[root@localhost ~]# mkdir lanmpp
[root@localhost ~]# mkdir /root/lanmpp/apache
  1. 2 download Apache & associated components
[root@localhost ~]# cd /root/lanmpp/apache
[root@localhost apache]# 
wget https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.48.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz
wget https://telkomuniversity.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.gz
wget https://telkomuniversity.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz

P-05) compile and install [Apache] components

  1. 1. Install [zlib] (it is not necessary to specify the installation directory)
[root@localhost apache]#
tar -xvf zlib-1.2.11.tar.gz
rm -rf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
./configure
make && make install
  1. 2. Install [pcre] (there is no need to specify the installation directory)
  • Apache needs to rely on pcre software, but due to the high version of Apache, the pre installed pcre can not be used. It just needs to install the appropriate version manually.
cd ..
tar -xvf pcre-8.45.tar.gz
rm -rf pcre-8.45.tar.gz
cd pcre-8.45/
./configure
make && make install

P-06) compile and install [Apache]

  1. 1 install the dependent expat library necessary for apr operation
  • Special note: the Expat library is missing and needs to be installed first. Otherwise, an error will occur when compiling apr... [apr util] fatal error [: expat.h:] does not have that file or directory:
cd ..
yum install -y  expat-devel
Dependency resolution.
===================================================================================
 software package               framework            edition                   Warehouse             size
===================================================================================
install:
 expat-devel          x86_64          2.2.5-4.el8            baseos           55 k

Transaction summary
===================================================================================
Install 1 package

Total downloads: 55 k
 Installation size: 156 k
 Download package:
expat-devel-2.2.5-4.el8.x86_64.rpm                 173 kB/s |  55 kB     00:00    
-----------------------------------------------------------------------------------
  1. 2 specify the Apache installation path
  • Specify the installation path in [– prefix=/usr/local/apache2] format
  1. 3 due to Apache source package 2.4* There is no dependency package integrating apr in the version by default, so the dependency problem needs to be solved in advance.
//[root@localhost apache]#
tar -xvf apr-1.7.0.tar.gz
rm -rf apr-1.7.0.tar.gz
tar -xvf apr-util-1.6.1.tar.gz
rm -rf apr-util-1.6.1.tar.gz
  1. 4 extract the Apache source package
//[root@localhost apache]#
tar -xvf httpd-2.4.48.tar.gz
rm -rf httpd-2.4.48.tar.gz
  1. 5 Apache encrypted transmission module mod_ssl, you need the first mock exam to install this module.
yum -y install openssl-devel
Dependency resolution.
===================================================================================
 software package              framework         edition                   Warehouse                 size
===================================================================================
upgrade:
 openssl             x86_64       1:1.1.1k-4.el8         Stream-BaseOS       709 k
 openssl-devel       x86_64       1:1.1.1k-4.el8         Stream-BaseOS       2.3 M
 openssl-libs        x86_64       1:1.1.1k-4.el8         Stream-BaseOS       1.5 M

Transaction summary
===================================================================================
Upgrade 3 package

Total downloads: 4.5 M
 Download package:
(1/3): openssl-1.1.1k-4.el8.x86_64.rpm             1.3 MB/s | 709 kB     00:00    
(2/3): openssl-libs-1.1.1k-4.el8.x86_64.rpm        2.1 MB/s | 1.5 MB     00:00    
(3/3): openssl-devel-1.1.1k-4.el8.x86_64.rpm       2.4 MB/s | 2.3 MB     00:00    
-----------------------------------------------------------------------------------
total                                               2.9 MB/s | 4.5 MB     00:01     
  1. 6 since there is no dependency package integrating apr in the Apache source package [2.4. *] version by default, the dependency problem needs to be solved in advance
  • Copy the source code package of APR & APR UTI to the specified directory in the unzipped directory [httpd-2.4.48] of > > Apache, rename it, and remove the version number:
cp -a /root/lanmpp/apache/apr-1.7.0 /root/lanmpp/apache/httpd-2.4.48/srclib/apr
cp -a /root/lanmpp/apache/apr-util-1.6.1 /root/lanmpp/apache/httpd-2.4.48/srclib/apr-util
  • Through the above copying operation, the two necessary source packages APR & APR UTI are integrated into the > > Apache decompression directory [httpd-2.4.48]
  1. 7 create user & groups and restrict their login to the system:
groupadd www
useradd --shell /sbin/nologin -g www www
  1. 8 source code compilation & installation of Apache
cd httpd-2.4.48/
 ./configure  \
 --prefix=/usr/local/apache2  \
 --sysconfdir=/usr/local/apache2/etc \
 --with-included-apr  \
 --enable-so   \
 --enable-deflate=shared  \
 --enable-expires=shared \
 --enable-rewrite=shared  \
 --enable-ssl
  • Note: the [– enable SSL] option is a parameter set in advance for the later implementation of [https].
make 
make install
  • Check the installation results
echo $? 
0
//The print result is "0", indicating that the installation is successful!

P-07) test and operation [Apache]

  1. 1 start Apache test
/usr/local/apache2/bin/apachectl start
  • AH00558 reports an error
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
//AH00558:httpd: cannot use localhost Localdomain reliably determines the fully qualified domain name of the server. Set the "ServerName" directive globally to suppress this message
  • **Prompt: * * no domain name is bound! If you have a domain name, you can bind it. Of course, you can also use your public network [IP]. If you don't have a domain name, you can set it to local [localhost] or 127.0.0.1
  1. 2 configuration & modify Apache's configuration file httpd conf
vim /usr/local/apache2/etc/httpd.conf
#Search: / ServerName
#ServerName www.example.com:80
//About 190-200 lines, remove the previous comment '#' and replace the domain name with your domain name or 'IP' or the public network 'IP' of your server As follows:
ServerName 127.0.0.1:80
ServerName localhost:80
//Of course, you can also modify the port number, such as changing the 'Apache' running port to '8080'

[https://img-blog.csdnimg.cn/97183dae3dbc4ae4aa961e72389c72de.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NuZ2Vl,size_16,color_FFFFFF,t_70#pic_center]

  • : wq save and exit! It should be OK to start apache again!
  1. 2 check & confirm whether Apache starts and generates processes
ps aux | grep httpd
root      340753  0.0  0.1  86676  4392 ?        Ss   17:58   0:00 /usr/local/apache2/bin/httpd -k start
daemon    340754  0.0  0.1 2107536 4848 ?        Sl   17:58   0:00 /usr/local/apache2/bin/httpd -k start
daemon    340755  0.0  0.1 2107536 4896 ?        Sl   17:58   0:00 /usr/local/apache2/bin/httpd -k start
daemon    340756  0.0  0.1 2107536 4848 ?        Sl   17:58   0:00 /usr/local/apache2/bin/httpd -k start
root      341022  0.0  0.0  12352  1124 pts/2    S+   18:03   0:00 grep --color=auto httpd
//After checking, the Apache process has produced
  1. 3. Check & confirm whether the 80 listening port is enabled
netstat -tnl
tcp6       0      0 ::1:4330                :::*                    LISTEN     
tcp6       0      0 :::111                  :::*                    LISTEN     
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
//After checking, port '80' has been opened & released
  • **Note: * * when it is found that the [80] port has not been opened, if you are using the [ECS] server, go to the management background and release the [security rules] in the instance to the [0.0.0.0:80] port. You can also modify it in the configuration file: [Listen 0.0.0.0:80]
  1. 4 note: for operating systems from [CentOS 7] to above, the installed [Apache] listens to the [80] port of the Ipv6 address by default, and does not listen to the [Ipv4] address, so it is necessary to modify the configuration file to listen.
Listen 0.0.0.0:80
  1. 5. Handling of error reports: if it is prompted that [/ usr/local/apache2/modules/mod_deflate.so] has no permission at startup, you can close [SELinux] to solve the problem. The problem that such. so files cannot be loaded or have no permission is a SELinux problem. MySQL and Apache may have similar problems
  • For the method of closing SELINUX, see the description in Section [2.4] of this paper

P-08) startup and operation [Apache]

  1. 1 start [Apache]
/usr/local/apache2/bin/apachectl start
//httpd (pid 340753) already running OK!Apache has started running
  1. 2 stop [Apache]
/usr/local/apache2/bin/apachectl stop
  • **Note: * * after each modification of [Apache] configuration, the [stop & start] command operation shall be performed on [Apache], so that the modified configuration parameters will take effect

P-09) add [Apache] to the system service

  1. 1. Create start stop script:
cp /usr/local/apache2/bin/apachectl /etc/init.d/apache
vi /etc/init.d/apache
======#!/bin/shg Add the following along with the notes'#'written with======
#chkconfig: 2345 10 90
#description: Activates/Deactivates Apache Web Server
/*Note: [2345] is to set the running level of [Apache] startup. 10 = priority and 90=k drop the priority of the process. It means that whoever rushes ahead will sacrifice quickly*/
  • In this way, you can execute a series of convenient commands for apache such as service apache [start], [stop], [restart] globally
  1. 2. Set [Apache] to start automatically:
chkconfig --add apache
chkconfig apache on
chkconfig --list apache
  • Turn off startup and self startup:
chkconfig apache off
  1. 3 [Apache] service startup and shutdown summary:
service apache start       /*Start service*/
service apache restart     /*Restart service*/
service apache stop        /*Out of Service*/
  • Warm reminder: for apache installed with the source code, it is recommended not to set the startup mode such as service httpd start before php is installed, because there will be a pit that is not a pit, which will start the httpd built in the system source, resulting in problems in installing the php module.
  1. 4. Check the running status of [Apache] after restarting the host:
systemctl status apache
systemctl status apache
● apache.service - SYSV: Activates/Deactivates Apache Web Server
   Loaded: loaded (/etc/rc.d/init.d/apache; generated)
   Active: active (running) since Mon 2021-08-11 22:44:14 CST; 10min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1105 ExecStart=/etc/rc.d/init.d/apache start (code=exited, status=0/SUCCESS)
    Tasks: 82 (limit: 23376)
   Memory: 29.9M
   CGroup: /system.slice/apache.service
           ├─1144 /usr/local/apache2/bin/httpd -k start
           ├─1150 /usr/local/apache2/bin/httpd -k start
           ├─1151 /usr/local/apache2/bin/httpd -k start
           └─1152 /usr/local/apache2/bin/httpd -k start

8 June 16 22:44:13 localhost.localdomain systemd[1]: Starting SYSV: Activates/Deactivates>
8 June 16 22:44:14 localhost.localdomain systemd[1]: Started SYSV: Activates/Deactivates >
lines 1-15/15 (END)

P-10) [Apache] service verification

  • Open the browser and enter the address to access: http: / / your domain name, or your server's public network [ip]. If [It works] is displayed, it indicates that the [Apache] server is running normally

  • Here I bind IP resolution to the domain name mhy COM, open the browser to see the effect

[https://img-blog.csdnimg.cn/445a8afeab3945d4beff09c69e6a811d.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NuZ2Vl,size_16,color_FFFFFF,t_70#pic_center]

  • OK! The installation of [Apache] by compiling is perfect and successful. Isn't it complicated and hard to send a document? If it is helpful to you, please praise it! Leave your opinions

  • For more [it & Programming] knowledge, please pay attention to my [sngee] blog... And welcome friends to communicate

Learning is like life, forging ahead
Encourage each other, the trend of ambition

tes >
lines 1-15/15 (END)

#### P-10) [Apache] service verification

- [x] Open the browser and enter the address to access: http://Your domain name, or your server's public network [ip], if [It works] is displayed, it indicates that the [Apache] server is running normally


- [x] Here I will `IP` Resolve bind to domain name `mhy.com` ,Open the browser to see the effect


[External chain picture transfer...(img-dNUj5he0-1629154436081)]

- [x] OK!Install in compiled mode[ Apache]Perfect success, isn't it not complicated? It's hard to send a document! If it helps you, please praise it! Leave your opinion......


- [x] More[ IT&[programming] knowledge content, please pay attention to me[ sngee]My blog... Also welcome friends to communicate

---

*Learning is like life, forging ahead*
*Encourage each other, the trend of ambition*





Keywords: Web Server

Added by lucidpc on Thu, 23 Dec 2021 18:55:02 +0200