Marco - build a simple Apache service

Keywords: Linux CentOS RPM Apache yum

1. View the service status of httpd: display the httpd unit, unable to find the service.

[root@localhost ~]#systemctl status httpd
Unit httpd.service could not be found.

2. Use yum to install httpd service. The following is the installation process:

[root@localhost ~]#yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be install
--> Processing Dependency: httpd-tools = 2.4.6-90.el7.centos fo
--> Processing Dependency: /etc/mime.types for package: httpd-2
--> Processing Dependency: libaprutil-1.so.0()(64bit) for packa
--> Processing Dependency: libapr-1.so.0()(64bit) for package: 
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-90.el7.centos will be i
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================
 Package                          Arch                        V
===============================================================
Installing:
 httpd                            x86_64                      2
Installing for dependencies:
 apr                              x86_64                      1
 apr-util                         x86_64                      1
 httpd-tools                      x86_64                      2
 mailcap                          noarch                      2

Transaction Summary
===============================================================
Install  1 Package (+4 Dependent packages)

Total download size: 3.0 M
Installed size: 10 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): apr-1.4.8-5.el7.x86_64.rpm                              
(2/5): apr-util-1.5.2-6.el7.x86_64.rpm                         
(3/5): httpd-tools-2.4.6-90.el7.centos.x86_64.rpm              
(4/5): mailcap-2.1.41-2.el7.noarch.rpm                         
(5/5): httpd-2.4.6-90.el7.centos.x86_64.rpm                    
---------------------------------------------------------------
Total                                                          
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-5.el7.x86_64                          
  Installing : apr-util-1.5.2-6.el7.x86_64                     
  Installing : httpd-tools-2.4.6-90.el7.centos.x86_64          
  Installing : mailcap-2.1.41-2.el7.noarch                     
  Installing : httpd-2.4.6-90.el7.centos.x86_64                
  Verifying  : apr-1.4.8-5.el7.x86_64                          
  Verifying  : mailcap-2.1.41-2.el7.noarch                     
  Verifying  : httpd-tools-2.4.6-90.el7.centos.x86_64          
  Verifying  : apr-util-1.5.2-6.el7.x86_64                     
  Verifying  : httpd-2.4.6-90.el7.centos.x86_64                

Installed:
  httpd.x86_64 0:2.4.6-90.el7.centos                           

Dependency Installed:
  apr.x86_64 0:1.4.8-5.el7   apr-util.x86_64 0:1.5.2-6.el7   ht

Complete!

3. Check the status of httpd service again

[root@localhost ~]#systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disab
   Active: inactive (dead) #Display dead, i.e. closed
     Docs: man:httpd(8)
           man:apachectl(8)

4. Start httpd service with start

[root@localhost ~]#systemctl start httpd

Use ss -nlt to confirm that port 80 is open

[root@localhost /etc/httpd/conf.d]#ss -nlt
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128    127.0.0.1:631                 *:*                  
LISTEN     0      100    127.0.0.1:25                  *:*                  
LISTEN     0      128    127.0.0.1:6010                *:*                  
LISTEN     0      128     *:58699               *:*                  
LISTEN     0      128     *:111                 *:*                  
LISTEN     0      5      192.168.122.1:53                  *:*                  
LISTEN     0      128     *:22                  *:*                  
LISTEN     0      128     [::1]:631                  [::]:*                  
LISTEN     0      100     [::1]:25                   [::]:*                  
LISTEN     0      128     [::1]:6010                 [::]:*                  
LISTEN     0      128      [::]:38016                [::]:*                  
LISTEN     0      128      [::]:111                  [::]:*                  
LISTEN     0      128      [::]:80                   [::]:*                  
LISTEN     0      128      [::]:22                   [::]:*   

5. Check the status of httpd service again

 [root@localhost ~]#systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disab
   Active: active (running) since Fri 2019-10-11 19:16:34 CST;  #Display service is running, enabled
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 9866 (httpd)
   Status: "Processing requests..."
    Tasks: 6
   CGroup: /system.slice/httpd.service
           ├─9866 /usr/sbin/httpd -DFOREGROUND
           ├─9867 /usr/sbin/httpd -DFOREGROUND
           ├─9868 /usr/sbin/httpd -DFOREGROUND
           ├─9869 /usr/sbin/httpd -DFOREGROUND
           ├─9870 /usr/sbin/httpd -DFOREGROUND
           └─9871 /usr/sbin/httpd -DFOREGROUND

Oct 11 19:16:34 localhost.localdomain systemd[1]: Starting The 
Oct 11 19:16:34 localhost.localdomain httpd[9866]: AH00558: htt
Oct 11 19:16:34 localhost.localdomain systemd[1]: Started The A
Hint: Some lines were ellipsized, use -l to show in full.

6. Use a browser to access the IP address of your virtual machine. If you can't access it, check whether a bridge network card is added. If not, add one manually

7. If you add a bridge network card and you still can't connect to the IP address of the virtual machine through the browser, you can use the following command to turn off the firewall

[root@localhost ~]#systemctl disable --now firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.           

8. After closing the firewall, confirm whether the httpd service is enabled again

[root@localhost ~]#systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disab
   Active: active (running) since Fri 2019-10-11 19:16:34 CST;  #Display service is running, enabled
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 9866 (httpd)
   Status: "Processing requests..."
    Tasks: 6
   CGroup: /system.slice/httpd.service
           ├─9866 /usr/sbin/httpd -DFOREGROUND
           ├─9867 /usr/sbin/httpd -DFOREGROUND
           ├─9868 /usr/sbin/httpd -DFOREGROUND
           ├─9869 /usr/sbin/httpd -DFOREGROUND
           ├─9870 /usr/sbin/httpd -DFOREGROUND
           └─9871 /usr/sbin/httpd -DFOREGROUND

Oct 11 19:16:34 localhost.localdomain systemd[1]: Starting The 
Oct 11 19:16:34 localhost.localdomain httpd[9866]: AH00558: htt
Oct 11 19:16:34 localhost.localdomain systemd[1]: Started The A
Hint: Some lines were ellipsized, use -l to show in full.                           

9. After confirming that the httpd service is enabled, you can use the browser to access it

Posted by bolerophone on Sun, 03 Nov 2019 03:43:49 -0800