Skip to content

How To Install the Apache Web Server on Ubuntu 24

Cloud Infrastructure Expert
How To Install the Apache Web Server on Ubuntu 24

 

How to Install Apache Web Server on Windows VPS

By Łukasz Bodźiony, CEO of NETCLOUD24.COM | Windows VPS

The Apache Web Server is one of the most popular and robust web servers available, known for its flexibility and extensive module ecosystem. This guide provides detailed instructions for installing Apache on FreeBSD, Ubuntu, Debian, and AlmaLinux 12 using manual setup, Docker, Ansible, Kubernetes, and Terraform. Follow along to set up and configure Apache for your web hosting needs.

Why Choose Apache?

Apache is a reliable, open-source web server that powers a significant portion of the internet. It supports a wide range of modules, is highly customizable, and works seamlessly across various operating systems, making it ideal for hosting websites and web applications.

Manual Installation on Debian / Ubuntu

Install Apache on Debian or Ubuntu-based systems with the following steps:


# Update system packages
sudo apt update && sudo apt upgrade -y

# Install Apache
sudo apt install -y apache2

# Start and enable Apache
sudo systemctl start apache2
sudo systemctl enable apache2
    

Verify Apache is running by accessing http://your_server_ip in a browser, which should display the default Apache page.

Manual Installation on AlmaLinux 12

For AlmaLinux 12 (or other RHEL-based systems):


# Update system packages
sudo dnf update -y

# Install Apache
sudo dnf install -y httpd

# Start and enable Apache
sudo systemctl start httpd
sudo systemctl enable httpd
    

Ensure the firewall allows HTTP traffic:


sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
    

Manual Installation on FreeBSD

For FreeBSD systems:


# Update package database
sudo pkg update

# Install Apache
sudo pkg install -y apache24

# Enable and start Apache
sudo sysrc apache24_enable="YES"
sudo service apache24 start
    

Apache’s default document root is /usr/local/www/apache24/data. Test by visiting http://your_server_ip.

Using Docker

Docker provides a portable way to deploy Apache across platforms:


# Pull the official Apache image
docker pull httpd:latest

# Run Apache container
docker run -d -p 80:80 --name apache-server \
  -v /path/to/webroot:/usr/local/apache2/htdocs \
  httpd:latest
    

Replace /path/to/webroot with your local directory containing web files. Access Apache at http://localhost.

Using Ansible for Automated Deployment

Ansible streamlines Apache installation. Create a playbook (apache.yml):


---
- hosts: all
  become: yes
  tasks:
    - name: Install Apache on Debian/Ubuntu
      apt:
        name: apache2
        state: present
        update_cache: yes
      when: ansible_os_family == "Debian"
    - name: Install Apache on RedHat-based systems
      dnf:
        name: httpd
        state: present
        update_cache: yes
      when: ansible_os_family == "RedHat"
    - name: Ensure Apache is running
      service:
        name: "{{ 'apache2' if ansible_os_family == 'Debian' else 'httpd' }}"
        state: started
        enabled: yes
    

Run the playbook:


ansible-playbook apache.yml
    

Using Kubernetes

Deploy Apache on Kubernetes with a deployment manifest (apache-deployment.yaml):


apiVersion: apps/v1
kind: Deployment
metadata:
  name: apache
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apache
  template:
    metadata:
      labels:
        app: apache
    spec:
      containers:
      - name: apache
        image: httpd:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: apache-service
spec:
  selector:
    app: apache
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: ClusterIP
    

Apply the manifest:


kubectl apply -f apache-deployment.yaml
    

Using Terraform

Deploy Apache on a VPS using Terraform (apache.tf):


provider "aws" {
  region = "us-east-1"
}

resource "aws_instance" "apache" {
  ami           = "ami-0c55b159cbfafe1f0" # Replace with your preferred AMI
  instance_type = "t2.micro"
  user_data     = <<-EOF
                  #!/bin/bash
                  apt update
                  apt install -y apache2
                  systemctl start apache2
                  systemctl enable apache2
                  EOF
  tags = {
    Name = "Apache-Server"
  }
}
    

Run Terraform:


terraform init
terraform apply
    

Configuration

Configure Apache by editing its configuration file (e.g., /etc/apache2/apache2.conf on Debian/Ubuntu or /etc/httpd/conf/httpd.conf on AlmaLinux). Example to set a custom document root:


DocumentRoot /var/www/mywebsite

    AllowOverride All
    Require all granted

    

Restart Apache after changes:


sudo systemctl restart apache2  # Debian/Ubuntu
sudo systemctl restart httpd   # AlmaLinux
sudo service apache24 restart  # FreeBSD
    

Promote Your VPS with NETCLOUD24.COM

Conclusion

This guide, authored by Łukasz Bodźiony, CEO of NETCLOUD24.COM (Windows VPS), provides comprehensive steps to install and configure the Apache Web Server on FreeBSD, Ubuntu, Debian, and AlmaLinux 12 using manual setup, Docker, Ansible, Kubernetes, and Terraform. For top-tier VPS hosting to support your Apache deployment, choose NETCLOUD24.COM.

 

Explore more

More on this topic

Netcloud24
Netcloud24
Cloud Infrastructure Expert · NetCloud24
In this section

More in Linux

Visit category

How to Set up PostgreSQL Replication on Debian 11

  Introduction PostgreSQL is a powerful, open-source object-relational database system that offers advanced features for database management. Setting up replication is essential for ensuring high availability and load…

Comments are closed.