TheKoguryo's Tech Blog

 Version 2024.04.01

Warning

This content has been generated by machine translation. The translations are automated and have not undergone human review or validation.

5.1 Installing Apache HTTP Server on Linux Instance

  1. Connect to the created instance through the SSH command. The commands below are based on Oracle Enterprise Linux.

    ssh –i <private_key> <username>@<public-ip-address>
    
  2. Install Apache HTTP Server

    sudo yum -y install httpd
    
  3. Open port 80, port for Apache HTTP in OS firewall

    sudo firewall-cmd --permanent --add-port=80/tcp
    

    Tips

    Firewall open ports
    Modify the above command according to a port other than the Apache server default port, or a port that needs to be opened when using other applications, and open the port in the firewall.
  4. Re-reflect firewall changes

    sudo firewall-cmd --reload
    
  5. Start Apache

    sudo systemctl start httpd
    sudo systemctl enable httpd
    
  6. Create server’s Root Index Document for testing

    sudo su
    echo 'Hello Apache' >/var/www/html/index.html
    

Example of installation

ubuntu@NOTEBOOK-WORK:~/.ssh$ ssh -i mysshkey opc@152.70.251.xx
Last login: Mon Jan 10 08:38:45 2022 from 223.62.21.xx
[opc@examplelinuxinstance ~]$ sudo yum -y install httpd
Loaded plugins: langpacks, ulninfo
ol7_MySQL80                                                                                 | 3.0 kB 00:00:00
ol7_MySQL80_connectors_community                                                            | 2.9 kB 00:00:00
ol7_MySQL80_tools_community                                                                 | 2.9 kB 00:00:00
ol7_UEKR6                                                                                   | 3.0 kB 00:00:00
ol7_addons                                                                                  | 3.0 kB 00:00:00
ol7_ksplice                                                                                 | 3.0 kB 00:00:00
ol7_latest                                                                                  | 3.6 kB 00:00:00
ol7_oci_included                                                                            | 2.9 kB 00:00:00
ol7_optional_latest                                                                         | 3.0 kB 00:00:00
ol7_software_collections                                                                    | 3.0 kB 00:00:00
(1/20): ol7_MySQL80_connectors_community/x86_64/updateinfo                                  |  71 B 00:00:01
(2/20): ol7_MySQL80_tools_community/x86_64/primary_db                                       | 13 kB 00:00:00
(3/20): ol7_UEKR6/x86_64/updateinfo                                                         | 389 kB 00:00:00
(4/20): ol7_MySQL80/x86_64/updateinfo                                                       |  71 B 00:00:01
(5/20): ol7_addons/x86_64/updateinfo                                                        | 131 kB 00:00:00
(6/20): ol7_addons/x86_64/primary_db                                                        | 209 kB 00:00:00
(7/20): ol7_MySQL80_tools_community/x86_64/updateinfo                                       |  71 B 00:00:01
(8/20): ol7_ksplice/updateinfo                                                              | 7.9 kB 00:00:00
(9/20): ol7_latest/x86_64/group_gz                                                          | 136 kB 00:00:00
(10/20): ol7_ksplice/primary_db                                                             | 2.4 MB 00:00:00
(11/20): ol7_MySQL80_connectors_community/x86_64/primary_db                                 | 27 kB 00:00:01
(12/20): ol7_oci_included/x86_64/primary_db                                                 | 754 kB 00:00:00
(13/20): ol7_latest/x86_64/updateinfo                                                       | 3.4 MB 00:00:00
(14/20): ol7_optional_latest/x86_64/updateinfo                                              | 1.3 MB 00:00:00
(15/20): ol7_software_collections/x86_64/updateinfo                                         | 8.9 kB 00:00:00
(16/20): ol7_software_collections/x86_64/primary_db                                         | 5.8 MB 00:00:00
(17/20): ol7_MySQL80/x86_64/primary_db                                                      | 183 kB 00:00:02
(18/20): ol7_optional_latest/x86_64/primary_db                                              | 5.6 MB 00:00:00
(19/20): ol7_UEKR6/x86_64/primary_db                                                        | 27 MB 00:00:01
(20/20): ol7_latest/x86_64/primary_db                                                       | 37 MB 00:00:01
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-97.0.5.el7_9.2 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-97.0.5.el7_9.2 for package: httpd-2.4.6-97.0.5.el7_9.2.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-97.0.5.el7_9.2.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-97.0.5.el7_9.2.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-97.0.5.el7_9.2.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-7.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.0.1.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-97.0.5.el7_9.2 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package                    Arch                 Version                        Repository                Size
=================================================================================================================
Installing:
 httpd                      x86_64               2.4.6-97.0.5.el7_9.2           ol7_latest                1.2 M
