
Apache is one of the most popular and widely used web servers in the world. It is reliable, secure, and highly customizable, making it an excellent choice for hosting websites and web applications. In this guide, we will walk you through how to Install Apache Web Server on Ubuntu step by step.
Table of Contents
- Prerequisites
- Step 1: Update System Packages
- Step 2: Install Apache Web Server on Ubuntu
- Step 3: Verify Apache Installation
- Step 4: Adjust Firewall Settings (Optional)
- Step 5: Test Apache Installation
- Step 6: Manage Apache Service
- Step 7: Configure Apache (Optional)
- Step 8: Enable Modules (Optional)
- Step 9: Secure Apache with SSL (Recommended)
- Conclusion
Prerequisites
Before starting, ensure the following:
- You have a system running Ubuntu (18.04, 20.04, or later).
- You have root or sudo access to the system.
- The system is connected to the internet.
Step 1: Update System Packages
Before installing any new software, it’s important to update your system package list to the latest version.
sudo apt update
sudo apt upgrade -y
This command ensures your system packages and dependencies are up-to-date.
Step 2: Install Apache Web Server on Ubuntu
To install Apache, run the following command:
sudo apt install apache2 -y
The -y
flag automatically confirms the installation.
Step 3: Verify Apache Installation
After the installation completes, check if Apache is installed and running by verifying its status.
sudo systemctl status apache2
If Apache is running, you will see output similar to:
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since [timestamp]
Read Also | EX200 RHCSA Exam Questions with Solutions: Your Path to RHEL 9 Certification
Step 4: Adjust Firewall Settings (Optional)
If UFW (Uncomplicated Firewall) is enabled, you need to allow Apache traffic.
First, check the available UFW application profiles:
sudo ufw app list
You will see output similar to:
Available applications: Apache Apache Full Apache Secure OpenSSH
Allow full Apache traffic:
sudo ufw allow 'Apache Full'
Enable UFW if it’s not already enabled:
sudo ufw enable
Step 5: Test Apache Installation
To verify that Apache is working correctly, open your web browser and navigate to your server’s IP address:
http://your-server-ip
You should see the default Apache welcome page, which confirms that the server is installed and running.
To find your server’s IP address, use:
ip a
Look for the inet
entry under your network interface.
Step 6: Manage Apache Service
Here are some common commands to manage the Apache service:
- Start Apache:
sudo systemctl start apache2
- Stop Apache:
sudo systemctl stop apache2
- Restart Apache:
sudo systemctl restart apache2
- Enable Apache to Start on Boot:
sudo systemctl enable apache2
- Disable Apache from Starting on Boot:
sudo systemctl disable apache2
Step 7: Configure Apache (Optional)
Apache’s configuration files are located in the /etc/apache2/
directory. The main configuration file is:
/etc/apache2/apache2.conf
To edit this file, use a text editor like Nano:
sudo nano /etc/apache2/apache2.conf
After making any changes, restart Apache:
sudo systemctl restart apache2
Read Also | Best CentOS and Redhat Alternatives | Open Source Linux OS
Step 8: Enable Modules (Optional)
Apache has various modules that can enhance its functionality. To enable a module, use the a2enmod
command.
For example, to enable the rewrite module:
sudo a2enmod rewrite
Restart Apache to apply the changes:
sudo systemctl restart apache2
Step 9: Secure Apache with SSL (Recommended)
To secure your Apache server with SSL, you can use Let’s Encrypt.
- Install Certbot:
sudo apt install certbot python3-certbot-apache -y
- Obtain and install an SSL certificate:
sudo certbot --apache
- Follow the prompts to configure SSL for your domain.
- Verify SSL renewal:
sudo certbot renew --dry-run
Conclusion
Congratulations! You have successfully learned how to Install Apache Web Server on Ubuntu and configure it for your needs. Apache is now ready to serve your websites or web applications. Don’t forget to secure and optimize your server for better performance.
For more tutorials and tech support, stay tuned to Magnetbyte for in-depth guides and reviews.
Read Also | How to install WordPress in Ubuntu Linux with LAMP