This guide provides you with step-by-step instructions to install Apache HTTP Server on your system. Whether you are a beginner or an experienced user, you will find these instructions helpful.

System Requirements

Before installing Apache, ensure your system meets the following requirements:

  • Linux distribution
  • Root or sudo access

Installation Steps

1. Update System Packages

First, update your system packages to ensure all necessary dependencies are installed.

sudo apt-get update
sudo apt-get upgrade

2. Install Apache

Now, install Apache using the package manager.

sudo apt-get install apache2

3. Verify Installation

After installation, verify that Apache is running by accessing your server's IP address or domain name in a web browser.

sudo systemctl status apache2

You should see the following output if Apache is running:

apache2.service - Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-04-14 10:45:21 UTC; 4min 11s ago

4. Configure Apache

Now, you can configure Apache to serve your websites. To modify the configuration, edit the main Apache configuration file located at /etc/apache2/apache2.conf.

sudo nano /etc/apache2/apache2.conf

Add the following line to enable the mod_rewrite module, which allows for URL rewriting:

LoadModule rewrite_module modules/mod_rewrite.so

5. Create a Website

Create a directory for your website's files, such as /var/www/html/your_website.

sudo mkdir /var/www/html/your_website

Create a sample HTML file for testing purposes:

<!DOCTYPE html>
<html>
<head>
    <title>My Website</title>
</head>
<body>
    <h1>Welcome to My Website</h1>
</body>
</html>

Copy the HTML file to the /var/www/html/your_website directory:

sudo cp sample.html /var/www/html/your_website/index.html

6. Enable the Website

To enable the website, create a new configuration file in the /etc/apache2/sites-available directory:

sudo nano /etc/apache2/sites-available/your_website.conf

Add the following configuration:

<VirtualHost *:80>
    ServerAdmin admin@your_website.com
    ServerName your_website.com
    ServerAlias www.your_website.com
    DocumentRoot /var/www/html/your_website
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable the website by creating a symbolic link to the configuration file:

sudo ln -s /etc/apache2/sites-available/your_website.conf /etc/apache2/sites-enabled/

Finally, restart Apache to apply the changes:

sudo systemctl restart apache2

7. Test Your Website

Access your website in a web browser using the domain name or IP address you assigned in the configuration file. You should see the sample HTML content.

Conclusion

Congratulations! You have successfully installed Apache HTTP Server and created a website. To learn more about Apache, visit our Apache documentation.