DeveloperBreeze

How to Install and Configure Apache on Ubuntu

Apache is one of the most popular and widely-used web servers. This tutorial will guide you through the process of installing and configuring Apache on an Ubuntu server.

Prerequisites:

  • An Ubuntu server (18.04, 20.04, or newer).
  • Root or sudo user privileges.

Step 1: Update the Package Index

Before installing Apache, it's a good idea to ensure your package index is up to date. Run the following command to update your server:

sudo apt update

Step 2: Install Apache

To install Apache on your server, use the following command:

sudo apt install apache2

Once the installation is complete, Apache will automatically start. You can verify if it's running with:

sudo systemctl status apache2

You should see a message indicating that Apache is active and running.

Step 3: Adjust the Firewall to Allow Web Traffic

If you have UFW (Uncomplicated Firewall) running, you will need to allow Apache traffic through the firewall. UFW has several predefined profiles that you can use to allow or deny traffic.

Check the available application profiles:

sudo ufw app list

You should see an output similar to:

Available applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH

To allow both HTTP and HTTPS traffic, run:

sudo ufw allow 'Apache Full'

Then, enable the firewall (if not already enabled):

sudo ufw enable

Step 4: Verify Apache Installation

To verify if Apache is installed and running correctly, open your browser and enter your server’s IP address:

http://your-server-ip

You should see the default Apache welcome page, which means Apache is working properly.

Step 5: Basic Apache Configuration

Apache’s configuration files are located in the /etc/apache2/ directory. You can configure global settings, virtual hosts, and more from these files.

Modify the Default Virtual Host

To customize the default website served by Apache, edit the configuration file:

sudo nano /etc/apache2/sites-available/000-default.conf

In this file, you can change the document root (where Apache serves files from) or add configurations such as additional directories.

Example: Change Document Root

If you want Apache to serve content from a different directory, you can change the DocumentRoot directive:

DocumentRoot /var/www/html

Save the file after making changes, then restart Apache to apply the changes:

sudo systemctl restart apache2

Step 6: Managing Apache

Start Apache:

sudo systemctl start apache2

Stop Apache:

sudo systemctl stop apache2

Restart Apache:

sudo systemctl restart apache2

Reload Apache (without stopping):

sudo systemctl reload apache2

Step 7: Enable Apache to Start on Boot

To ensure Apache starts on boot, use the following command:

sudo systemctl enable apache2

Step 8: Check Apache Server Logs

Apache logs can help troubleshoot issues with your web server. The logs are located in the /var/log/apache2/ directory.

  • Access logs: /var/log/apache2/access.log
  • Error logs: /var/log/apache2/error.log

You can view the logs using the cat or tail command:

sudo tail -f /var/log/apache2/error.log

Conclusion

Congratulations! You have successfully installed and configured Apache on your Ubuntu server. You can now host your websites and further customize your Apache setup according to your needs.


Continue Reading

Discover more amazing content handpicked just for you

Tutorial
bash

Renaming a subdomain in Apache and generating a new SSL certificate

   sudo systemctl status apache2

Open your browser and visit https://new.example.com to ensure that it’s accessible with a valid SSL certificate.

Nov 07, 2024
Read More
Tutorial
bash

How to Create SSL for a Website on Ubuntu

Run the following command to obtain and automatically configure your Apache server to use the SSL certificate:

sudo certbot --apache

Oct 21, 2024
Read More
Article
bash

Top 25 Nginx Web Server Best Security Practices

By default, Nginx runs as the root user. Change this to a non-privileged user like www-data to limit the scope of potential security breaches.

In your Nginx configuration file, set:

Sep 24, 2024
Read More
Tutorial

Adding a Subdomain on an Apache Server

The first step in setting up a subdomain is to create a DNS record that points to your server’s IP address. This tells the internet where to find your subdomain.

  • Name: Enter the subdomain name (e.g., blog for blog.example.com).
  • Type: Select A.
  • Value: Enter the IP address of your Apache server.
  • TTL: You can leave this as the default value.

Aug 21, 2024
Read More
Tutorial
json bash

Building Progressive Web Apps (PWAs) with Modern APIs

Progressive Web Apps (PWAs) are web applications that leverage modern web technologies to deliver an app-like experience to users. They combine the best of web and mobile apps, offering features such as offline access, push notifications, and device hardware access. In this tutorial, we will explore how to build a PWA using modern web APIs, including Service Workers, Web App Manifest, and IndexedDB.

To follow along with this tutorial, you should have a basic understanding of HTML, CSS, and JavaScript. Familiarity with modern JavaScript (ES6+) is also helpful.

Aug 05, 2024
Read More
Tutorial
python bash

Deploying a Flask Application on a VPS Using Gunicorn and Nginx

sudo nano /etc/nginx/sites-available/developerbreeze

Paste the following:

Aug 03, 2024
Read More
Code
php

Get Current URL

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!