Install Apache on CentOS on VirtualBox

A memorandum when Apache was installed on CentOS of VitrualBox.

environment

It is assumed that you have made the basic settings of CentOS in the following articles. https://qiita.com/kazu_kazu/items/6e8dd09a5b0f641c3bf3

MacBook Pro (macOS Catalina version 10.15.6) VirtualBox 6.1.14 CentOS 8.2 Apache 2.4.37

Apache installation

Install according to the following article. WEB ARCH LABO "Procedures for installing Apache httpd 2.4 on CentOS 7 with yum" https://weblabo.oscasierra.net/apache-installing-apache24-yum-centos7-1/

Install with yum, not from source. First, display the package information to check the version to install.

[test1@www ~]$ yum info httpd
CentOS-8 - AppStream                            4.8 kB/s | 4.3 kB     00:00    
CentOS-8 - Base                                  11 kB/s | 3.9 kB     00:00    
CentOS-8 - Extras                               4.4 kB/s | 1.5 kB     00:00    
Available packages
name: httpd
version: 2.4.37
release: 21.module_el8.2.0+494+1df74eae
Arch         : x86_64
size: 1.7 M
Source: httpd-2.4.37-21.module_el8.2.0+494+1df74eae.src.rpm
Repository: AppStream
Overview: Apache HTTP Server
URL          : https://httpd.apache.org/
license: ASL 2.0
Explanation: The Apache HTTP Server is a powerful, efficient, and extensible
             : web server.

Next is installation.

[test1@www ~]$ sudo yum -y install httpd
[test1@www ~]$ httpd -v
Server version: Apache/2.4.37 (centos)
Server built:   Sep 15 2020 15:41:16

Start and stop confirmation

[test1@www ~]$ systemctl start httpd.service 
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ====
'httpd.service'Authentication is required to start.
Authenticating as: 
Password: 
==== AUTHENTICATION COMPLETE ====

[test1@www ~]$ systemctl status httpd.service 
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor pres>
   Active: active (running) since Sat 2020-10-24 16:57:35 JST; 45s ago
     Docs: man:httpd.service(8)
 Main PID: 33732 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 4876)
   Memory: 20.9M
   CGroup: /system.slice/httpd.service
           ├─33732 /usr/sbin/httpd -DFOREGROUND
           ├─33737 /usr/sbin/httpd -DFOREGROUND
           ├─33738 /usr/sbin/httpd -DFOREGROUND
           ├─33739 /usr/sbin/httpd -DFOREGROUND
           └─33740 /usr/sbin/httpd -DFOREGROUND

Access the web server by entering http: // (IP address of the guest who installed Apache) in the host browser. Success if the following screen is displayed.

スクリーンショット 2020-10-24 17.02.34.png

Web server stopped.

[test1@www ~]$ systemctl stop httpd.service 
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ====
'httpd.service'Authentication is required to stop.
Authenticating as: 
Password: 
==== AUTHENTICATION COMPLETE ====

Enabling access from other than the host OS

The current virtual machine network settings are NAT for adapter 1 and host-only adapter for adapter 2. The status of the host and guest IP addresses is as follows.

OS Interface name IPv4 address
The guests enp0s3(NAT) 10.0.2.15
The guests enp0s8(Host-only adapter) 192.168.56.10
host en0 192.168.0.4
host vboxnet0 (host-only adapter) 192.168.56.1

Access to the Web server from the host to the guest can be easily realized by using the host-only adapter, but access within the same LAN other than the host (access from your smartphone to the guest, etc.) will be accessed via NAT. In order to access guests with NAT, you need to configure port forwarding (NAT is set to be inaccessible from the host and other computers by default).

From the VM settings, go to Network → Adapter 1 → Advanced → Port Forwarding and set as follows (the name should be appropriate, and the host port should be a port other than the well-known port and not used by the host).

スクリーンショット 2020-10-24 21.00.17.png

Allow http on the guest firewall. I don't know why the host-only adapter was able to connect without permission.

[root@www ~]# firewall-cmd --add-service=http --permanent 
success
[root@www ~]# firewall-cmd --reload 
success
[root@www ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3 enp0s8
  sources: 
  services: cockpit dhcpv6-client http
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

After starting the web server as a guest, check the connection on the smartphone (the following picture is a picture of the browser of the host PC, but the connection was also possible on the smartphone).

スクリーンショット 2020-10-24 21.05.18.png

The IPv4 address entered in the browser is not that of the guest, but the IPv4 address of the host and the port number set in port forwarding are entered (as mentioned above, NAT cannot directly access the guest, so connect via the host).

For NAT and port forwarding, I referred to the following user manual. http://download.virtualbox.org/virtualbox/UserManual.pdf

Recommended Posts

Install Apache on CentOS on VirtualBox
Install apache 2.4.46 from source on CentOS7
Install Golang on CentOS 8
Install Neo4j 4.1.3 on centOS
Install Vertica 10.0 on CentOS 6.10
Install PostgreSQL 12 on Centos8
Install Python 3 on CentOS 7
Install kuromoji on CentOS7
Install Mattermost on CentOS 7
Install PostGIS 2.5.5 on CentOS7
Install jpndistrict on CentOS 7
Install Redmine 4.1.1 on CentOS 7
Smokeping Install on CentOS7
Install PostgreSQL 13 on CentOS 7.5
Install CentOS Stream8 in VirtualBox
Install OpenFOAM v2006 on CentOS
Install Jenkins on Docker's CentOS
Install Ruby 2.7 on CentOS 7 (SCL)
Try DPDK20 SDK on CentOS7 ①Install
Install Ruby 2.5 on CentOS 7 using SCL
Install Java Open JDK 8 on CentOS 7
How to install MariaDB 10.4 on CentOS 8
Steps to install MySQL 8 on CentOS 8
Steps to install devtoolset-6 on CentOS 7
Install Java 9 on windows 10 and CentOS 7
Install Apache JMeter
Install MariaDB (CentOS 8)
Install samba4 from source code on CentOS8
Install the webmail client Rainloop on CentOS 8
How to install beta php8.0 on CentOS8
[CentOS] Install apache-loggen
OpenVPN on CentOS 8
Install CentOS 7 on Raspberry pi 4 Model B
Install NextCloud on CentOS 7 with Alibaba Cloud ECS
Command to install nginx / PHP7 / php-fpm on CentOS7
Install GitLab on CentOS 8 with no internet connection
Install Java, Apache, Tomcat9 on EC2 (Amazon Linux2)
Install CMS Made Simple v2.2.2 on LAMP on CentOS 7.3
Install gradle on mac
Install Corretto 8 on Windows
Maven on CentOS 7 tutorial
Install OpenJDK on macOS
Install Java on Mac
Docker installation on CentOS 6
Use perltidy on CentOS 8
Install pyqt5 on ubuntu
Try OpenLiteSpeed on CentOS8
OpenAM installation on VirtualBox
[CentOS7] Install aws cli
Install Docker on Manjaro
Install Ruby on Ubuntu 20.04
Use mod_auth_cas on CentOS 8
Install lombok on SpringToolSuite4
Use bat on Centos.
Jetty v8 on CentOS7
Install Autoware on Ubuntu 18.04.5
OpenJDK installation on CentOS 7
Apache2 on Ubuntu20.04 LTS
Install openjdk11 on mac
Install Homebrew on Ubuntu 20.04
Install OpenJDK 8 on mac