Installing for dependencies:
 apr                        x86_64               1.4.8-7.el7                    ol7_latest                103 k
 apr-util                   x86_64               1.5.2-6.0.1.el7                ol7_latest                91 k
 httpd-tools                x86_64               2.4.6-97.0.5.el7_9.2           ol7_latest                93 k
 mailcap                    noarch               2.1.41-2.el7                   ol7_latest                30 k

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

Total download size: 1.5 M
Installed size: 4.3 M
Downloading packages:
(1/5): apr-1.4.8-7.el7.x86_64.rpm                                                           | 103 kB 00:00:00
(2/5): apr-util-1.5.2-6.0.1.el7.x86_64.rpm                                                  | 91 kB 00:00:00
(3/5): httpd-tools-2.4.6-97.0.5.el7_9.2.x86_64.rpm                                          | 93 kB 00:00:00
(4/5): mailcap-2.1.41-2.el7.noarch.rpm                                                      | 30 kB 00:00:00
(5/5): httpd-2.4.6-97.0.5.el7_9.2.x86_64.rpm                                                | 1.2 MB 00:00:00
------------------------------------------------------------------------------------------------------------------
Total                                                                              1.5 MB/s | 1.5 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : apr-1.4.8-7.el7.x86_64                                                                      1/5
 Installing : apr-util-1.5.2-6.0.1.el7.x86_64                                                             2/5
 Installing : httpd-tools-2.4.6-97.0.5.el7_9.2.x86_64                                                     3/5
 Installing : mailcap-2.1.41-2.el7.noarch                                                                 4/5
 Installing : httpd-2.4.6-97.0.5.el7_9.2.x86_64                                                           5/5
 Verifying : httpd-tools-2.4.6-97.0.5.el7_9.2.x86_64                                                      1/5
 Verifying : apr-1.4.8-7.el7.x86_64                                                                       2/5
 Verifying : apr-util-1.5.2-6.0.1.el7.x86_64                                                              3/5
 Verifying : mailcap-2.1.41-2.el7.noarch                                                                  4/5
 Verifying : httpd-2.4.6-97.0.5.el7_9.2.x86_64                                                            5/5

Installed:
 httpd.x86_64 0:2.4.6-97.0.5.el7_9.2

Dependency Installed:
 apr.x86_64 0:1.4.8-7.el7         apr-util.x86_64 0:1.5.2-6.0.1.el7         httpd-tools.x86_64 0:2.4.6-97.0.5.el7_9.2         mailcap.noarch 0:2.1.41-2.el7

Complete!
[opc@examplelinuxinstance ~]$ sudo firewall-cmd --permanent --add-port=80/tcp
success
[opc@examplelinuxinstance ~]$ sudo firewall-cmd --reload
success
[opc@examplelinuxinstance ~]$ sudo systemctl start httpd
[opc@examplelinuxinstance ~]$ sudo su
[root@examplelinuxinstance opc]# echo 'Hello Apache' >/var/www/html/index.html
[root@examplelinuxinstance opc]# exit
exit
[opc@examplelinuxinstance ~]$ curl http://127.0.0.1:80/index.html
Hello Apache


As an individual, this article was written with my personal time. There may be errors in the content of the article, and the opinions in the article are personal opinions.

Last updated on 11 Jan 2019